org.salespointframework.core.data
Class PersistentList<E>

java.lang.Object
  extended by org.salespointframework.core.data.PersistentList<E>
Type Parameters:
E - generic type of items
All Implemented Interfaces:
java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>, DatasourceChangeListener, DatasourceOnChangeListener, ExternalModificationListener

public class PersistentList<E>
extends java.lang.Object
implements java.util.List<E>, DatasourceOnChangeListener, DatasourceChangeListener, ExternalModificationListener

A PersistentList represents a List which persists its items via PersistenceManager's listing methods. This lists need a unique id which is composed of host and id This list doesn't provide an order, so you should not use get(int) and remove(int) methods. make sure that all objects you store in it, are persistable by PersistenceManager.persist(Object) items in this list are cached for performance reasons. most methods are thread safe.

Since:
4.0
Author:
Thomas Kissinger

Field Summary
static long DEFAULT_CACHE_LIFETIME
          the default cache life time
 
Constructor Summary
PersistentList(java.lang.Object host, java.lang.String id, java.lang.Class oc, java.lang.Object recoveryContext)
          constructor
PersistentList(java.lang.Object host, java.lang.String id, java.lang.Class oc, java.lang.Object respectKey, java.lang.Class contextMap, java.lang.Class kc, java.lang.Object recoveryContext, PersistentMap map)
          constructor.
PersistentList(java.lang.String id, java.lang.Class oc)
          default constructor because of a java language weakness you need to pass the type of generic argument explicitly
 
Method Summary
 boolean add(E e)
           
 void add(int index, E element)
           
 boolean addAll(java.util.Collection<? extends E> c)
           
 boolean addAll(int index, java.util.Collection<? extends E> c)
          this method is not implemented
 boolean addExternalModificationListener(ExternalModificationListener eml)
          add a ExternalModificationListener
 void clear()
           
 boolean contains(java.lang.Object o)
           
 boolean containsAll(java.util.Collection<?> c)
          this method is not implemented
 void DatasourceChanged(boolean pumpUp)
          invalidate caches, when datasource changed. and pump up the event
 void DatasourceOnChange()
          pump up the datasource on change event
 void externalModificationOccurred()
          invalidate caches and pump up the event
 E get(int index)
           
 java.lang.Object getHost()
          get host
 java.lang.String getId()
          get id
 java.lang.String getListId()
          get encoded list id
 java.lang.String getListId(boolean raw)
          get list id
 java.lang.Object getLock()
          get lock
 int indexOf(java.lang.Object o)
           
 void invalidateCache()
          invalidate caches
 boolean isEmpty()
           
 java.util.Iterator<E> iterator()
           
 int lastIndexOf(java.lang.Object o)
          this method is not implemented
 java.util.ListIterator<E> listIterator()
          this method is not implemented
 java.util.ListIterator<E> listIterator(int index)
          this method is not implemented
 E remove(int index)
           
 boolean remove(java.lang.Object o)
           
 boolean removeAll(java.util.Collection<?> c)
          this method is not implemented
 void removeExternalModificationListener(ExternalModificationListener eml)
          remove ExternalModificationListener
 boolean retainAll(java.util.Collection<?> c)
          this method is not implemented
 E set(int index, E element)
           
 void setCacheLifetime(long cacheLifetime)
          set cacheLifetime
 int size()
           
 java.util.List<E> subList(int fromIndex, int toIndex)
          this method is not implemented
 java.lang.Object[] toArray()
           
<T> T[]
toArray(T[] a)
          this method is not implemented
 void unsubscribe()
          unsubscribe listeners from PersistenceManager
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.List
equals, hashCode
 

Field Detail

DEFAULT_CACHE_LIFETIME

public static long DEFAULT_CACHE_LIFETIME
the default cache life time

Constructor Detail

PersistentList

public PersistentList(java.lang.String id,
                      java.lang.Class oc)
default constructor because of a java language weakness you need to pass the type of generic argument explicitly

Parameters:
id - id
oc - oc

PersistentList

public PersistentList(java.lang.Object host,
                      java.lang.String id,
                      java.lang.Class oc,
                      java.lang.Object recoveryContext)
constructor

Parameters:
host - host
id - id
oc - oc
recoveryContext - recoveryContext

PersistentList

public PersistentList(java.lang.Object host,
                      java.lang.String id,
                      java.lang.Class oc,
                      java.lang.Object respectKey,
                      java.lang.Class contextMap,
                      java.lang.Class kc,
                      java.lang.Object recoveryContext,
                      PersistentMap map)
constructor. Warning: This constructor should never be called directly, unless you know what you are doing!

Parameters:
host - host
id - id
oc - oc
respectKey - respectKey
contextMap - c
kc - kc
recoveryContext - recoveryContext
map - map
Method Detail

getLock

public java.lang.Object getLock()
get lock

Returns:

getId

public java.lang.String getId()
get id

Returns:

getHost

public java.lang.Object getHost()
get host

Returns:

setCacheLifetime

public void setCacheLifetime(long cacheLifetime)
set cacheLifetime

Parameters:
cacheLifetime -

unsubscribe

public void unsubscribe()
unsubscribe listeners from PersistenceManager


getListId

public java.lang.String getListId()
get encoded list id

Returns:

getListId

public java.lang.String getListId(boolean raw)
get list id

Parameters:
raw - true, if id should not be encoded
Returns:

invalidateCache

public void invalidateCache()
invalidate caches


add

public boolean add(E e)
Specified by:
add in interface java.util.Collection<E>
Specified by:
add in interface java.util.List<E>
See Also:
List.add(Object)

add

public void add(int index,
                E element)
Specified by:
add in interface java.util.List<E>
See Also:
List.add(int, Object)

addAll

public boolean addAll(java.util.Collection<? extends E> c)
Specified by:
addAll in interface java.util.Collection<E>
Specified by:
addAll in interface java.util.List<E>
See Also:
List.addAll(Collection)

addAll

public boolean addAll(int index,
                      java.util.Collection<? extends E> c)
this method is not implemented

Specified by:
addAll in interface java.util.List<E>

clear

public void clear()
Specified by:
clear in interface java.util.Collection<E>
Specified by:
clear in interface java.util.List<E>
See Also:
List.clear()

contains

public boolean contains(java.lang.Object o)
Specified by:
contains in interface java.util.Collection<E>
Specified by:
contains in interface java.util.List<E>
See Also:
List.contains(Object)

containsAll

public boolean containsAll(java.util.Collection<?> c)
this method is not implemented

Specified by:
containsAll in interface java.util.Collection<E>
Specified by:
containsAll in interface java.util.List<E>

get

public E get(int index)
Specified by:
get in interface java.util.List<E>
See Also:
List.get(int)

indexOf

public int indexOf(java.lang.Object o)
Specified by:
indexOf in interface java.util.List<E>
See Also:
List.indexOf(Object)

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection<E>
Specified by:
isEmpty in interface java.util.List<E>
See Also:
List.isEmpty()

iterator

public java.util.Iterator<E> iterator()
Specified by:
iterator in interface java.lang.Iterable<E>
Specified by:
iterator in interface java.util.Collection<E>
Specified by:
iterator in interface java.util.List<E>
See Also:
List.iterator()

lastIndexOf

public int lastIndexOf(java.lang.Object o)
this method is not implemented

Specified by:
lastIndexOf in interface java.util.List<E>

listIterator

public java.util.ListIterator<E> listIterator()
this method is not implemented

Specified by:
listIterator in interface java.util.List<E>

listIterator

public java.util.ListIterator<E> listIterator(int index)
this method is not implemented

Specified by:
listIterator in interface java.util.List<E>

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Collection<E>
Specified by:
remove in interface java.util.List<E>
See Also:
List.remove(Object)

remove

public E remove(int index)
Specified by:
remove in interface java.util.List<E>
Returns:
always null
See Also:
List.remove(int)

removeAll

public boolean removeAll(java.util.Collection<?> c)
this method is not implemented

Specified by:
removeAll in interface java.util.Collection<E>
Specified by:
removeAll in interface java.util.List<E>

retainAll

public boolean retainAll(java.util.Collection<?> c)
this method is not implemented

Specified by:
retainAll in interface java.util.Collection<E>
Specified by:
retainAll in interface java.util.List<E>

set

public E set(int index,
             E element)
Specified by:
set in interface java.util.List<E>
Returns:
always null
See Also:
List.set(int, Object)

size

public int size()
Specified by:
size in interface java.util.Collection<E>
Specified by:
size in interface java.util.List<E>
See Also:
List.size()

subList

public java.util.List<E> subList(int fromIndex,
                                 int toIndex)
this method is not implemented

Specified by:
subList in interface java.util.List<E>

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection<E>
Specified by:
toArray in interface java.util.List<E>
See Also:
List.toArray()

toArray

public <T> T[] toArray(T[] a)
this method is not implemented

Specified by:
toArray in interface java.util.Collection<E>
Specified by:
toArray in interface java.util.List<E>

DatasourceOnChange

public void DatasourceOnChange()
pump up the datasource on change event

Specified by:
DatasourceOnChange in interface DatasourceOnChangeListener

DatasourceChanged

public void DatasourceChanged(boolean pumpUp)
invalidate caches, when datasource changed. and pump up the event

Specified by:
DatasourceChanged in interface DatasourceChangeListener
Parameters:
pumpUp - true if the event should be pumped up to hosts, because this event is mostly triggered twice. first time to invalidate caches. second time for load new data

addExternalModificationListener

public boolean addExternalModificationListener(ExternalModificationListener eml)
add a ExternalModificationListener

Parameters:
eml - the listener
Returns:
true on success

removeExternalModificationListener

public void removeExternalModificationListener(ExternalModificationListener eml)
remove ExternalModificationListener

Parameters:
eml - the listener to remove

externalModificationOccurred

public void externalModificationOccurred()
invalidate caches and pump up the event

Specified by:
externalModificationOccurred in interface ExternalModificationListener