public class LazyForeignCollection<T,ID> extends BaseForeignCollection<T,ID> implements Serializable
ForeignCollectionField annotation when an
object is refreshed or queried (i.e. not created). Most of the methods here require a pass through the database.
Operations such as size() therefore should most likely not be used because of their expense. Chances are you only
want to use the iterator(), toArray(), and toArray(Object[]) methods.
WARNING: Most likely for(;;) loops should not be used here since we need to be careful about closing the iterator.
dao| Constructor and Description |
|---|
LazyForeignCollection(Dao<T,ID> dao,
Object parent,
Object parentId,
FieldType foreignFieldType,
String orderColumn,
boolean orderAscending)
WARNING: The user should not be calling this constructor.
|
| Modifier and Type | Method and Description |
|---|---|
CloseableIterator<T> |
closeableIterator()
Returns an iterator over a set of elements of type T which can be closed.
|
CloseableIterator<T> |
closeableIterator(int flags)
Same as
ForeignCollection.iterator(int). |
void |
closeLastIterator()
This will close the last iterator returned by the
Collection.iterator() method. |
boolean |
contains(Object obj) |
boolean |
containsAll(Collection<?> collection) |
boolean |
equals(Object other)
This is just a call to
Object.equals(Object). |
CloseableWrappedIterable<T> |
getWrappedIterable()
This makes a one time use iterable class that can be closed afterwards.
|
CloseableWrappedIterable<T> |
getWrappedIterable(int flags)
Like
ForeignCollection.getWrappedIterable() but while specifying flags for the results. |
int |
hashCode()
This is just a call to
Object.hashCode(). |
boolean |
isEager()
Returns true if this an eager collection otherwise false.
|
boolean |
isEmpty() |
CloseableIterator<T> |
iterator()
The iterator returned from a lazy collection keeps a connection open to the database as it iterates across the
collection.
|
CloseableIterator<T> |
iterator(int flags)
Like
Collection.iterator() but while specifying flags for the results. |
CloseableIterator<T> |
iteratorThrow()
Like
Collection.iterator() but returns a closeable iterator instead and can throw a SQLException. |
CloseableIterator<T> |
iteratorThrow(int flags)
Like
ForeignCollection.iteratorThrow() but while specifying flags for the results. |
int |
refreshAll()
Call to refresh on all of the items currently in the collection with the database.
|
int |
refreshCollection()
This re-issues the query that initially built the collection replacing any underlying result collection with a
new one build from the database.
|
boolean |
remove(Object data)
Remove the item from the collection and the associated database table.
|
boolean |
removeAll(Collection<?> collection)
Remove the items in the collection argument from the foreign collection and the associated database table.
|
int |
size() |
Object[] |
toArray() |
<E> E[] |
toArray(E[] array) |
List<T> |
toList()
Return a list of items from the database.
|
int |
updateAll()
Update all of the items currently in the collection with the database.
|
add, addAll, clear, getDao, getPreparedQuery, refresh, retainAll, updateclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitparallelStream, removeIf, spliterator, streampublic LazyForeignCollection(Dao<T,ID> dao, Object parent, Object parentId, FieldType foreignFieldType, String orderColumn, boolean orderAscending)
Dao.assignEmptyForeignCollection(Object, String) or Dao.getEmptyForeignCollection(String) methods
instead.public CloseableIterator<T> iterator()
AutoCloseable.close() or go all the way through the loop to ensure
that the connection has been closed. You can also call closeLastIterator() on the collection itself
which will close the last iterator returned. See the reentrant warning.public CloseableIterator<T> iterator(int flags)
ForeignCollectionCollection.iterator() but while specifying flags for the results. This is necessary with certain
database types. The resultFlags could be something like ResultSet.TYPE_SCROLL_INSENSITIVE or other values.iterator in interface ForeignCollection<T>public CloseableIterator<T> closeableIterator()
CloseableIterablecloseableIterator in interface CloseableIterable<T>public CloseableIterator<T> closeableIterator(int flags)
ForeignCollectionForeignCollection.iterator(int).closeableIterator in interface ForeignCollection<T>public CloseableIterator<T> iteratorThrow() throws SQLException
ForeignCollectionCollection.iterator() but returns a closeable iterator instead and can throw a SQLException.iteratorThrow in interface ForeignCollection<T>SQLExceptionpublic CloseableIterator<T> iteratorThrow(int flags) throws SQLException
ForeignCollectionForeignCollection.iteratorThrow() but while specifying flags for the results. This is necessary with certain database
types. The resultFlags could be something like ResultSet.TYPE_SCROLL_INSENSITIVE or other values.iteratorThrow in interface ForeignCollection<T>SQLExceptionpublic CloseableWrappedIterable<T> getWrappedIterable()
ForeignCollectionCloseableWrappedIterable but multiple threads can each call this to get their own closeable iterable.getWrappedIterable in interface ForeignCollection<T>public CloseableWrappedIterable<T> getWrappedIterable(int flags)
ForeignCollectionForeignCollection.getWrappedIterable() but while specifying flags for the results. This is necessary with certain
database types. The resultFlags could be something like ResultSet.TYPE_SCROLL_INSENSITIVE or other values.getWrappedIterable in interface ForeignCollection<T>public void closeLastIterator()
throws Exception
ForeignCollectionCollection.iterator() method.
NOTE: For lazy collections, this is not reentrant. If multiple threads are getting iterators from a lazy
collection from the same object then you should use ForeignCollection.getWrappedIterable() to get a reentrant wrapped
iterable for each thread instead.
closeLastIterator in interface ForeignCollection<T>Exceptionpublic boolean isEager()
ForeignCollectionisEager in interface ForeignCollection<T>public int size()
size in interface Collection<T>public boolean isEmpty()
isEmpty in interface Collection<T>public boolean contains(Object obj)
contains in interface Collection<T>public boolean containsAll(Collection<?> collection)
containsAll in interface Collection<T>public boolean remove(Object data)
BaseForeignCollectionremove in interface Collection<T>remove in class BaseForeignCollection<T,ID>public boolean removeAll(Collection<?> collection)
BaseForeignCollectionremoveAll in interface Collection<T>removeAll in class BaseForeignCollection<T,ID>public List<T> toList()
public Object[] toArray()
toArray in interface Collection<T>public <E> E[] toArray(E[] array)
toArray in interface Collection<T>public int updateAll()
ForeignCollectionupdateAll in interface ForeignCollection<T>public int refreshAll()
ForeignCollectionForeignCollection.refreshCollection().refreshAll in interface ForeignCollection<T>public int refreshCollection()
ForeignCollectionrefreshCollection in interface ForeignCollection<T>public boolean equals(Object other)
Object.equals(Object).
NOTE: This method is here for documentation purposes because EagerForeignCollection.equals(Object) is
defined.
equals in interface Collection<T>equals in class Objectpublic int hashCode()
Object.hashCode().
NOTE: This method is here for documentation purposes because EagerForeignCollection.equals(Object) is
defined.
hashCode in interface Collection<T>hashCode in class ObjectThis documentation is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.