org.datanucleus.store.query
Class AbstractQueryResult

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList
          extended by org.datanucleus.store.query.AbstractQueryResult
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable, java.util.Collection, java.util.List, QueryResult
Direct Known Subclasses:
CandidateIdsQueryResult

public abstract class AbstractQueryResult
extends java.util.AbstractList
implements QueryResult, 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 :-

See Also:
Serialized Form

Field Summary
protected  boolean closed
          Whether the results are close.
protected  java.util.List<ManagedConnectionResourceListener> connectionListeners
          List of listeners to notify when the query results are closed.
protected  boolean loadResultsAtCommit
          Whether to load any unread results at commit (when connection is closed).
protected static Localiser LOCALISER
          Localiser for messages.
protected  Query query
          The Query object.
protected  java.lang.String resultSizeMethod
          Method for getting the size of the results.
protected  int size
          size of the query results.
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
AbstractQueryResult(Query query)
          Constructor of the result from a Query.
 
Method Summary
 void add(int index, java.lang.Object element)
          Method to add a result.
 boolean add(java.lang.Object o)
          Method to add results.
 boolean addAll(int index, java.util.Collection c)
          Method to add results.
 void addConnectionListener(ManagedConnectionResourceListener listener)
          Method to register a listener to be notified when the query result is closing.
protected  void assertIsOpen()
          Internal method to throw an Exception if the ResultSet is open.
 void clear()
          Method to clear the results.
 void close()
          Method to close the results, meaning that they are inaccessible after this point.
protected abstract  void closeResults()
          Inform the query result that we are closing the results now.
protected abstract  void closingConnection()
          Inform the query result that the connection is being closed so perform any operations now, or rest in peace.
 boolean contains(java.lang.Object o)
          Method to check if the specified object is contained in this result.
 boolean containsAll(java.util.Collection c)
          Method to check if all of the specified objects are contained here.
 void disconnect()
          Method to disconnect the results from the ObjectManager, meaning that thereafter it just behaves like a List.
abstract  boolean equals(java.lang.Object o)
          Equality operator for QueryResults.
abstract  java.lang.Object get(int index)
          Method to retrieve a particular element from the list.
protected  int getSizeUsingMethod()
          Method to get the size using the "resultSizeMethod".
 int hashCode()
          Accessor for the hashcode of this object
 int indexOf(java.lang.Object o)
          Method to check the index of a result.
 boolean isEmpty()
          Returns true if this collection contains no elements.
protected  boolean isOpen()
          Accessor whether the results are open.
abstract  java.util.Iterator iterator()
          Accessor for an iterator for the results.
 int lastIndexOf(java.lang.Object o)
          Method to check the last index of a result.
abstract  java.util.ListIterator listIterator()
          Accessor for a list iterator for the results.
 java.lang.Object remove(int index)
          Method to remove a result.
 java.lang.Object set(int index, java.lang.Object element)
          Method to set the position of a result.
 int size()
          Method to return the size of the result.
 java.util.List subList(int fromIndex, int toIndex)
          Method return a sub list of results.
 java.lang.Object[] toArray()
          Method to return the results as an array.
 java.lang.Object[] toArray(java.lang.Object[] a)
          Method to return the results as an array.
 
Methods inherited from class java.util.AbstractList
listIterator, removeRange
 
Methods inherited from class java.util.AbstractCollection
addAll, remove, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
addAll, remove, removeAll, retainAll
 
Methods inherited from interface java.util.List
addAll, remove, removeAll, retainAll
 

Field Detail

LOCALISER

protected static final Localiser LOCALISER
Localiser for messages.


query

protected Query query
The Query object.


closed

protected boolean closed
Whether the results are close.


connectionListeners

protected java.util.List<ManagedConnectionResourceListener> connectionListeners
List of listeners to notify when the query results are closed.


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 ObjectManager, 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:
disconnect in interface QueryResult

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:
close in interface QueryResult

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.


add

public void add(int index,
                java.lang.Object element)
Method to add a result. Unsupported.

Specified by:
add in interface java.util.List
Overrides:
add in class java.util.AbstractList
Parameters:
index - The position to add
element - The results to add

add

public boolean add(java.lang.Object o)
Method to add results. Unsupported.

Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.List
Overrides:
add in class java.util.AbstractList
Parameters:
o - The result to add
Returns:
true if added successfully

addAll

public boolean addAll(int index,
                      java.util.Collection c)
Method to add results. Unsupported.

Specified by:
addAll in interface java.util.List
Overrides:
addAll in class java.util.AbstractList
Parameters:
index - The position to add
c - The results to add
Returns:
true if added successfully

clear

public void clear()
Method to clear the results.

Specified by:
clear in interface java.util.Collection
Specified by:
clear in interface java.util.List
Overrides:
clear in class java.util.AbstractList

contains

public boolean contains(java.lang.Object o)
Method to check if the specified object is contained in this result.

Specified by:
contains in interface java.util.Collection
Specified by:
contains in interface java.util.List
Overrides:
contains in class java.util.AbstractCollection
Parameters:
o - The object
Returns:
Whether it is contained here.

containsAll

public boolean containsAll(java.util.Collection c)
Method to check if all of the specified objects are contained here.

Specified by:
containsAll in interface java.util.Collection
Specified by:
containsAll in interface java.util.List
Overrides:
containsAll in class java.util.AbstractCollection
Parameters:
c - The collection of objects
Returns:
Whether they are all contained here.

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.

Specified by:
equals in interface java.util.Collection
Specified by:
equals in interface java.util.List
Overrides:
equals in class java.util.AbstractList
Parameters:
o - The object to compare against
Returns:
Whether they are equal

get

public abstract java.lang.Object get(int index)
Method to retrieve a particular element from the list.

Specified by:
get in interface java.util.List
Specified by:
get in class java.util.AbstractList
Parameters:
index - The index of the element
Returns:
The element at index

hashCode

public int hashCode()
Accessor for the hashcode of this object

Specified by:
hashCode in interface java.util.Collection
Specified by:
hashCode in interface java.util.List
Overrides:
hashCode in class java.util.AbstractList
Returns:
The hash code

indexOf

public int indexOf(java.lang.Object o)
Method to check the index of a result. Not supported.

Specified by:
indexOf in interface java.util.List
Overrides:
indexOf in class java.util.AbstractList
Parameters:
o - The result
Returns:
The position

isEmpty

public boolean isEmpty()
Returns true if this collection contains no elements.

Specified by:
isEmpty in interface java.util.Collection
Specified by:
isEmpty in interface java.util.List
Overrides:
isEmpty in class java.util.AbstractCollection
Returns:
true if this collection contains no elements.

iterator

public abstract java.util.Iterator iterator()
Accessor for an iterator for the results.

Specified by:
iterator in interface java.lang.Iterable
Specified by:
iterator in interface java.util.Collection
Specified by:
iterator in interface java.util.List
Overrides:
iterator in class java.util.AbstractList
Returns:
The iterator

lastIndexOf

public int lastIndexOf(java.lang.Object o)
Method to check the last index of a result. Not supported.

Specified by:
lastIndexOf in interface java.util.List
Overrides:
lastIndexOf in class java.util.AbstractList
Parameters:
o - The result
Returns:
The last index

listIterator

public abstract java.util.ListIterator listIterator()
Accessor for a list iterator for the results.

Specified by:
listIterator in interface java.util.List
Overrides:
listIterator in class java.util.AbstractList
Returns:
a ListIterator with the query results

remove

public java.lang.Object remove(int index)
Method to remove a result. Not supported.

Specified by:
remove in interface java.util.List
Overrides:
remove in class java.util.AbstractList
Parameters:
index - The position of the result.
Returns:
The removed object.

set

public java.lang.Object set(int index,
                            java.lang.Object element)
Method to set the position of a result. Not supported.

Specified by:
set in interface java.util.List
Overrides:
set in class java.util.AbstractList
Parameters:
index - Position of the result
element - The result
Returns:
The element

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:
size in interface java.util.Collection
Specified by:
size in interface java.util.List
Specified by:
size in class java.util.AbstractCollection
Returns:
The size of the result.

subList

public java.util.List 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.

Specified by:
subList in interface java.util.List
Overrides:
subList in class java.util.AbstractList
Parameters:
fromIndex - start position
toIndex - end position (exclusive)
Returns:
The list of results

toArray

public java.lang.Object[] toArray()
Method to return the results as an array.

Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.List
Overrides:
toArray in class java.util.AbstractCollection
Returns:
The array.

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
Method to return the results as an array.

Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.List
Overrides:
toArray in class java.util.AbstractCollection
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


Copyright © 2010. All Rights Reserved.