Class AbstractQueryResult<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
org.datanucleus.store.query.AbstractQueryResult<E>
- Type Parameters:
E- Type of "element" returned by this query result
- All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, List<E>, QueryResult<E>
- Direct Known Subclasses:
CandidateIdsQueryResult
public abstract class AbstractQueryResult<E>
extends AbstractList<E>
implements QueryResult<E>, Serializable
Abstract representation of a QueryResult.
Provides default implementations of the majority of list methods that we aren't likely to
be providing in a concrete query result.
This class is used where your query implementation needs to return a wrapper to a List so that
you can intercept calls and convert a row of the results into object(s), to avoid full instantiation
at creation.
Supports the following query extensions :-
- datanucleus.query.resultSizeMethod The method used to find the size of the result set.
- datanucleus.query.loadResultsAtCommit Whether to load all results when the connection is closing. Has no effect if caching is not used.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ApiAdapterprotected booleanWhether the results are close.protected List<ManagedConnectionResourceListener> List of listeners to notify when the query results are closed.protected booleanWhether to load any unread results at commit (when connection is closed).protected QueryThe Query object.protected StringMethod for getting the size of the results.private static final longprotected intsize of the query results.Fields inherited from class AbstractList
modCount -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidMethod to add a result.booleanMethod to add results.booleanaddAll(int index, Collection c) Method to add results.voidMethod to register a listener to be notified when the query result is closing.protected voidInternal method to throw an Exception if the ResultSet is open.voidclear()Method to clear the results.voidclose()Method to close the results, meaning that they are inaccessible after this point.protected abstract voidInform the query result that we are closing the results now.protected abstract voidInform the query result that the connection is being closed so perform any operations now, or rest in peace.booleanMethod to check if the specified object is contained in this result.booleanMethod to check if all of the specified objects are contained here.voidMethod to disconnect the results from the ExecutionContext, meaning that thereafter it just behaves like a List.abstract booleanEquality operator for QueryResults.abstract Eget(int index) Method to retrieve a particular element from the list.protected intMethod to get the size using the "resultSizeMethod".inthashCode()Accessor for the hashcode of this objectintMethod to check the index of a result.booleanisEmpty()Returns true if this collection contains no elements.protected booleanisOpen()Accessor whether the results are open.iterator()Accessor for an iterator for the results.intMethod to check the last index of a result.abstract ListIterator<E> Accessor for a list iterator for the results.remove(int index) Method to remove a result.Method to set the position of a result.intsize()Method to return the size of the result.subList(int fromIndex, int toIndex) Method return a sub list of results.Object[]toArray()Method to return the results as an array.<T> T[]toArray(T[] a) Method to return the results as an array.Methods inherited from class AbstractList
listIterator, removeRangeMethods inherited from interface Collection
parallelStream, removeIf, streamMethods inherited from interface List
addAll, remove, removeAll, replaceAll, retainAll, sort, spliterator
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
closed
protected boolean closedWhether the results are close. -
query
The Query object. -
connectionListeners
List of listeners to notify when the query results are closed. -
api
-
size
protected int sizesize of the query results. Is -1 until known. -
resultSizeMethod
Method for getting the size of the results. -
loadResultsAtCommit
protected boolean loadResultsAtCommitWhether to load any unread results at commit (when connection is closed).
-
-
Constructor Details
-
AbstractQueryResult
Constructor of the result from a Query.- Parameters:
query- The Query
-
-
Method Details
-
disconnect
public void disconnect()Method to disconnect the results from the ExecutionContext, meaning that thereafter it just behaves like a List. All remaining results are read in at this point (unless selected not to be).- Specified by:
disconnectin interfaceQueryResult<E>
-
closingConnection
protected abstract void closingConnection()Inform the query result that the connection is being closed so perform any operations now, or rest in peace. -
closeResults
protected abstract void closeResults()Inform the query result that we are closing the results now. -
close
public void close()Method to close the results, meaning that they are inaccessible after this point.- Specified by:
closein interfaceQueryResult<E>
-
addConnectionListener
Method to register a listener to be notified when the query result is closing.- Parameters:
listener- The listener
-
isOpen
protected boolean isOpen()Accessor whether the results are open.- Returns:
- Whether it is open.
-
assertIsOpen
protected void assertIsOpen()Internal method to throw an Exception if the ResultSet is open. -
equals
Equality operator for QueryResults. Overrides the AbstractList implementation since that uses size() and iterator() and that would cause problems when closed.- Specified by:
equalsin interfaceCollection<E>- Specified by:
equalsin interfaceList<E>- Overrides:
equalsin classAbstractList<E>- Parameters:
o- The object to compare against- Returns:
- Whether they are equal
-
get
-
hashCode
public int hashCode()Accessor for the hashcode of this object- Specified by:
hashCodein interfaceCollection<E>- Specified by:
hashCodein interfaceList<E>- Overrides:
hashCodein classAbstractList<E>- Returns:
- The hash code
-
iterator
-
listIterator
Accessor for a list iterator for the results.- Specified by:
listIteratorin interfaceList<E>- Overrides:
listIteratorin classAbstractList<E>- Returns:
- a ListIterator with the query results
-
isEmpty
public boolean isEmpty()Returns true if this collection contains no elements.- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceList<E>- Overrides:
isEmptyin classAbstractCollection<E>- Returns:
- true if this collection contains no elements.
-
size
public int size()Method to return the size of the result. Hands off the calculation of the size to getSizeUsingMethod() which should be overridden if you want to support other methods.- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceList<E>- Specified by:
sizein classAbstractCollection<E>- Returns:
- The size of the result.
-
subList
Method return a sub list of results. Method create new ArrayList, iterate and call get() in subclass for optimum performance. -
toArray
Method to return the results as an array.- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceList<E>- Overrides:
toArrayin classAbstractCollection<E>- Returns:
- The array.
-
toArray
public <T> T[] toArray(T[] a) Method to return the results as an array.- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceList<E>- Overrides:
toArrayin classAbstractCollection<E>- Parameters:
a- The array to copy into.- Returns:
- The array.
-
getSizeUsingMethod
protected int getSizeUsingMethod()Method to get the size using the "resultSizeMethod". This implementation supports "COUNT" method. Override this in subclasses to implement other methods.- Returns:
- The size
- Throws:
ArithmeticException- if the size overflows the integer return type
-
add
-
add
Method to add results. Unsupported.- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceList<E>- Overrides:
addin classAbstractList<E>- Parameters:
o- The result to add- Returns:
- true if added successfully
-
addAll
Method to add results. Unsupported. -
clear
public void clear()Method to clear the results.- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceList<E>- Overrides:
clearin classAbstractList<E>
-
contains
Method to check if the specified object is contained in this result.- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceList<E>- Overrides:
containsin classAbstractCollection<E>- Parameters:
o- The object- Returns:
- Whether it is contained here.
-
containsAll
Method to check if all of the specified objects are contained here.- Specified by:
containsAllin interfaceCollection<E>- Specified by:
containsAllin interfaceList<E>- Overrides:
containsAllin classAbstractCollection<E>- Parameters:
c- The collection of objects- Returns:
- Whether they are all contained here.
-
indexOf
-
lastIndexOf
Method to check the last index of a result. Not supported.- Specified by:
lastIndexOfin interfaceList<E>- Overrides:
lastIndexOfin classAbstractList<E>- Parameters:
o- The result- Returns:
- The last index
-
remove
-
set
-