de.mguennewig.pobjects.memdb
Class PredicateQuery

java.lang.Object
  extended by de.mguennewig.pobjects.Query
      extended by de.mguennewig.pobjects.memdb.PredicateQuery

public abstract class PredicateQuery
extends Query

Abstract base class for all queries that are evaluated within the pobjects library using the Term instead of SQL.

The function calls are limited to the same set as for in-memory CHECK constraint tests.

SelectExpr and ViewDecl are not supported.

TODO: Queries over multiple tables will return the wrong result, when the tables are not combined over predicates with each other.

TODO: addConj(de.mguennewig.pobjects.Condition) skips terms that do not affect the result. Even thought it does not change the result the terms should stay in and ignored by the used EvalContext. The EvalContext should compute something like a plan.

TODO Distinct queries don't filter on the row tuple as we don't do cross-joins so far and the results for each table can be different in length.

Author:
Michael Günnewig

Field Summary
 
Fields inherited from class de.mguennewig.pobjects.Query
ASCENDING, DESCENDING
 
Constructor Summary
PredicateQuery(Container db)
          Creates a new empty query.
 
Method Summary
 void addConj(Condition condition)
          Adds the Condition to the list of boolean expressions, that are AND'ed together to form the WHERE part of the statement.
 int count()
          Returns the number of rows which will be returned by the query.
 EvalContext evaluate(boolean forCount)
          Evaluates this query.
 Record[][] execute()
          Executes this query and returns the result.
 PObjResultSet executeResultSet()
          Executes this query and returns the result set for row-by-row processing.
 
Methods inherited from class de.mguennewig.pobjects.Query
addArguments, addJoin, addOrderBy, addOrderBy, addOrderBy, addOrderBy, addTableExpr, addTableExpr, getContainer, getNumTableExprs, getTableExpr, isDistinct, isOrdered, pullInReference, setDistinct, setLimit
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PredicateQuery

public PredicateQuery(Container db)
Creates a new empty query.

Method Detail

addConj

public void addConj(Condition condition)
Adds the Condition to the list of boolean expressions, that are AND'ed together to form the WHERE part of the statement.

This method does some optimizations, like splitting AND expression which contain a join, and ignoring expressions that don't affect the result.

Overrides:
addConj in class Query
Throws:
java.lang.IllegalArgumentException - if condition is null.
See Also:
EvalContext.addWhereConj(de.mguennewig.pobjects.Term)

count

public int count()
Returns the number of rows which will be returned by the query.

Specified by:
count in class Query

evaluate

public EvalContext evaluate(boolean forCount)
Evaluates this query.

Specified by:
evaluate in class Query

execute

public Record[][] execute()
Executes this query and returns the result.

The real evaluation is done in evaluateQuery() and here only the last steps are done, like ORDER BY, OFFSET and LIMIT.

Overrides:
execute in class Query
Returns:
Array of array.
       result = new Record[][] {
         new Table_1[] { table_1[row_0], table_1[row_1], ... },
         new Table_2[] { table_2[row_0], table_2[row_1], ... },
         ...
       };
       
See Also:
Query.executeResultSet()

executeResultSet

public PObjResultSet executeResultSet()
Executes this query and returns the result set for row-by-row processing.

Specified by:
executeResultSet in class Query
Throws:
java.lang.UnsupportedOperationException
See Also:
Query.execute()