Package org.datanucleus.store.query
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:
java.io.Serializable,java.lang.Iterable<E>,java.util.Collection<E>,java.util.List<E>,QueryResult<E>
- Direct Known Subclasses:
CandidateIdsQueryResult
public abstract class AbstractQueryResult<E> extends java.util.AbstractList<E> implements QueryResult<E>, java.io.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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected ApiAdapterapiprotected booleanclosedWhether the results are close.protected java.util.List<ManagedConnectionResourceListener>connectionListenersList of listeners to notify when the query results are closed.protected booleanloadResultsAtCommitWhether to load any unread results at commit (when connection is closed).protected QueryqueryThe Query object.protected java.lang.StringresultSizeMethodMethod for getting the size of the results.private static longserialVersionUIDprotected intsizesize of the query results.
-
Constructor Summary
Constructors Constructor Description AbstractQueryResult(Query query)Constructor of the result from a Query.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidadd(int index, E element)Method to add a result.booleanadd(E o)Method to add results.booleanaddAll(int index, java.util.Collection c)Method to add results.voidaddConnectionListener(ManagedConnectionResourceListener listener)Method to register a listener to be notified when the query result is closing.protected voidassertIsOpen()Internal 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 voidcloseResults()Inform the query result that we are closing the results now.protected abstract voidclosingConnection()Inform the query result that the connection is being closed so perform any operations now, or rest in peace.booleancontains(java.lang.Object o)Method to check if the specified object is contained in this result.booleancontainsAll(java.util.Collection c)Method to check if all of the specified objects are contained here.voiddisconnect()Method to disconnect the results from the ExecutionContext, meaning that thereafter it just behaves like a List.abstract booleanequals(java.lang.Object o)Equality operator for QueryResults.abstract Eget(int index)Method to retrieve a particular element from the list.protected intgetSizeUsingMethod()Method to get the size using the "resultSizeMethod".inthashCode()Accessor for the hashcode of this objectintindexOf(java.lang.Object o)Method to check the index of a result.booleanisEmpty()Returns true if this collection contains no elements.protected booleanisOpen()Accessor whether the results are open.abstract java.util.Iterator<E>iterator()Accessor for an iterator for the results.intlastIndexOf(java.lang.Object o)Method to check the last index of a result.abstract java.util.ListIterator<E>listIterator()Accessor for a list iterator for the results.Eremove(int index)Method to remove a result.Eset(int index, E element)Method to set the position of a result.intsize()Method to return the size of the result.java.util.List<E>subList(int fromIndex, int toIndex)Method return a sub list of results.java.lang.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 java.util.AbstractCollection
addAll, remove, removeAll, retainAll, toString
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
closed
protected boolean closed
Whether the results are close.
-
query
protected Query query
The Query object.
-
connectionListeners
protected java.util.List<ManagedConnectionResourceListener> connectionListeners
List of listeners to notify when the query results are closed.
-
api
protected ApiAdapter api
-
size
protected int size
size of the query results. Is -1 until known.
-
resultSizeMethod
protected java.lang.String resultSizeMethod
Method for getting the size of the results.
-
loadResultsAtCommit
protected boolean loadResultsAtCommit
Whether to load any unread results at commit (when connection is closed).
-
-
Constructor Detail
-
AbstractQueryResult
public AbstractQueryResult(Query query)
Constructor of the result from a Query.- Parameters:
query- The Query
-
-
Method Detail
-
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
public void addConnectionListener(ManagedConnectionResourceListener listener)
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
public abstract boolean equals(java.lang.Object o)
Equality operator for QueryResults. Overrides the AbstractList implementation since that uses size() and iterator() and that would cause problems when closed.
-
get
public abstract E get(int index)
Method to retrieve a particular element from the list.
-
hashCode
public int hashCode()
Accessor for the hashcode of this object
-
iterator
public abstract java.util.Iterator<E> iterator()
Accessor for an iterator for the results.
-
listIterator
public abstract java.util.ListIterator<E> listIterator()
Accessor for a list iterator for the results.
-
isEmpty
public boolean isEmpty()
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.
-
subList
public java.util.List<E> subList(int fromIndex, int toIndex)
Method return a sub list of results. Method create new ArrayList, iterate and call get() in subclass for optimum performance.
-
toArray
public java.lang.Object[] toArray()
Method to return the results as an array.
-
toArray
public <T> T[] toArray(T[] a)
Method to return the results as an 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:
java.lang.ArithmeticException- if the size overflows the integer return type
-
add
public void add(int index, E element)Method to add a result. Unsupported.
-
add
public boolean add(E o)
Method to add results. Unsupported.
-
addAll
public boolean addAll(int index, java.util.Collection c)Method to add results. Unsupported.
-
clear
public void clear()
Method to clear the results.
-
contains
public boolean contains(java.lang.Object o)
Method to check if the specified object is contained in this result.
-
containsAll
public boolean containsAll(java.util.Collection c)
Method to check if all of the specified objects are contained here.
-
indexOf
public int indexOf(java.lang.Object o)
Method to check the index of a result. Not supported.
-
lastIndexOf
public int lastIndexOf(java.lang.Object o)
Method to check the last index of a result. Not supported.
-
remove
public E remove(int index)
Method to remove a result. Not supported.
-
-