org.garret.perst
Interface Query<T>


public interface Query<T>

Class representing JSQL query. JSQL allows to select members of Perst collections using SQL like predicate. Almost all Perst collections have select() method which execute arbitrary JSQL query. But it is also possible to create Query instance explicitely, Using storage.createQuery class. In this case it is possible to specify query with parameters, once prepare query and then multiple times specify parameters and execute it. Also Query interface allows to specify indices and resolvers. JSQL can use arbitrary Perst GenericIndex to perform fast selection if object instead of sequeial search. And user provided resolver allows to substitute SQL joins.


Method Summary
 void addIndex(java.lang.String key, GenericIndex<T> index)
          Add index which can be used to optimize query execution (replace sequential search with direct index access)
 void enableRuntimeErrorReporting(boolean enabled)
          Enable or disable reporting of runtime errors on console.
 java.util.Iterator<T> execute(java.util.Iterator<T> iterator)
          Execute prepared query
 void prepare(java.lang.Class cls, java.lang.String predicate)
          Prepare SQL statement
 void prepare(java.lang.String className, java.lang.String predicate)
          Prepare SQL statement
 java.util.Iterator<T> select(java.lang.Class cls, java.util.Iterator<T> iterator, java.lang.String predicate)
          Execute query
 java.util.Iterator<T> select(java.lang.String className, java.util.Iterator<T> iterator, java.lang.String predicate)
          Execute query
 void setBoolParameter(int index, boolean value)
          Set value of query parameter
 void setIntParameter(int index, long value)
          Set value of query parameter
 void setParameter(int index, java.lang.Object value)
          Set value of query parameter
 void setRealParameter(int index, double value)
          Set value of query parameter
 void setResolver(java.lang.Class original, java.lang.Class resolved, Resolver resolver)
          Specify resolver.
 

Method Detail

addIndex

void addIndex(java.lang.String key,
              GenericIndex<T> index)
Add index which can be used to optimize query execution (replace sequential search with direct index access)

Parameters:
key - indexed field
index - implementation of index

enableRuntimeErrorReporting

void enableRuntimeErrorReporting(boolean enabled)
Enable or disable reporting of runtime errors on console. Subtime errors during JSQL query are reported in two ways:
  1. If query error reporting is enabled then message is printed to System.err
  2. If storage listener is registered, then JSQLRuntimeError of method listener is invoked
By default reporting to System.err is enabled.

Parameters:
enabled - if true then reportnig is enabled

execute

java.util.Iterator<T> execute(java.util.Iterator<T> iterator)
Execute prepared query

Parameters:
iterator - iterator for sequential access to objects in the table
Returns:
iterator through selected objects. This iterator doesn't support remove() method.

prepare

void prepare(java.lang.Class cls,
             java.lang.String predicate)
Prepare SQL statement

Parameters:
cls - class of iterated objects
predicate - selection crieria with '?' placeholders for parameter value

prepare

void prepare(java.lang.String className,
             java.lang.String predicate)
Prepare SQL statement

Parameters:
className - name of the class of iterated objects
predicate - selection crieria with '?' placeholders for parameter value

select

java.util.Iterator<T> select(java.lang.Class cls,
                             java.util.Iterator<T> iterator,
                             java.lang.String predicate)
                             throws CompileError
Execute query

Parameters:
cls - class of inspected objects
iterator - iterator for sequential access to objects in the table
predicate - selection crieria
Returns:
iterator through selected objects. This iterator doesn't support remove() method.
Throws:
CompileError

select

java.util.Iterator<T> select(java.lang.String className,
                             java.util.Iterator<T> iterator,
                             java.lang.String predicate)
                             throws CompileError
Execute query

Parameters:
className - name of the class of inspected objects
iterator - iterator for sequential access to objects in the table
predicate - selection crieria
Returns:
iterator through selected objects. This iterator doesn't support remove() method.
Throws:
CompileError

setBoolParameter

void setBoolParameter(int index,
                      boolean value)
Set value of query parameter

Parameters:
index - parameters index (1 based)
value - value of boolean parameter

setIntParameter

void setIntParameter(int index,
                     long value)
Set value of query parameter

Parameters:
index - parameters index (1 based)
value - value of integer parameter

setParameter

void setParameter(int index,
                  java.lang.Object value)
Set value of query parameter

Parameters:
index - parameters index (1 based)
value - value of parameter (for scalar parameters instance f correspondendt wrapper class, for example java.lang.Long

setRealParameter

void setRealParameter(int index,
                      double value)
Set value of query parameter

Parameters:
index - parameters index (1 based)
value - value of real parameter

setResolver

void setResolver(java.lang.Class original,
                 java.lang.Class resolved,
                 Resolver resolver)
Specify resolver. Resolver can be used to replaced SQL JOINs: given object ID, it will provide reference to the resolved object

Parameters:
original - class which instances will have to be resolved
resolved - class of the resolved object
resolver - class implementing Resolver interface