public class EagerForeignCollection<T,ID> extends BaseForeignCollection<T,ID> implements CloseableWrappedIterable<T>, Serializable, List<T>
ForeignCollectionField
annotation when an
object is refreshed or queried (i.e. not created).dao
Constructor and Description |
---|
EagerForeignCollection(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 |
---|---|
void |
add(int index,
T element) |
boolean |
add(T data)
Adds the object to the collection.
|
boolean |
addAll(Collection<? extends T> collection)
Add the collection of elements to this collection.
|
boolean |
addAll(int index,
Collection<? extends T> c) |
void |
close()
This will close the iterator that was wrapped.
|
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 o) |
boolean |
containsAll(Collection<?> c) |
boolean |
equals(Object obj)
This is just a call to the equals method of the internal results list.
|
T |
get(int index) |
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 the hashcode method of the internal results list.
|
int |
indexOf(Object element) |
boolean |
isEager()
Returns true if this an eager collection otherwise false.
|
boolean |
isEmpty() |
CloseableIterator<T> |
iterator() |
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 |
lastIndexOf(Object element) |
ListIterator<T> |
listIterator()
NOTE: changes to the iterator are _not_ replicated to the foreign collection.
|
ListIterator<T> |
listIterator(int index)
NOTE: changes to the iterator are _not_ replicated to the foreign collection.
|
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.
|
T |
remove(int index) |
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.
|
boolean |
retainAll(Collection<?> collection)
Uses the iterator to run through the dao and retain only the items that are in the passed in collection.
|
T |
set(int index,
T element) |
int |
size() |
List<T> |
subList(int fromIndex,
int toIndex) |
Object[] |
toArray() |
<E> E[] |
toArray(E[] array) |
int |
updateAll()
Update all of the items currently in the collection with the database.
|
clear, getDao, getPreparedQuery, refresh, update
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
clear, replaceAll, sort, spliterator
parallelStream, removeIf, stream
public EagerForeignCollection(Dao<T,ID> dao, Object parent, Object parentId, FieldType foreignFieldType, String orderColumn, boolean orderAscending) throws SQLException
Dao.assignEmptyForeignCollection(Object, String)
or Dao.getEmptyForeignCollection(String)
methods
instead.SQLException
public CloseableIterator<T> iterator()
public CloseableIterator<T> iterator(int flags)
ForeignCollection
Collection.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()
CloseableIterable
closeableIterator
in interface CloseableIterable<T>
public CloseableIterator<T> closeableIterator(int flags)
ForeignCollection
ForeignCollection.iterator(int)
.closeableIterator
in interface ForeignCollection<T>
public CloseableIterator<T> iteratorThrow()
ForeignCollection
Collection.iterator()
but returns a closeable iterator instead and can throw a SQLException.iteratorThrow
in interface ForeignCollection<T>
public CloseableIterator<T> iteratorThrow(int flags)
ForeignCollection
ForeignCollection.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>
public CloseableWrappedIterable<T> getWrappedIterable()
ForeignCollection
CloseableWrappedIterable
but multiple threads can each call this to get their own closeable iterable.getWrappedIterable
in interface ForeignCollection<T>
public CloseableWrappedIterable<T> getWrappedIterable(int flags)
ForeignCollection
ForeignCollection.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 close()
CloseableWrappedIterable
close
in interface CloseableWrappedIterable<T>
close
in interface AutoCloseable
public void closeLastIterator()
ForeignCollection
Collection.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>
public boolean isEager()
ForeignCollection
isEager
in interface ForeignCollection<T>
public int size()
public boolean isEmpty()
public boolean contains(Object o)
public boolean containsAll(Collection<?> c)
containsAll
in interface Collection<T>
containsAll
in interface List<T>
public Object[] toArray()
public <E> E[] toArray(E[] array)
public boolean add(T data)
ForeignCollection
Dao.create(Object)
. If the object has already been created in the database then you just need to set the
foreign field on the object and call Dao.update(Object)
. If you add it here the DAO will try to create it
in the database again which will most likely cause an error.add
in interface ForeignCollection<T>
add
in interface Collection<T>
add
in interface List<T>
add
in class BaseForeignCollection<T,ID>
Collection.add(Object)
public boolean addAll(Collection<? extends T> collection)
BaseForeignCollection
addAll
in interface Collection<T>
addAll
in interface List<T>
addAll
in class BaseForeignCollection<T,ID>
public boolean remove(Object data)
BaseForeignCollection
remove
in interface Collection<T>
remove
in interface List<T>
remove
in class BaseForeignCollection<T,ID>
public boolean removeAll(Collection<?> collection)
BaseForeignCollection
removeAll
in interface Collection<T>
removeAll
in interface List<T>
removeAll
in class BaseForeignCollection<T,ID>
public boolean retainAll(Collection<?> collection)
BaseForeignCollection
retainAll
in interface Collection<T>
retainAll
in interface List<T>
retainAll
in class BaseForeignCollection<T,ID>
public int updateAll() throws SQLException
ForeignCollection
updateAll
in interface ForeignCollection<T>
SQLException
public int refreshAll() throws SQLException
ForeignCollection
ForeignCollection.refreshCollection()
.refreshAll
in interface ForeignCollection<T>
SQLException
public int refreshCollection() throws SQLException
ForeignCollection
refreshCollection
in interface ForeignCollection<T>
SQLException
public boolean addAll(int index, Collection<? extends T> c)
public int lastIndexOf(Object element)
lastIndexOf
in interface List<T>
public ListIterator<T> listIterator()
listIterator
in interface List<T>
List.listIterator()
public ListIterator<T> listIterator(int index)
listIterator
in interface List<T>
List.listIterator(int)
public boolean equals(Object obj)
This documentation is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.