org.benow.repository.query
Class QueryContext

java.lang.Object
  extended by org.benow.repository.query.QueryContext

public class QueryContext
extends java.lang.Object

A QueryContext is an accessor to an instance of a query. It uses the field information of a given query, along with supplied field values to perform a query. The separation between QueryContext and ClassQuery allows for query preparation before execution, speeding things up, and also allows for re-entrant code (multiple of the same query executing simultaneously).

Author:
andy

Nested Class Summary
static class QueryContext.ObjectsIterator
          repository: org.benow.repository.query.ObjectsIterator
static class QueryContext.OrderField
           
 
Method Summary
 QueryContext bind(int val)
          Adds an int to this context, returning this
 QueryContext bind(long from)
           
 QueryContext bind(java.lang.Object val)
          Adds an object to this context, returning this
 org.benow.java.collection.SubList<? extends PersistentObject> getAllObjects(Transaction tx)
           
 java.lang.Class getClassToQuery()
           
 PersistentObject getObject()
           
 java.lang.Object getObject(Transaction tx)
           
 ResultIterator<? extends PersistentObject> getObjectIterator()
           
 ResultIterator<? extends PersistentObject> getObjectIterator(Transaction tx)
           
 java.util.List getObjects()
          Gets object using a one-off transaction from default connection to default repository realm.
 org.benow.java.collection.SubList getObjects(int starting, int spanning)
           
 PersistentList getObjects(int from, int spanning, Transaction tx)
           
 void getObjects(JSQLList<?> holder, int starting, int spanning)
           
 PersistentList getObjects(PersistentArrayList objects, Transaction tx)
          Gets all objects into the given collection
 PersistentList<? extends PersistentObject> getObjects(PopulateableArray objects, int starting, int spanning, Transaction tx)
          Fetches a subset of objects as dictated by this query into the given collection.
 java.util.List getObjects(Transaction tx)
           
 QueryContext.ObjectsIterator getObjectsIterator(Transaction tx)
          Returns an $ObjectsIterator over the objects (and specifications) in the query.
 java.lang.Object[] getParameters()
           
 ClassQuery getQuery()
           
 int getSpanning()
           
 int getStartIndex()
           
 boolean hasParameters()
           
 void setOrderField(QueryContext.OrderField orderPair)
           
 void setOrderField(java.lang.String fieldName)
          Orders ascending by given field.
 void setOrderField(java.lang.String fieldName, QueryContext.OrderField.Ordering ordering)
           
 void setOrderFields(QueryContext.OrderField[] orderPairs)
           
 void setOrderStatement(java.lang.String ordering)
           
 void setSpanning(int spanning)
           
 void setStartIndex(int startIdx)
          Fetch object starting from this index
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

setSpanning

public void setSpanning(int spanning)
Parameters:
spanning -

setStartIndex

public void setStartIndex(int startIdx)
Fetch object starting from this index

Parameters:
startIdx -

getSpanning

public int getSpanning()
Returns:
number of spanned items

setOrderStatement

public void setOrderStatement(java.lang.String ordering)

getObjectsIterator

public QueryContext.ObjectsIterator getObjectsIterator(Transaction tx)
                                                throws ObjectRepositoryException
Returns an $ObjectsIterator over the objects (and specifications) in the query. Calls to result.next() return a SubList (extended List) of items, which allows for inspection of the current position within the total number of results. Calls to result.hasNext() cause the next set of results to be fetched.

Parameters:
tx -
Returns:
iterator over results
Throws:
ObjectRepositoryException - on initial fetch error
See Also:
SubList

getObject

public java.lang.Object getObject(Transaction tx)
                           throws NoSuchObjectException,
                                  ObjectRepositoryException
Parameters:
tx -
Returns:
object as queried
Throws:
ObjectRepositoryException
NoSuchObjectException

getObjects

public java.util.List getObjects(Transaction tx)
                          throws ObjectRepositoryException
Parameters:
tx -
Returns:
objects as queried
Throws:
ObjectRepositoryException

bind

public QueryContext bind(int val)
Adds an int to this context, returning this

Parameters:
val -
Returns:
this, after added value

bind

public QueryContext bind(java.lang.Object val)
Adds an object to this context, returning this

Parameters:
val -
Returns:
this, after added value

getClassToQuery

public java.lang.Class getClassToQuery()
Returns:
class that is queried

getQuery

public ClassQuery getQuery()
Returns:
query to which this context applies

getParameters

public java.lang.Object[] getParameters()
Returns:
parameters for queries

getStartIndex

public int getStartIndex()
Returns:
start index of the query

hasParameters

public boolean hasParameters()
Returns:
true if has parameters

bind

public QueryContext bind(long from)
Parameters:
from -
Returns:
added value

getObjects

public PersistentList getObjects(int from,
                                 int spanning,
                                 Transaction tx)
                          throws ObjectRepositoryException
Parameters:
from -
spanning -
tx -
Returns:
queried objects
Throws:
ObjectRepositoryException

getObjects

public PersistentList getObjects(PersistentArrayList objects,
                                 Transaction tx)
                          throws ObjectRepositoryException
Gets all objects into the given collection

Parameters:
objects -
tx -
Throws:
ObjectRepositoryException

getObjects

public PersistentList<? extends PersistentObject> getObjects(PopulateableArray objects,
                                                             int starting,
                                                             int spanning,
                                                             Transaction tx)
                                                      throws ObjectRepositoryException
Fetches a subset of objects as dictated by this query into the given collection.

Parameters:
objects -
starting -
spanning -
tx -
Throws:
ObjectRepositoryException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getAllObjects

public org.benow.java.collection.SubList<? extends PersistentObject> getAllObjects(Transaction tx)
                                                                            throws ObjectRepositoryException
Parameters:
tx -
Returns:
objects SubList.FROM_START and SubList.SPANNING_ALL
Throws:
ObjectRepositoryException

getObjects

public java.util.List getObjects()
                          throws ObjectRepositoryError
Gets object using a one-off transaction from default connection to default repository realm. Nice and simple, but a bit inefficient if there is more than one operation to do with the repository.

Returns:
Throws:
ObjectRepositoryError

getObject

public PersistentObject getObject()
                           throws NoSuchObjectException
Throws:
NoSuchObjectException

getObjects

public org.benow.java.collection.SubList getObjects(int starting,
                                                    int spanning)

getObjects

public void getObjects(JSQLList<?> holder,
                       int starting,
                       int spanning)

getObjectIterator

public ResultIterator<? extends PersistentObject> getObjectIterator()

getObjectIterator

public ResultIterator<? extends PersistentObject> getObjectIterator(Transaction tx)

setOrderField

public void setOrderField(QueryContext.OrderField orderPair)

setOrderFields

public void setOrderFields(QueryContext.OrderField[] orderPairs)

setOrderField

public void setOrderField(java.lang.String fieldName,
                          QueryContext.OrderField.Ordering ordering)

setOrderField

public void setOrderField(java.lang.String fieldName)
Orders ascending by given field.