org.neodatis.odb.core.query.execution
Class GenericQueryExecutor

java.lang.Object
  extended by org.neodatis.odb.core.query.execution.GenericQueryExecutor
All Implemented Interfaces:
IMultiClassQueryExecutor, IQueryExecutor
Direct Known Subclasses:
CriteriaQueryExecutor, NativeQueryExecutor, ValuesCriteriaQueryExecutor

public abstract class GenericQueryExecutor
extends java.lang.Object
implements IMultiClassQueryExecutor

Generic query executor. This class does all the job of iterating in the object list and call particular query matching to check if the object must be included in the query result.

If the query has index, An execution plan is calculated to optimize the execution. The query execution plan is calculated by subclasses (using abstract method getExecutionPlan).


Field Summary
protected  IQueryExecutorCallback callback
           
protected  ClassInfo classInfo
          The class of the object being fetched
protected  NonNativeObjectInfo currentNnoi
           
protected  OID currentOid
           
protected  boolean executeStartAndEndOfQueryAction
          Used for multi class executor to indicate not to execute start and end method of query result action
static java.lang.String LOG_ID
           
protected  OID nextOID
          The next object position
protected  IObjectReader objectReader
          The object used to read object data from database
protected  IQuery query
          The query being executed
protected  ISession session
          The current database session
protected  IStorageEngine storageEngine
          The storage engine
 
Constructor Summary
GenericQueryExecutor(IQuery query, IStorageEngine engine)
           
 
Method Summary
 OdbComparable buildOrderByKey(AttributeValuesMap values)
           
 OdbComparable buildOrderByKey(NonNativeObjectInfo nnoi)
           
 OdbComparable buildOrderByKey(java.lang.Object object)
          TODO very bad.
abstract  java.lang.Comparable computeIndexKey(ClassInfo ci, ClassInfoIndex index)
           
<T> Objects<T>
execute(boolean inMemory, int startIndex, int endIndex, boolean returnObjects, IMatchingObjectAction queryResultAction)
          The main query execution method
 boolean executeStartAndEndOfQueryAction()
          Used to indicate if the execute method must call start and end method of the queryResultAction.
abstract  java.lang.Object getCurrentObjectMetaRepresentation()
          This can be a NonNAtiveObjectInf or AttributeValuesMap
abstract  IQueryExecutionPlan getExecutionPlan()
           
abstract  java.lang.String getFullClassName(IQuery query)
           
 IQuery getQuery()
           
 IStorageEngine getStorageEngine()
           
abstract  boolean matchObjectWithOid(OID oid, boolean loadObjectInfo, boolean inMemory)
          Check if the object with oid matches the query, returns true This method must compute the next object oid and the orderBy key if it exists!
abstract  void prepareQuery()
           
 void setClassInfo(ClassInfo classInfo)
          The class on which to execute the query
 void setExecuteStartAndEndOfQueryAction(boolean yes)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_ID

public static final java.lang.String LOG_ID
See Also:
Constant Field Values

storageEngine

protected IStorageEngine storageEngine
The storage engine


query

protected IQuery query
The query being executed


classInfo

protected ClassInfo classInfo
The class of the object being fetched


objectReader

protected IObjectReader objectReader
The object used to read object data from database


session

protected ISession session
The current database session


nextOID

protected OID nextOID
The next object position


currentOid

protected OID currentOid

currentNnoi

protected NonNativeObjectInfo currentNnoi

callback

protected IQueryExecutorCallback callback

executeStartAndEndOfQueryAction

protected boolean executeStartAndEndOfQueryAction
Used for multi class executor to indicate not to execute start and end method of query result action

Constructor Detail

GenericQueryExecutor

public GenericQueryExecutor(IQuery query,
                            IStorageEngine engine)
Method Detail

getExecutionPlan

public abstract IQueryExecutionPlan getExecutionPlan()

prepareQuery

public abstract void prepareQuery()

computeIndexKey

public abstract java.lang.Comparable computeIndexKey(ClassInfo ci,
                                                     ClassInfoIndex index)

getCurrentObjectMetaRepresentation

public abstract java.lang.Object getCurrentObjectMetaRepresentation()
This can be a NonNAtiveObjectInf or AttributeValuesMap

Returns:

matchObjectWithOid

public abstract boolean matchObjectWithOid(OID oid,
                                           boolean loadObjectInfo,
                                           boolean inMemory)
Check if the object with oid matches the query, returns true This method must compute the next object oid and the orderBy key if it exists!

Parameters:
oid - The object position
loadObjectInfo - To indicate if object must loaded (when the query indicator 'in memory' is false, we do not need to load object, only ids)
inMemory - To indicate if object must be actually loaded to memory

execute

public <T> Objects<T> execute(boolean inMemory,
                              int startIndex,
                              int endIndex,
                              boolean returnObjects,
                              IMatchingObjectAction queryResultAction)
Description copied from interface: IQueryExecutor
The main query execution method

Specified by:
execute in interface IQueryExecutor
Returns:

getFullClassName

public abstract java.lang.String getFullClassName(IQuery query)
Specified by:
getFullClassName in interface IQueryExecutor

buildOrderByKey

public OdbComparable buildOrderByKey(java.lang.Object object)
TODO very bad. Should remove the instanceof

Parameters:
object -
Returns:

buildOrderByKey

public OdbComparable buildOrderByKey(NonNativeObjectInfo nnoi)

buildOrderByKey

public OdbComparable buildOrderByKey(AttributeValuesMap values)

executeStartAndEndOfQueryAction

public boolean executeStartAndEndOfQueryAction()
Description copied from interface: IMultiClassQueryExecutor
Used to indicate if the execute method must call start and end method of the queryResultAction. The default is yes. For MultiClass Query executor, it is set to false to avoid to reset the result

Specified by:
executeStartAndEndOfQueryAction in interface IMultiClassQueryExecutor
Returns:
true or false to indicate if start and end method of queryResultAction must be executed

setExecuteStartAndEndOfQueryAction

public void setExecuteStartAndEndOfQueryAction(boolean yes)
Specified by:
setExecuteStartAndEndOfQueryAction in interface IMultiClassQueryExecutor

getStorageEngine

public IStorageEngine getStorageEngine()
Specified by:
getStorageEngine in interface IMultiClassQueryExecutor

getQuery

public IQuery getQuery()
Specified by:
getQuery in interface IMultiClassQueryExecutor

setClassInfo

public void setClassInfo(ClassInfo classInfo)
Description copied from interface: IMultiClassQueryExecutor
The class on which to execute the query

Specified by:
setClassInfo in interface IMultiClassQueryExecutor