org.equanda.persistence
Class LazyList<ID,TYPE extends HasId<ID>>

java.lang.Object
  extended by org.equanda.persistence.LazyList<ID,TYPE>
All Implemented Interfaces:
Serializable, Iterable<TYPE>, Collection<TYPE>, List<TYPE>, ExceptionCodes
Direct Known Subclasses:
LazyEJBListBase, LazyProxyListBase

public abstract class LazyList<ID,TYPE extends HasId<ID>>
extends Object
implements List<TYPE>, ExceptionCodes, Serializable

Abstract base class for LazyList instances.

A LazyList tries to get the resultset in batches if possible. The batch size if configurable. These batches are cached and the expiration timeout for this cache is also configurable.

When an element is obtained, an attempt is made to get the data from the cache. If the cache is stale (timeout exceeded), then the instance is refreshed (to minimize the number of full selectors).

For resultsets which cannot be batched (ADD on subselects), the full list of UOIDs for the elements is maintained.

Depending on some conditions, it is possible that the size() method does not function. In that case it will throw an exception. isEmpty should always function.

The behaviour is optimized for (forward) iteration of the list.

Author:
Joachim Van der Auwera
See Also:
Serialized Form

Field Summary
protected  EquandaQuery query
           
protected  SelectorsStateType selectorsState
           
 
Fields inherited from interface org.equanda.client.ExceptionCodes
CME_DATA_HAS_BEEN_ALREADY_CHANGED, ECV_CANNOT_ADD_NULL_TO_MULTIPLE_FIELD, ECV_CASCADE_KEEP, ECV_COMPARE_CONSTRAINT_NOT_SATISFIED, ECV_COMPARE_TYPE_CONSTRAINT_NOT_SATISFIED, ECV_CONSTRAINT_VIOLATION, ECV_COULD_NOT_TEST_CHOICES_USING_CLASS, ECV_DOWNCAST_CREATE_ERROR, ECV_DOWNCAST_FAILED_CANNOT_DOWNCAST_ROOT, ECV_DOWNCAST_SELECTOR_ERROR, ECV_FAILED_TO_CREATE_INCLUDED_VALUE, ECV_FAILED_TO_UPDATE_VALUE, ECV_FIELD_IS_REQUIRED, ECV_FIELD_IS_UNIQUE, ECV_IMMUTABLE_IF_OTHER_FIELD_IS_SET, ECV_INCLUDE_VALUE_HAS_WRONG_TYPE, ECV_INTERNAL_ERROR_ON_CREATE_INCLUDED_VALUE, ECV_INVALID_TABLE_TYPE, ECV_OTHERSIDE_EMBEDDED_FIELD_IMMUTABLE_ONCE_SET, ECV_VALUE_IS_NOT_ONE_OF_THE_CHOICES, EE_CANNOT_CREATE_LAZYCOLLECTION, EE_CANNOT_INIT_BEAN, EE_FAILED_PROXY_REMOVE, EE_FAILED_TO_UPDATE_VALUE, EE_OBJECT_NOT_FOUND, EPE_NULL_UOID_INVALID, EPE_PERSISTENCE_EXCEPTION, EPE_UOID_NOT_FOUND, UONA_OPERATION_NOT_ALLOWED
 
Constructor Summary
LazyList(EquandaQuery query)
           
LazyList(List<EquandaQuery> queries, boolean addOperator, int equandaLimit)
           
 
Method Summary
 void add(int i, TYPE type)
           
 boolean add(TYPE type)
           
 boolean addAll(Collection<? extends TYPE> types)
           
 boolean addAll(int i, Collection<? extends TYPE> types)
           
 void clear()
           
 boolean contains(Object obj)
           
 boolean containsAll(Collection<?> objects)
           
 long fullSize()
           
 TYPE get(int index)
           
protected abstract  int getCacheCapacity()
          Get the max number of objecs to keep in cache
protected abstract  int getCacheExpirationPeriod()
          Get the number of milliseconds that the cache is considered valid
protected abstract  TYPE[] getMultipleObjects(ID[] ids)
          Get TYPE objects for the given ids
protected abstract  TYPE[] getMultipleObjects(int first, int size)
           
protected abstract  TYPE getOneObject(ID id)
          Get TYPE object for the given Uoid.
protected abstract  TYPE getOneObject(int index)
           
protected abstract  EquandaSelector getSelector()
          Get the selector object for the TYPE
 int indexOf(Object o)
           
 boolean isEmpty()
          make List object complete
 Iterator<TYPE> iterator()
           
 int lastIndexOf(Object o)
           
 ListIterator<TYPE> listIterator()
           
 ListIterator<TYPE> listIterator(int i)
           
 void refresh()
          refresh list, force release cache
protected abstract  TYPE refreshObject(TYPE obj)
          Refresh the given object to make sure the data is live (used when cache timeout expired)
 TYPE remove(int index)
           
 boolean remove(Object o)
           
 boolean removeAll(Collection<?> objects)
           
 boolean retainAll(Collection<?> objects)
           
 TYPE set(int i, TYPE type)
           
 void setMockObject(MockObject m)
           
 int size()
          Deprecated.  
 List<TYPE> subList(int i, int i1)
           
 Object[] toArray()
           
<T> T[]
toArray(T[] ts)
           
 
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

query

protected EquandaQuery query

selectorsState

protected SelectorsStateType selectorsState
Constructor Detail

LazyList

public LazyList(EquandaQuery query)

LazyList

public LazyList(List<EquandaQuery> queries,
                boolean addOperator,
                int equandaLimit)
Method Detail

getCacheCapacity

protected abstract int getCacheCapacity()
Get the max number of objecs to keep in cache

Returns:
cache capacity

getCacheExpirationPeriod

protected abstract int getCacheExpirationPeriod()
Get the number of milliseconds that the cache is considered valid

Returns:
cache expiration persiod in ms

getSelector

protected abstract EquandaSelector getSelector()
                                        throws NamingException
Get the selector object for the TYPE

Returns:
selector object
Throws:
NamingException - problems

getOneObject

protected abstract TYPE getOneObject(ID id)
                                                throws NamingException,
                                                       EquandaException
Get TYPE object for the given Uoid.

Parameters:
id - pk
Returns:
object with given id
Throws:
NamingException - problems
EquandaException - problems

getMultipleObjects

protected abstract TYPE[] getMultipleObjects(ID[] ids)
                                                        throws NamingException,
                                                               EquandaException
Get TYPE objects for the given ids

Parameters:
ids - pks
Returns:
objects with given ids
Throws:
NamingException - problems
EquandaException - problems

refreshObject

protected abstract TYPE refreshObject(TYPE obj)
                                                 throws NamingException,
                                                        EquandaException
Refresh the given object to make sure the data is live (used when cache timeout expired)

Parameters:
obj - object to refresh
Returns:
fresh version of object
Throws:
NamingException - problems
EquandaException - problems

getOneObject

protected abstract TYPE getOneObject(int index)
                                                throws NamingException,
                                                       EquandaException
Throws:
NamingException
EquandaException

getMultipleObjects

protected abstract TYPE[] getMultipleObjects(int first,
                                             int size)
                                                        throws NamingException,
                                                               EquandaException
Throws:
NamingException
EquandaException

setMockObject

public void setMockObject(MockObject m)

contains

public boolean contains(Object obj)
Specified by:
contains in interface Collection<TYPE extends HasId<ID>>
Specified by:
contains in interface List<TYPE extends HasId<ID>>

get

public TYPE get(int index)
Specified by:
get in interface List<TYPE extends HasId<ID>>

iterator

public Iterator<TYPE> iterator()
Specified by:
iterator in interface Iterable<TYPE extends HasId<ID>>
Specified by:
iterator in interface Collection<TYPE extends HasId<ID>>
Specified by:
iterator in interface List<TYPE extends HasId<ID>>

fullSize

public long fullSize()

size

public int size()
Deprecated. 

Specified by:
size in interface Collection<TYPE extends HasId<ID>>
Specified by:
size in interface List<TYPE extends HasId<ID>>

isEmpty

public boolean isEmpty()
make List object complete

Specified by:
isEmpty in interface Collection<TYPE extends HasId<ID>>
Specified by:
isEmpty in interface List<TYPE extends HasId<ID>>

add

public boolean add(TYPE type)
Specified by:
add in interface Collection<TYPE extends HasId<ID>>
Specified by:
add in interface List<TYPE extends HasId<ID>>

add

public void add(int i,
                TYPE type)
Specified by:
add in interface List<TYPE extends HasId<ID>>

set

public TYPE set(int i,
                TYPE type)
Specified by:
set in interface List<TYPE extends HasId<ID>>

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection<TYPE extends HasId<ID>>
Specified by:
toArray in interface List<TYPE extends HasId<ID>>

toArray

public <T> T[] toArray(T[] ts)
Specified by:
toArray in interface Collection<TYPE extends HasId<ID>>
Specified by:
toArray in interface List<TYPE extends HasId<ID>>

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<TYPE extends HasId<ID>>
Specified by:
remove in interface List<TYPE extends HasId<ID>>

containsAll

public boolean containsAll(Collection<?> objects)
Specified by:
containsAll in interface Collection<TYPE extends HasId<ID>>
Specified by:
containsAll in interface List<TYPE extends HasId<ID>>

addAll

public boolean addAll(Collection<? extends TYPE> types)
Specified by:
addAll in interface Collection<TYPE extends HasId<ID>>
Specified by:
addAll in interface List<TYPE extends HasId<ID>>

addAll

public boolean addAll(int i,
                      Collection<? extends TYPE> types)
Specified by:
addAll in interface List<TYPE extends HasId<ID>>

removeAll

public boolean removeAll(Collection<?> objects)
Specified by:
removeAll in interface Collection<TYPE extends HasId<ID>>
Specified by:
removeAll in interface List<TYPE extends HasId<ID>>

retainAll

public boolean retainAll(Collection<?> objects)
Specified by:
retainAll in interface Collection<TYPE extends HasId<ID>>
Specified by:
retainAll in interface List<TYPE extends HasId<ID>>

clear

public void clear()
Specified by:
clear in interface Collection<TYPE extends HasId<ID>>
Specified by:
clear in interface List<TYPE extends HasId<ID>>

remove

public TYPE remove(int index)
Specified by:
remove in interface List<TYPE extends HasId<ID>>

indexOf

public int indexOf(Object o)
Specified by:
indexOf in interface List<TYPE extends HasId<ID>>

lastIndexOf

public int lastIndexOf(Object o)
Specified by:
lastIndexOf in interface List<TYPE extends HasId<ID>>

listIterator

public ListIterator<TYPE> listIterator()
Specified by:
listIterator in interface List<TYPE extends HasId<ID>>

listIterator

public ListIterator<TYPE> listIterator(int i)
Specified by:
listIterator in interface List<TYPE extends HasId<ID>>

subList

public List<TYPE> subList(int i,
                          int i1)
Specified by:
subList in interface List<TYPE extends HasId<ID>>

refresh

public void refresh()
refresh list, force release cache



Copyright © 2007-2009. All Rights Reserved.