org.jpox.store.query
Class AbstractQueryResult

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractList
          extended byorg.jpox.store.query.AbstractQueryResult
All Implemented Interfaces:
java.util.Collection, java.util.List, Queryable, QueryResult, java.io.Serializable
Direct Known Subclasses:
ForwardQueryResult, InsensitiveQueryResult

public abstract class AbstractQueryResult
extends java.util.AbstractList
implements QueryResult, java.io.Serializable

Abstract representation of a QueryResult.

Version:
$Revision: 1.8 $
See Also:
Serialized Form

Field Summary
protected  boolean closed
          Whether the results are close.
protected static Localiser LOCALISER
          Localiser for messages.
protected  QueryExpression qs
          The Query statement used to generate these results.
protected  Query query
          The Query object.
protected  Query.ResultObjectFactory rof
          Result Object Factory used for accessing the elements.
protected  java.sql.ResultSet rs
          The ResultSet containing the results.
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
AbstractQueryResult(QueryExpression qs, Query query, Query.ResultObjectFactory rof, java.sql.ResultSet rs)
          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.
protected  void assertIsOpen()
          Internal method to throw a JDOUserException if the ResultSet is open.
 void clear()
          Method to clear the results.
 void close()
          Method to close the results.
protected  void closeResultSet()
          Internal method to close the ResultSet.
 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.
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.
 int hashCode()
          Accessor for the hashcode of this object
 int indexOf(java.lang.Object o)
          Method to check the index of a result.
abstract  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.
 QueryExpression newQueryStatement()
          Returns a prototypical query statement over the underlying collection.
 QueryExpression newQueryStatement(java.lang.Class candidateClass)
          Returns a prototypical query statement over the underlying collection, pre-filtered to include only objects of the specified class.
 Query.ResultObjectFactory newResultObjectFactory(QueryExpression stmt, boolean ignoreCache, java.lang.Class resultClass, boolean useFetchPlan)
          Returns a suitable query result factory for results produced by the specified query.
 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.
abstract  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 org.jpox.store.query.QueryResult
closingConnection
 
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 final Query query
The Query object.


rof

protected final Query.ResultObjectFactory rof
Result Object Factory used for accessing the elements.


rs

protected java.sql.ResultSet rs
The ResultSet containing the results.


qs

protected QueryExpression qs
The Query statement used to generate these results.


closed

protected boolean closed
Whether the results are close.

Constructor Detail

AbstractQueryResult

public AbstractQueryResult(QueryExpression qs,
                           Query query,
                           Query.ResultObjectFactory rof,
                           java.sql.ResultSet rs)
Constructor of the result from a Query.

Parameters:
qs - The Query Statement
query - The Query
rof - The factory to retrieve results from
rs - The ResultSet from the Query Statement
Method Detail

isOpen

protected boolean isOpen()
Accessor whether the results are open.

Returns:
Whether it is open.

assertIsOpen

protected void assertIsOpen()
Internal method to throw a JDOUserException if the ResultSet is open.


closeResultSet

protected void closeResultSet()
Internal method to close the ResultSet.


close

public void close()
Method to close the results.

Specified by:
close in interface QueryResult

add

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

Specified by:
add in interface java.util.List
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
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
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

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
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
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
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
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
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
Parameters:
o - The result
Returns:
The position

isEmpty

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

This implementation check if the result is empty.

Specified by:
isEmpty in interface Queryable
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.util.Collection
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
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
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
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
Parameters:
index - Position of the result
element - The result
Returns:
The element

size

public abstract int size()
Method to return the size of the result.

Specified by:
size in interface java.util.Collection
Returns:
The size of the result.

subList

public java.util.List subList(int fromIndex,
                              int toIndex)
Method return a sub list of results. Not supported.

Specified by:
subList in interface java.util.List
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
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
Parameters:
a - The array to copy into.
Returns:
The array.

newQueryStatement

public QueryExpression newQueryStatement()
Description copied from interface: Queryable
Returns a prototypical query statement over the underlying collection.

The returned query statement selects all applicable rows from the relevant base table(s) and the column that represents the element or element ID. The statement can then be modified to join additional tables, select more columns, add WHERE conditions, etc.

Specified by:
newQueryStatement in interface Queryable
Returns:
The new prototypical query statement.

newQueryStatement

public QueryExpression newQueryStatement(java.lang.Class candidateClass)
Description copied from interface: Queryable
Returns a prototypical query statement over the underlying collection, pre-filtered to include only objects of the specified class.

Specified by:
newQueryStatement in interface Queryable
Parameters:
candidateClass -
Returns:
The new prototypical query statement.
See Also:
Queryable.newQueryStatement()

newResultObjectFactory

public Query.ResultObjectFactory newResultObjectFactory(QueryExpression stmt,
                                                        boolean ignoreCache,
                                                        java.lang.Class resultClass,
                                                        boolean useFetchPlan)
Description copied from interface: Queryable
Returns a suitable query result factory for results produced by the specified query.

The stmt argument must have been obtained by a previous call to newQueryStatement() on the same Queryable.

Specified by:
newResultObjectFactory in interface Queryable
Parameters:
stmt - The query statement
ignoreCache - Whether to ignore the cache
resultClass - Create objects of a particular type
useFetchPlan - whether to use the fetch plan to retrieve fields in the same query
Returns:
A factory for creating PersistenceCapable objects from query results.


Copyright © -2007 . All Rights Reserved.