org.garret.jsql
Class Query

java.lang.Object
  extended byorg.garret.jsql.Query

public class Query
extends java.lang.Object

Class representing JSQL query.


Constructor Summary
Query()
           
 
Method Summary
 boolean add(java.lang.Object obj)
          Add object to the selection.
static java.lang.Object castLiteral(java.lang.Class type, java.lang.Object value)
          Cast literal to the stpecified type.
 void enableRuntimeErrorReporting(boolean enabled)
          Enable or disable reporting of runtime errors By default it is enabled.
 java.lang.Object[] execute(QueryIterator iterator)
          Execute prepared query
 java.lang.Object[] execute(QueryIterator iterator, int limit)
          Execute prepared query
 java.lang.Object[] execute(QueryIterator iterator, int limit, int nThreads)
          Execute prepared query
static java.lang.Object normalizeKeyValue(java.lang.Object value)
          Convert key value to the form used by JSQL to make it possible to compare it with JSQL expression value.
 void prepare(java.lang.Class cls, java.lang.String query)
          Prepare SQL statement
 void prepare(java.lang.String className, java.lang.String query)
          Prepare SQL statement
 java.lang.Object[] select(java.lang.Class cls, QueryIterator iterator, java.lang.String query)
          Execute query
 java.lang.Object[] select(java.lang.Class cls, QueryIterator iterator, java.lang.String query, int limit)
          Execute query
 java.lang.Object[] select(java.lang.Class cls, QueryIterator iterator, java.lang.String query, int limit, int nThreads)
          Execute query
 java.lang.Object[] select(java.lang.String className, QueryIterator iterator, java.lang.String query)
          Execute query
 java.lang.Object[] select(java.lang.String className, QueryIterator iterator, java.lang.String query, int limit)
          Execute query
 java.lang.Object[] select(java.lang.String className, QueryIterator iterator, java.lang.String query, int limit, int nThreads)
          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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Query

public Query()
Method Detail

select

public java.lang.Object[] select(java.lang.Class cls,
                                 QueryIterator iterator,
                                 java.lang.String query,
                                 int limit,
                                 int nThreads)
                          throws CompileError
Execute query

Parameters:
cls - class of inspected objects
iterator - iterator for sequential and direct access to objects in the table
query - selection crieria
limit - limitation for numbe of selected records
nThreads - number of threads for concurrent execution of sequential search, if 0, then will be set equal to the number of processors available for the JVM
Returns:
array of selected objects
Throws:
CompileError

select

public java.lang.Object[] select(java.lang.Class cls,
                                 QueryIterator iterator,
                                 java.lang.String query)
                          throws CompileError
Execute query

Parameters:
cls - class of inspected objects
iterator - iterator for sequential and direct access to objects in the table
query - selection crieria
Returns:
array of selected objects
Throws:
CompileError

select

public java.lang.Object[] select(java.lang.Class cls,
                                 QueryIterator iterator,
                                 java.lang.String query,
                                 int limit)
                          throws CompileError
Execute query

Parameters:
cls - class of inspected objects
iterator - iterator for sequential and direct access to objects in the table
query - selection crieria
limit - limitation for numbe of selected records
Returns:
array of selected objects
Throws:
CompileError

select

public java.lang.Object[] select(java.lang.String className,
                                 QueryIterator iterator,
                                 java.lang.String query,
                                 int limit,
                                 int nThreads)
Execute query

Parameters:
className - name of the class of inspected objects
iterator - iterator for sequential and direct access to objects in the table
query - selection crieria
limit - limitation for numbe of selected records
nThreads - number of threads for concurrent execution of sequential search, if 0, then will be set equal to the number of processors available for the JVM
Returns:
array of selected objects

select

public java.lang.Object[] select(java.lang.String className,
                                 QueryIterator iterator,
                                 java.lang.String query)
                          throws CompileError
Execute query

Parameters:
className - name of the class of inspected objects
iterator - iterator for sequential and direct access to objects in the table
query - selection crieria
Returns:
array of selected objects
Throws:
CompileError

select

public java.lang.Object[] select(java.lang.String className,
                                 QueryIterator iterator,
                                 java.lang.String query,
                                 int limit)
                          throws CompileError
Execute query

Parameters:
className - name of the class of inspected objects
iterator - iterator for sequential and direct access to objects in the table
query - selection crieria
limit - limitation for numbe of selected records
Returns:
array of selected objects
Throws:
CompileError

setParameter

public 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

setIntParameter

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

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

setRealParameter

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

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

setBoolParameter

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

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

add

public boolean add(java.lang.Object obj)
Add object to the selection. This method ise used by QueryIterator.getByKeyRange method to store selected records

Parameters:
obj - object selected by index
Returns:
false is selection limit is reached, false otherwise

prepare

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

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

prepare

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

Parameters:
query - selection crieria with '?' placeholders for parameter value

execute

public java.lang.Object[] execute(QueryIterator iterator)
Execute prepared query

Parameters:
iterator - iterator for sequential and direct access to objects in the table
Returns:
array of selected objects

execute

public java.lang.Object[] execute(QueryIterator iterator,
                                  int limit)
Execute prepared query

Parameters:
iterator - iterator for sequential and direct access to objects in the table
limit - limitation for numbe of selected records
Returns:
array of selected objects

execute

public java.lang.Object[] execute(QueryIterator iterator,
                                  int limit,
                                  int nThreads)
Execute prepared query

Parameters:
iterator - iterator for sequential and direct access to objects in the table
limit - limitation for numbe of selected records
nThreads - number of threads for concurrent execution of sequential search, if 0, then will be set equal to the number of processors available for the JVM
Returns:
array of selected objects

enableRuntimeErrorReporting

public void enableRuntimeErrorReporting(boolean enabled)
Enable or disable reporting of runtime errors By default it is enabled.

Parameters:
enabled - if true then reportnig is enabled

setResolver

public 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

normalizeKeyValue

public static java.lang.Object normalizeKeyValue(java.lang.Object value)
Convert key value to the form used by JSQL to make it possible to compare it with JSQL expression value. This method should be used in index access implementations in QueryIterators to store key value.

Parameters:
value - value of the key
Returns:
normalized key value

castLiteral

public static java.lang.Object castLiteral(java.lang.Class type,
                                           java.lang.Object value)
Cast literal to the stpecified type. This method is alternative to normalizeKeyValue. If key values are not stored in index in normalized form, then search literals should be converted to the type of the key field. This conversion is performed by JSQL when field type is know at compile time and should be also performed by QueryIterator in case of using dynamic binding.

Parameters:
type - type to which literla should be converted
value - literal value
Returns:
converted literal value or null value of literal is out of specified type domain