com.avaje.ebean.bean
Interface BeanCollection<E>

All Superinterfaces:
Serializable
All Known Implementing Classes:
AbstractBeanCollection, BeanList, BeanMap, BeanSet

public interface BeanCollection<E>
extends Serializable

Lazy loading capable Maps, Lists and Sets.

This also includes the ability to listen for additions and removals to or from the Map Set or List. The purpose of gathering the additions and removals is to support persisting ManyToMany objects. The additions and removals become inserts and deletes from the intersection table.

Technically this is NOT an extension of java.util.Collection. The reason being that java.util.Map is not a Collection. I realise this makes this name confusing so I apologise for that.


Nested Class Summary
static class BeanCollection.ModifyListenMode
           
 
Field Summary
static int DEFAULT
          The default state (CacheStrategy readOnly can be applied).
static int READONLY
          Bean is READ ONLY (not editable).
static int SHARED
          Read Only immutable state and can't be made editable (in cache and sharable).
 
Method Summary
 void backgroundFetchWait()
          Wait for the fetch to complete.
 void backgroundFetchWait(long wait, TimeUnit timeUnit)
          Wait for the fetch to complete with a given timeout.
 boolean checkEmptyLazyLoad()
          Check after the lazy load that the underlying collection is not null (handle case where join to many not outer).
 Object getActualCollection()
          Returns the underlying List Set or Map object.
 Collection<E> getActualDetails()
          Returns the underlying details as an iterator.
 ExpressionList<?> getFilterMany()
          Return the filter (if any) that was used in building this collection.
 int getLoaderIndex()
          Return the index position of this collection in the lazy/query loader.
 Set<E> getModifyAdditions()
          Return the list of objects added to the list set or map.
 Set<E> getModifyRemovals()
          Return the list of objects removed from the list set or map.
 Object getOwnerBean()
          Return the bean that owns this collection.
 String getPropertyName()
          Return the bean property name this collection represents.
 boolean hasMoreRows()
          Set to true if maxRows was hit and there are actually more rows available.
 void internalAdd(Object bean)
          Add the bean to the collection.
 boolean isEmpty()
          Return true if the List Set or Map is empty.
 boolean isFinishedFetch()
          Returns true if the fetch has finished.
 boolean isPopulated()
          return true if there are real rows held.
 boolean isReadOnly()
          Return true if the collection should be treated as readOnly and no elements can be added or removed etc.
 boolean isSharedInstance()
          Return true if this collection is owned by a sharedInstance.
 void modifyAddition(E bean)
          Add an object to the additions list.
 void modifyRemoval(Object bean)
          Add an object to the deletions list.
 void modifyReset()
          Reset the set of additions and deletions.
 void setBackgroundFetch(Future<Integer> future)
          Set when this collection is being loaded via a background thread.
 void setBeanCollectionTouched(BeanCollectionTouched notify)
          Set a listener to be notified when the BeanCollection is first touched.
 void setFilterMany(ExpressionList<?> filterMany)
          Set the filter that was used in building this collection.
 void setFinishedFetch(boolean finishedFetch)
          Set to true when a fetch has finished.
 void setHasMoreRows(boolean hasMoreRows)
          Set to true when maxRows is hit but there are actually more rows available.
 void setLoader(int beanLoaderIndex, BeanCollectionLoader beanLoader)
          Set the loader that will be used to lazy/query load this collection.
 void setModifyListening(BeanCollection.ModifyListenMode modifyListenMode)
          Set modify listening on or off.
 void setReadOnly(boolean readOnly)
          Set to true if you want the BeanCollection to be treated as read only.
 void setSharedInstance()
          Set when this collection is owned by a sharedInstance.
 int size()
          Return the number of elements in the List Set or Map.
 

Field Detail

DEFAULT

static final int DEFAULT
The default state (CacheStrategy readOnly can be applied).

See Also:
Constant Field Values

READONLY

static final int READONLY
Bean is READ ONLY (not editable).

See Also:
Constant Field Values

SHARED

static final int SHARED
Read Only immutable state and can't be made editable (in cache and sharable).

See Also:
Constant Field Values
Method Detail

getOwnerBean

Object getOwnerBean()
Return the bean that owns this collection.


getPropertyName

String getPropertyName()
Return the bean property name this collection represents.


getLoaderIndex

int getLoaderIndex()
Return the index position of this collection in the lazy/query loader.

Used for batch loading of collections.


checkEmptyLazyLoad

boolean checkEmptyLazyLoad()
Check after the lazy load that the underlying collection is not null (handle case where join to many not outer).

That is, if the collection was not loaded due to filterMany predicates etc then make sure the collection is set to empty.


getFilterMany

ExpressionList<?> getFilterMany()
Return the filter (if any) that was used in building this collection.

This is so that the filter can be applied on refresh.


setFilterMany

void setFilterMany(ExpressionList<?> filterMany)
Set the filter that was used in building this collection.


setBackgroundFetch

void setBackgroundFetch(Future<Integer> future)
Set when this collection is being loaded via a background thread.

Refer to Query.setBackgroundFetchAfter(int)


backgroundFetchWait

void backgroundFetchWait(long wait,
                         TimeUnit timeUnit)
Wait for the fetch to complete with a given timeout.

Refer to Query.setBackgroundFetchAfter(int)


backgroundFetchWait

void backgroundFetchWait()
Wait for the fetch to complete.

Refer to Query.setBackgroundFetchAfter(int)


isSharedInstance

boolean isSharedInstance()
Return true if this collection is owned by a sharedInstance.

That is, return true if it is a Many property of a bean in the cache.


setSharedInstance

void setSharedInstance()
Set when this collection is owned by a sharedInstance.

That is, it is a Many property on a bean in the cache.


setBeanCollectionTouched

void setBeanCollectionTouched(BeanCollectionTouched notify)
Set a listener to be notified when the BeanCollection is first touched.


setLoader

void setLoader(int beanLoaderIndex,
               BeanCollectionLoader beanLoader)
Set the loader that will be used to lazy/query load this collection.


setReadOnly

void setReadOnly(boolean readOnly)
Set to true if you want the BeanCollection to be treated as read only. This means no elements can be added or removed etc.


isReadOnly

boolean isReadOnly()
Return true if the collection should be treated as readOnly and no elements can be added or removed etc.


internalAdd

void internalAdd(Object bean)
Add the bean to the collection.

This is disallowed for BeanMap.


getActualCollection

Object getActualCollection()
Returns the underlying List Set or Map object.


size

int size()
Return the number of elements in the List Set or Map.


isEmpty

boolean isEmpty()
Return true if the List Set or Map is empty.


getActualDetails

Collection<E> getActualDetails()
Returns the underlying details as an iterator.

Note that for maps this returns the entrySet as we need the keys of the map.


hasMoreRows

boolean hasMoreRows()
Set to true if maxRows was hit and there are actually more rows available.

Can be used by client code that is paging through results using setFirstRow() setMaxRows(). If this returns true then the client can display a 'next' button etc.


setHasMoreRows

void setHasMoreRows(boolean hasMoreRows)
Set to true when maxRows is hit but there are actually more rows available. This is set so that client code knows that there is more data available.


isFinishedFetch

boolean isFinishedFetch()
Returns true if the fetch has finished. False if the fetch is continuing in a background thread.


setFinishedFetch

void setFinishedFetch(boolean finishedFetch)
Set to true when a fetch has finished. Used when a fetch continues in the background.


isPopulated

boolean isPopulated()
return true if there are real rows held. Return false is this is using Deferred fetch to lazy load the rows and the rows have not yet been fetched.


setModifyListening

void setModifyListening(BeanCollection.ModifyListenMode modifyListenMode)
Set modify listening on or off. This is used to keep track of objects that have been added to or removed from the list set or map.

This is required only for ManyToMany collections. The additions and deletions are used to insert or delete entries from the intersection table. Otherwise modifyListening is false.


modifyAddition

void modifyAddition(E bean)
Add an object to the additions list.

This will potentially end up as an insert into a intersection table for a ManyToMany.


modifyRemoval

void modifyRemoval(Object bean)
Add an object to the deletions list.

This will potentially end up as an delete from an intersection table for a ManyToMany.


getModifyAdditions

Set<E> getModifyAdditions()
Return the list of objects added to the list set or map. These will used to insert rows into the intersection table of a ManyToMany.


getModifyRemovals

Set<E> getModifyRemovals()
Return the list of objects removed from the list set or map. These will used to delete rows from the intersection table of a ManyToMany.


modifyReset

void modifyReset()
Reset the set of additions and deletions. This is called after the additions and removals have been processed.



Copyright © 2010. All Rights Reserved.