org.datanucleus.store.mapped.expression
Interface QueryExpression


public interface QueryExpression

Expression for a query in language-independent form.


Method Summary
 void addExtension(java.lang.String key, java.lang.Object value)
          Method to define an extension for this query statement allowing control over its behaviour in generating a query.
 void addGroupingExpression(ScalarExpression expr)
          Method to add a grouping clause to the statement.
 void andCondition(BooleanExpression condition)
          add an condition to the query.
 void andCondition(BooleanExpression condition, boolean unionQueries)
          add an condition to the query and queries involved in the union if unionQuery is true
 void crossJoin(LogicSetExpression tableExpr, boolean unionQueries)
          Method to add tables/crossJoin but no joins to they, will be output as FROM TABLE1,TABLE2,TABLE3
 java.lang.String getCandidateAlias()
          Accessor for the candidate alias in use by the query.
 java.lang.Class getCandidateClass()
          Accessor for the candidate class of the query expression.
 ClassLoaderResolver getClassLoaderResolver()
          Accessor for the ClassLoaderResolver to use with this query statement.
 java.util.HashMap getExtensions()
          Accessor for the extensions for this expression.
 DatastoreIdentifier getMainTableAlias()
          Accessor for the alias of the main table of this query.
 LogicSetExpression getMainTableExpression()
          Accessor for the expression for the main table of this query.
 int getNumberOfScalarExpressions()
          Accessor for the number of ScalarExpression projected.
 QueryExpression getParent()
          Accessor for the parent QueryExpression if this is a nested expression.
 MappedStoreManager getStoreManager()
          Accessor for the store manager associated with this query.
 LogicSetExpression getTableExpression(DatastoreIdentifier alias)
          Accessor to the table expression for the given alias.
 java.lang.Object getValueForExtension(java.lang.String key)
          Accessor for the value for an extension.
 boolean hasCrossJoin(LogicSetExpression tableExpr)
          Method to add tables/alias but no joins to they, will be output as FROM TABLE1,TABLE2,TABLE3 Checks parent expressions until reach the root expression
 boolean hasNucleusTypeExpression()
          Whether this query will return a meta data expression in the SELECT clause
 void innerJoin(ScalarExpression expr, ScalarExpression expr2, LogicSetExpression tblExpr, boolean equals)
          Method to do an inner join to another table.
 void innerJoin(ScalarExpression expr, ScalarExpression expr2, LogicSetExpression tblExpr, boolean equals, boolean unionQueries)
          Method to do an inner join to another table, and optionally apply it to any unions for this query.
 void iorCondition(BooleanExpression condition)
          add an condition to the query.
 void iorCondition(BooleanExpression condition, boolean unionQueries)
          add an condition to the query and queries involved in the union if unionQuery is true
 void leftOuterJoin(ScalarExpression expr, ScalarExpression expr2, LogicSetExpression tblExpr, boolean equals)
          Method to do a left outer join to another table.
 void leftOuterJoin(ScalarExpression expr, ScalarExpression expr2, LogicSetExpression tblExpr, boolean equals, boolean unionQueries)
          Method to do a left outer join to another table, and optionally apply it to any unions for this query.
 LogicSetExpression newTableExpression(DatastoreContainerObject mainTable, DatastoreIdentifier alias)
          Creates a table expression
 LogicSetExpression[] newTableExpression(DatastoreContainerObject mainTable, DatastoreIdentifier alias, boolean unionQueries)
          Creates a table expression
 void reset()
          Allows reseting the compiled expression
 void rightOuterJoin(ScalarExpression expr, ScalarExpression expr2, LogicSetExpression tblExpr, boolean equals)
          Method to do a right outer join to another table.
 void rightOuterJoin(ScalarExpression expr, ScalarExpression expr2, LogicSetExpression tblExpr, boolean equals, boolean unionQueries)
          Method to do a right outer join to another table, and optionally apply it to any unions for this query.
 int[] select(DatastoreIdentifier alias, JavaTypeMapping mapping)
          Select columns, add to union queries, if unionQueries is true
 int[] select(DatastoreIdentifier alias, JavaTypeMapping mapping, boolean unionQueries)
          select columns, add to union queries, if unionQueries is true
 int[] select(JavaTypeMapping mapping)
          Select the columns for a mapping
 int[] select(JavaTypeMapping mapping, boolean unionQueries)
          select a new column, add to union queries, if unionQueries is true
 int[] selectDatastoreIdentity(java.lang.String alias, boolean unionQueries)
          Select the datastore identity column.
 int[] selectField(java.lang.String fieldName, java.lang.String alias, boolean unionQueries)
          Select the column(s) for the specified field in the primary table of the query.
 int selectScalarExpression(ScalarExpression expr)
          select an expression; eg: "'Text' as alias"
 int selectScalarExpression(ScalarExpression expr, boolean unionQueries)
          select an expression; eg: "'Text' as alias"
 int[] selectVersion(java.lang.String alias, boolean unionQueries)
          Select the version column.
 void setCandidateInformation(java.lang.Class cls, java.lang.String alias)
          Method to set the candidate class and alias in use by the query.
 void setDistinctResults(boolean distinctResults)
          Set whether this statement returns distinct results.
 void setExistsSubQuery(boolean isExistsSubQuery)
          Set this query is to be used as a as set for the Exists function.
 void setHaving(BooleanExpression expr)
          Method to set the having clause of the statement.
 void setOrdering(ScalarExpression[] exprs, boolean[] descending)
          Mutator for the ordering criteria.
 void setParent(QueryExpression parentQueryExpr)
          Sets the parent QueryExpression of this query.
 void setRangeConstraint(long offset, long count)
          Method to add a range constraint on any SELECT.
 void setUpdates(ScalarExpression[] exprs)
          set the update condition(s) for the query.
 StatementText toDeleteStatementText()
          Method to convert the criteria into a delete statement text.
 StatementText toStatementText(boolean lock)
          Method to convert the criteria into the statement text.
 StatementText toUpdateStatementText()
          Method to convert the criteria into an update statement text.
 void union(QueryExpression qe)
          Union two QueryExpressions this and qe.
 

Method Detail

setParent

void setParent(QueryExpression parentQueryExpr)
Sets the parent QueryExpression of this query. In SQL it can be exemplified as SELECT 1 FROM PARENT WHERE EXISTS (SELECT 1 FROM THIS) The parent QueryExpression is the nesting SQL.

Parameters:
parentQueryExpr - the parent of this query

getParent

QueryExpression getParent()
Accessor for the parent QueryExpression if this is a nested expression.

Returns:
Parent expression

setCandidateInformation

void setCandidateInformation(java.lang.Class cls,
                             java.lang.String alias)
Method to set the candidate class and alias in use by the query. The expression is created with a candidate table, yet this could store more than 1 class. Additionally the "alias" of the candidate table expression is a DatastoreIdentifier whereas this alias here is a String form.

Parameters:
cls - The candidate class
alias - The alias

getCandidateClass

java.lang.Class getCandidateClass()
Accessor for the candidate class of the query expression.

Returns:
Candidate class

getCandidateAlias

java.lang.String getCandidateAlias()
Accessor for the candidate alias in use by the query.

Returns:
Candidate alias

getMainTableExpression

LogicSetExpression getMainTableExpression()
Accessor for the expression for the main table of this query. This is the same as the default table expression except where this is a subquery.

Returns:
Main table expression

getMainTableAlias

DatastoreIdentifier getMainTableAlias()
Accessor for the alias of the main table of this query.

Returns:
Alias for the main table in the query

getTableExpression

LogicSetExpression getTableExpression(DatastoreIdentifier alias)
Accessor to the table expression for the given alias.

Parameters:
alias - the alias
Returns:
the TableExpression

newTableExpression

LogicSetExpression newTableExpression(DatastoreContainerObject mainTable,
                                      DatastoreIdentifier alias)
Creates a table expression

Parameters:
mainTable - the main table
alias - the alias
Returns:
TableExpression

newTableExpression

LogicSetExpression[] newTableExpression(DatastoreContainerObject mainTable,
                                        DatastoreIdentifier alias,
                                        boolean unionQueries)
Creates a table expression

Parameters:
mainTable - the main table
alias - the alias
unionQueries - Whether to add to any union
Returns:
TableExpression[]

getStoreManager

MappedStoreManager getStoreManager()
Accessor for the store manager associated with this query.

Returns:
The store manager

getClassLoaderResolver

ClassLoaderResolver getClassLoaderResolver()
Accessor for the ClassLoaderResolver to use with this query statement.

Returns:
ClassLoader resolver

setDistinctResults

void setDistinctResults(boolean distinctResults)
Set whether this statement returns distinct results.

Parameters:
distinctResults - Whether we return distinct results

addExtension

void addExtension(java.lang.String key,
                  java.lang.Object value)
Method to define an extension for this query statement allowing control over its behaviour in generating a query.

Parameters:
key - Extension key
value - Value for the key

getValueForExtension

java.lang.Object getValueForExtension(java.lang.String key)
Accessor for the value for an extension.

Parameters:
key - Key for the extension
Returns:
Value for the extension (if any)

getExtensions

java.util.HashMap getExtensions()
Accessor for the extensions for this expression.

Returns:
Extensions

hasNucleusTypeExpression

boolean hasNucleusTypeExpression()
Whether this query will return a meta data expression in the SELECT clause

Returns:
hasMetaDataExpression

selectDatastoreIdentity

int[] selectDatastoreIdentity(java.lang.String alias,
                              boolean unionQueries)
Select the datastore identity column.

Parameters:
alias - Alias to use for this column
unionQueries - Whether to select the datastore id column of all unioned tables
Returns:
The position of the column in the result set

selectVersion

int[] selectVersion(java.lang.String alias,
                    boolean unionQueries)
Select the version column.

Parameters:
alias - Alias to use for this column
unionQueries - Whether to select the version column of all unioned tables
Returns:
The position of the column in the result set

selectField

int[] selectField(java.lang.String fieldName,
                  java.lang.String alias,
                  boolean unionQueries)
Select the column(s) for the specified field in the primary table of the query.

Parameters:
fieldName - Name of the field
alias - Alias to use for these column(s)
unionQueries - Whether to select the field column(s) of all unioned queries.
Returns:
The position of the columns in the result set.

select

int[] select(JavaTypeMapping mapping)
Select the columns for a mapping

Parameters:
mapping - The mapping
Returns:
The index of the columns in the select

select

int[] select(JavaTypeMapping mapping,
             boolean unionQueries)
select a new column, add to union queries, if unionQueries is true

Parameters:
mapping - The mapping
unionQueries - Whether to add to any union
Returns:
The index of the columns in the select

selectScalarExpression

int selectScalarExpression(ScalarExpression expr)
select an expression; eg: "'Text' as alias"

Parameters:
expr - The expression to add to the select statement
Returns:
The index of the expression in the select

selectScalarExpression

int selectScalarExpression(ScalarExpression expr,
                           boolean unionQueries)
select an expression; eg: "'Text' as alias"

Parameters:
expr - The expression to add to the select statement
unionQueries - whether to apply the select in all queries unified by the union clause
Returns:
The index of the expression in the select

select

int[] select(DatastoreIdentifier alias,
             JavaTypeMapping mapping)
Select columns, add to union queries, if unionQueries is true

Parameters:
alias - The alias
mapping - The mapping
Returns:
The index of the columns in the select

select

int[] select(DatastoreIdentifier alias,
             JavaTypeMapping mapping,
             boolean unionQueries)
select columns, add to union queries, if unionQueries is true

Parameters:
alias - The alias
mapping - The mapping
unionQueries - Whether to add to any union
Returns:
The index of the column in the select

andCondition

void andCondition(BooleanExpression condition)
add an condition to the query.

Parameters:
condition - the Boolean expression

andCondition

void andCondition(BooleanExpression condition,
                  boolean unionQueries)
add an condition to the query and queries involved in the union if unionQuery is true

Parameters:
condition - the Boolean expression
unionQueries - whether to apply the condition in all queries unified by the union clause

crossJoin

void crossJoin(LogicSetExpression tableExpr,
               boolean unionQueries)
Method to add tables/crossJoin but no joins to they, will be output as FROM TABLE1,TABLE2,TABLE3

Parameters:
tableExpr - table expression
unionQueries - Whether to apply the alias to unions of this query.

hasCrossJoin

boolean hasCrossJoin(LogicSetExpression tableExpr)
Method to add tables/alias but no joins to they, will be output as FROM TABLE1,TABLE2,TABLE3 Checks parent expressions until reach the root expression

Parameters:
tableExpr - table expression

innerJoin

void innerJoin(ScalarExpression expr,
               ScalarExpression expr2,
               LogicSetExpression tblExpr,
               boolean equals,
               boolean unionQueries)
Method to do an inner join to another table, and optionally apply it to any unions for this query.

Parameters:
expr - the left hand expression
expr2 - the right hand expression
tblExpr - the
equals - if the join is applied as filter, if use equals or not equals
unionQueries - whether to apply the inner join in all queries unified by the union clause

innerJoin

void innerJoin(ScalarExpression expr,
               ScalarExpression expr2,
               LogicSetExpression tblExpr,
               boolean equals)
Method to do an inner join to another table.

Parameters:
expr - the left hand expression
expr2 - the right hand expression
tblExpr - The table expression for the table to apply the join
equals - if the join is applied as filter, if use equals or not equals

leftOuterJoin

void leftOuterJoin(ScalarExpression expr,
                   ScalarExpression expr2,
                   LogicSetExpression tblExpr,
                   boolean equals,
                   boolean unionQueries)
Method to do a left outer join to another table, and optionally apply it to any unions for this query.

Parameters:
expr - the left hand expression
expr2 - the right hand expression
tblExpr - The table expression for the table to apply the join
equals - if the join is applied as filter, if use equals or not equals
unionQueries - Whether to apply to unions of this query.

leftOuterJoin

void leftOuterJoin(ScalarExpression expr,
                   ScalarExpression expr2,
                   LogicSetExpression tblExpr,
                   boolean equals)
Method to do a left outer join to another table.

Parameters:
expr - the left hand expression
expr2 - the right hand expression
tblExpr - The table expression
equals - if the join is applied as filter, if use equals or not equals

rightOuterJoin

void rightOuterJoin(ScalarExpression expr,
                    ScalarExpression expr2,
                    LogicSetExpression tblExpr,
                    boolean equals,
                    boolean unionQueries)
Method to do a right outer join to another table, and optionally apply it to any unions for this query.

Parameters:
expr - the left hand expression
expr2 - the right hand expression
tblExpr - The table expression for the table to apply the join
equals - if the join is applied as filter, if use equals or not equals
unionQueries - Whether to apply to unions of this query.

rightOuterJoin

void rightOuterJoin(ScalarExpression expr,
                    ScalarExpression expr2,
                    LogicSetExpression tblExpr,
                    boolean equals)
Method to do a right outer join to another table.

Parameters:
expr - the left hand expression
expr2 - the right hand expression
tblExpr - The table expression for the table to apply the join
equals - if the join is applied as filter, if use equals or not equals

addGroupingExpression

void addGroupingExpression(ScalarExpression expr)
Method to add a grouping clause to the statement. Grouping clauses that are implied by the selected columns will be added automatically so this provides a means to supplement them.

Parameters:
expr - The group by expression

setHaving

void setHaving(BooleanExpression expr)
Method to set the having clause of the statement.

Parameters:
expr - The having expression

setOrdering

void setOrdering(ScalarExpression[] exprs,
                 boolean[] descending)
Mutator for the ordering criteria.

Parameters:
exprs - The expressions to order by
descending - Whether each expression is ascending/descending

setUpdates

void setUpdates(ScalarExpression[] exprs)
set the update condition(s) for the query.

Parameters:
exprs - the Boolean expression

union

void union(QueryExpression qe)
Union two QueryExpressions this and qe. Both QueryExpressions must have the same ScalarExpressions selected, and they must be in the same select order. valid: e.g. a) fieldA, fieldB, fieldE, fieldC b) fieldA, fieldB, fieldE, fieldC invalid: e.g. a) fieldA, fieldE, fieldB, fieldC b) fieldA, fieldB, fieldE, fieldC

Parameters:
qe - the QueryExpression

iorCondition

void iorCondition(BooleanExpression condition)
add an condition to the query.

Parameters:
condition - the Boolean expression

iorCondition

void iorCondition(BooleanExpression condition,
                  boolean unionQueries)
add an condition to the query and queries involved in the union if unionQuery is true

Parameters:
condition - the Boolean expression
unionQueries - whether to apply the condition in all queries unified by the union clause

setRangeConstraint

void setRangeConstraint(long offset,
                        long count)
Method to add a range constraint on any SELECT. This typically will use LIMIT/OFFSET where they are supported by the underlying RDBMS.

Parameters:
offset - The offset to start from
count - The number of records to return

setExistsSubQuery

void setExistsSubQuery(boolean isExistsSubQuery)
Set this query is to be used as a as set for the Exists function. example WHERE EXISTS( QUERY )

Parameters:
isExistsSubQuery - The isExistsSubQuery to set.

getNumberOfScalarExpressions

int getNumberOfScalarExpressions()
Accessor for the number of ScalarExpression projected.

Returns:
The number of columns in the SELECT

toDeleteStatementText

StatementText toDeleteStatementText()
Method to convert the criteria into a delete statement text.

Returns:
The StatementText

toUpdateStatementText

StatementText toUpdateStatementText()
Method to convert the criteria into an update statement text.

Returns:
The StatementText

toStatementText

StatementText toStatementText(boolean lock)
Method to convert the criteria into the statement text.

Parameters:
lock - whether to lock the instances using this statement
Returns:
The StatementText

reset

void reset()
Allows reseting the compiled expression



Copyright © 2010. All Rights Reserved.