com.j256.ormlite.dao
Class BaseForeignCollection<T,ID>

java.lang.Object
  extended by com.j256.ormlite.dao.BaseForeignCollection<T,ID>
All Implemented Interfaces:
CloseableIterable<T>, ForeignCollection<T>, Serializable, Iterable<T>, Collection<T>
Direct Known Subclasses:
EagerForeignCollection, LazyForeignCollection

public abstract class BaseForeignCollection<T,ID>
extends Object
implements ForeignCollection<T>, Serializable

Base collection that is set on a field that as been marked with the ForeignCollectionField annotation when an object is refreshed or queried (i.e. not created).

WARNING: Most likely for(;;) loops should not be used here since we need to be careful about closing the iterator.

Author:
graywatson
See Also:
Serialized Form

Field Summary
protected  Dao<T,ID> dao
           
 
Constructor Summary
protected BaseForeignCollection(Dao<T,ID> dao, String fieldName, Object fieldValue, String orderColumn, Object parent)
           
 
Method Summary
 boolean add(T data)
          Add an element to the collection.
 boolean addAll(Collection<? extends T> collection)
          Add the collection of elements to this collection.
 void clear()
          Clears the collection and uses the iterator to run through the dao and delete all of the items in the collection from the associated database table.
protected  PreparedQuery<T> getPreparedQuery()
           
abstract  boolean remove(Object data)
          Remove the item from the collection and the associated database table.
abstract  boolean removeAll(Collection<?> collection)
          Remove the items in the collection argument from the foreign collection and the associated database table.
 boolean retainAll(Collection<?> collection)
          Uses the iterator to run through the dao and retain only the items that are in the passed in collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.j256.ormlite.dao.ForeignCollection
closeLastIterator, getWrappedIterable, isEager, iteratorThrow
 
Methods inherited from interface java.util.Collection
contains, containsAll, equals, hashCode, isEmpty, iterator, size, toArray, toArray
 
Methods inherited from interface com.j256.ormlite.dao.CloseableIterable
closeableIterator
 

Field Detail

dao

protected final transient Dao<T,ID> dao
Constructor Detail

BaseForeignCollection

protected BaseForeignCollection(Dao<T,ID> dao,
                                String fieldName,
                                Object fieldValue,
                                String orderColumn,
                                Object parent)
Method Detail

add

public boolean add(T data)
Add an element to the collection. This will also add the item to the associated database table.

Specified by:
add in interface Collection<T>
Returns:
Returns true if the item did not already exist in the collection otherwise false.

addAll

public boolean addAll(Collection<? extends T> collection)
Add the collection of elements to this collection. This will also them to the associated database table.

Specified by:
addAll in interface Collection<T>
Returns:
Returns true if the item did not already exist in the collection otherwise false.

remove

public abstract boolean remove(Object data)
Remove the item from the collection and the associated database table. NOTE: we can't just do a dao.delete(data) because it has to be in the collection.

Specified by:
remove in interface Collection<T>
Returns:
True if the item was found in the collection otherwise false.

removeAll

public abstract boolean removeAll(Collection<?> collection)
Remove the items in the collection argument from the foreign collection and the associated database table. NOTE: we can't just do a for (...) dao.delete(item) because the items have to be in the collection.

Specified by:
removeAll in interface Collection<T>
Returns:
True if the item was found in the collection otherwise false.

retainAll

public boolean retainAll(Collection<?> collection)
Uses the iterator to run through the dao and retain only the items that are in the passed in collection. This will remove the items from the associated database table as well.

Specified by:
retainAll in interface Collection<T>
Returns:
Returns true of the collection was changed at all otherwise false.

clear

public void clear()
Clears the collection and uses the iterator to run through the dao and delete all of the items in the collection from the associated database table. This is different from removing all of the elements in the table since this iterator is across just one item's foreign objects.

Specified by:
clear in interface Collection<T>

getPreparedQuery

protected PreparedQuery<T> getPreparedQuery()
                                     throws SQLException
Throws:
SQLException


This content is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.