org.datanucleus.store.rdbms.query
Class QueryStatement

java.lang.Object
  extended by org.datanucleus.store.rdbms.query.QueryStatement
All Implemented Interfaces:
org.datanucleus.store.mapped.expression.QueryExpression
Direct Known Subclasses:
Oracle99QueryStatement, OracleQueryStatement

public class QueryStatement
extends java.lang.Object
implements org.datanucleus.store.mapped.expression.QueryExpression

Representation of a statement for a Query. Provides methods to specify joins to other tables and to select columns from these tables. Provides methods to apply restrictions on the result. The resultant statement consists of a SELECT clause, a FROM clause and a WHERE clause. Provides output as either a SELECT statement or as a DELETE statement. The DELETE form of the statement uses just the FROM and WHERE clauses. This statement may represent a subquery.


Nested Class Summary
static class QueryStatement.Join
          A join in a query.
 
Field Summary
protected  java.lang.String candidateAlias
          Candidate alias used by the query (defaults to "this").
protected  java.lang.Class candidateClass
          Candidate class for the query.
protected  java.util.List<org.datanucleus.store.mapped.expression.LogicSetExpression> crossJoins
          Cross joins.
protected  boolean distinctResults
          Whether to make results distinct.
protected  java.util.HashMap<java.lang.String,java.lang.Object> extensions
          Map of extensions, keyed by the extension name.
protected  java.util.List<org.datanucleus.store.mapped.expression.ScalarExpression> groupingExpressions
          Expression(s) for the GROUP BY clause.
protected  boolean hasAggregateExpression
          whether there is an aggregate expression present in the select
protected  org.datanucleus.store.mapped.expression.BooleanExpression havingExpr
          Expression for any HAVING clause.
protected  boolean isExistsSubQuery
          Whether this query is to be used as a as set for the Exists function.
protected  java.util.List<QueryStatement.Join> joins
          inner/left/right joins
protected  java.util.List<org.datanucleus.store.mapped.DatastoreIdentifier> joinsToTableAliases
          Internal List of table aliases, to ensure that we don't have duplicate JOINs From vs To
protected static org.datanucleus.util.Localiser LOCALISER
          Localisation for messages.
protected  org.datanucleus.store.mapped.DatastoreIdentifier mainTableAlias
          Alias for the main table.
protected  org.datanucleus.store.mapped.expression.LogicSetExpression mainTableExpr
          Table expression for the main table of this statement.
protected  boolean[] orderingDirections
          Directions for any ORDER BY expressions (1 for each orderingExpressions entry).
protected  org.datanucleus.store.mapped.expression.ScalarExpression[] orderingExpressions
          Expressions for any ORDER BY clause.
protected  long rangeCount
          The number of records to be retrieved in any range restriction.
protected  long rangeOffset
          The offset for any range restriction.
protected  java.util.List<java.lang.String> selected
          Expression(s) for selected fields/columns.
protected  org.datanucleus.store.mapped.expression.StatementText stmtText
          Statement text for this Query Statement.
protected  org.datanucleus.store.mapped.MappedStoreManager storeMgr
          Store Manager.
protected  java.util.Map<org.datanucleus.store.mapped.DatastoreIdentifier,org.datanucleus.store.mapped.expression.LogicSetExpression> tableExprsByAlias
           
protected  java.util.List<QueryStatement> union
          List of unioned query expressions.
protected  org.datanucleus.store.mapped.expression.ScalarExpression[] updateExprs
          Update condition
protected  org.datanucleus.store.mapped.expression.BooleanExpression whereExpr
          Expression for the WHERE clause.
 
Constructor Summary
QueryStatement(org.datanucleus.store.mapped.DatastoreContainerObject mainTable, org.datanucleus.store.mapped.DatastoreIdentifier alias, org.datanucleus.ClassLoaderResolver clr)
          Constructor, allowing the specification of the alias of the main table.
 
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(org.datanucleus.store.mapped.expression.ScalarExpression expr)
          Method to add a grouping expression to the query.
protected  void addOrderingColumnsToSelect()
          Convenience method to add any necessary columns to the SELECT that are needed by the ordering constraint.
 void andCondition(org.datanucleus.store.mapped.expression.BooleanExpression condition)
          Method to add an additional WHERE clause to the query.
 void andCondition(org.datanucleus.store.mapped.expression.BooleanExpression condition, boolean unionQueries)
          add an condition to the query and queries involved in the union if unionQuery is true
protected  void assertNotFrozen()
          Assert if the statement text is already generated.
 void crossJoin(org.datanucleus.store.mapped.expression.LogicSetExpression tableExpr, boolean unionQueries)
          Method to add a cross-join to the supplied table.
protected  org.datanucleus.store.mapped.expression.StatementText generateOrderingStatement()
          Convenience method to generate the ordering statement to add to the overall query statement.
 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.
 org.datanucleus.ClassLoaderResolver getClassLoaderResolver()
          Accessor for the class-loader resolver.
 java.util.HashMap getExtensions()
          Accessor for the extensions for this expression.
 org.datanucleus.store.mapped.DatastoreIdentifier getMainTableAlias()
          Accessor for the main table identifier alias.
 org.datanucleus.store.mapped.expression.LogicSetExpression getMainTableExpression()
          Accessor for the main table of this statement.
 int getNumberOfScalarExpressions()
          Accessor for the number of ScalarExpression projected.
 org.datanucleus.store.mapped.expression.QueryExpression getParent()
          Accessor for the parent QueryExpression if this is a nested expression.
 org.datanucleus.store.mapped.MappedStoreManager getStoreManager()
          Accessor for the Store Manager.
 org.datanucleus.store.mapped.expression.LogicSetExpression getTableExpression(org.datanucleus.store.mapped.DatastoreIdentifier alias)
          Accessor for the table with the specified "alias".
 java.lang.Object getValueForExtension(java.lang.String key)
          Accessor for the value for an extension.
 boolean hasCrossJoin(org.datanucleus.store.mapped.expression.LogicSetExpression tableExpr)
          Method to return if the query statement has a cross join involving the supplied table expression.
 boolean hasNucleusTypeExpression()
          Whether this query will return a meta data expression (containing NUCLEUS_TYPE).
 void innerJoin(org.datanucleus.store.mapped.expression.ScalarExpression expr, org.datanucleus.store.mapped.expression.ScalarExpression expr2, org.datanucleus.store.mapped.expression.LogicSetExpression tblExpr, boolean equals)
          Method to do an inner join to another table.
 void innerJoin(org.datanucleus.store.mapped.expression.ScalarExpression expr, org.datanucleus.store.mapped.expression.ScalarExpression expr2, org.datanucleus.store.mapped.expression.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(org.datanucleus.store.mapped.expression.BooleanExpression condition)
          Method to add an IOR condition to the WHERE clause of the statement.
 void iorCondition(org.datanucleus.store.mapped.expression.BooleanExpression condition, boolean unionQueries)
          add an condition to the query and queries involved in the union if unionQuery is true
 void leftOuterJoin(org.datanucleus.store.mapped.expression.ScalarExpression expr, org.datanucleus.store.mapped.expression.ScalarExpression expr2, org.datanucleus.store.mapped.expression.LogicSetExpression tblExpr, boolean equals)
          Method to do a left outer join to another table.
 void leftOuterJoin(org.datanucleus.store.mapped.expression.ScalarExpression expr, org.datanucleus.store.mapped.expression.ScalarExpression expr2, org.datanucleus.store.mapped.expression.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.
 org.datanucleus.store.mapped.expression.LogicSetExpression newTableExpression(org.datanucleus.store.mapped.DatastoreContainerObject table, org.datanucleus.store.mapped.DatastoreIdentifier alias)
          Method to return the table expression for a new table, and add to the managed table expressions for this query.
 org.datanucleus.store.mapped.expression.LogicSetExpression[] newTableExpression(org.datanucleus.store.mapped.DatastoreContainerObject table, org.datanucleus.store.mapped.DatastoreIdentifier alias, boolean unionQueries)
          Method to return the table expression for a new table, and add to the managed table expressions for this query.
 void reset()
          Resets the compiled expression statement.
 void rightOuterJoin(org.datanucleus.store.mapped.expression.ScalarExpression expr, org.datanucleus.store.mapped.expression.ScalarExpression expr2, org.datanucleus.store.mapped.expression.LogicSetExpression tblExpr, boolean equals)
          Method to do a right outer join to another table.
 void rightOuterJoin(org.datanucleus.store.mapped.expression.ScalarExpression expr, org.datanucleus.store.mapped.expression.ScalarExpression expr2, org.datanucleus.store.mapped.expression.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(org.datanucleus.store.mapped.DatastoreIdentifier tableAlias, org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping)
          Select columns of the specified mapping for the table identifier.
 int[] select(org.datanucleus.store.mapped.DatastoreIdentifier tableAlias, org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping, boolean unionQueries)
          select columns, add to union queries, if unionQueries is true
 int[] select(org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping)
          Select the columns for a mapping.
 int[] select(org.datanucleus.store.mapped.mapping.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 of the primary table of the query.
 int[] selectField(java.lang.String fieldName, java.lang.String alias, boolean unionQueries)
          Select the column(s) for the specified field of the primary table of the query.
 int selectScalarExpression(org.datanucleus.store.mapped.expression.ScalarExpression expr)
          Select an expression.
 int selectScalarExpression(org.datanucleus.store.mapped.expression.ScalarExpression expr, boolean unionQueries)
          Select an expression.
 int[] selectVersion(java.lang.String alias, boolean unionQueries)
          Select the version column of the primary table of the query.
 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)
          Mutator for whether the query returns distinct results.
 void setExistsSubQuery(boolean isExistsSubQuery)
          Set this query is to be used as a set for the Exists function.
 void setHaving(org.datanucleus.store.mapped.expression.BooleanExpression expr)
          Mutator for the "having" expression.
 void setOrdering(org.datanucleus.store.mapped.expression.ScalarExpression[] exprs, boolean[] descending)
          Mutator for the ordering criteria.
 void setParent(org.datanucleus.store.mapped.expression.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(org.datanucleus.store.mapped.expression.ScalarExpression[] exprs)
          Method to set the UPDATE clause of the statement.
 org.datanucleus.store.mapped.expression.StatementText toDeleteStatementText()
          Method to convert the criteria into a delete statement text.
 org.datanucleus.store.mapped.expression.StatementText toStatementText(boolean lock)
          Method to convert the criteria into the statement text.
 org.datanucleus.store.mapped.expression.StatementText toUpdateStatementText()
          Method to convert the criteria into an update statement text.
 void union(org.datanucleus.store.mapped.expression.QueryExpression expr)
          Method to union this query statement with another query statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALISER

protected static final org.datanucleus.util.Localiser LOCALISER
Localisation for messages.


storeMgr

protected final org.datanucleus.store.mapped.MappedStoreManager storeMgr
Store Manager.


candidateClass

protected java.lang.Class candidateClass
Candidate class for the query.


candidateAlias

protected java.lang.String candidateAlias
Candidate alias used by the query (defaults to "this").


mainTableAlias

protected final org.datanucleus.store.mapped.DatastoreIdentifier mainTableAlias
Alias for the main table.


mainTableExpr

protected final org.datanucleus.store.mapped.expression.LogicSetExpression mainTableExpr
Table expression for the main table of this statement.


tableExprsByAlias

protected java.util.Map<org.datanucleus.store.mapped.DatastoreIdentifier,org.datanucleus.store.mapped.expression.LogicSetExpression> tableExprsByAlias

union

protected java.util.List<QueryStatement> union
List of unioned query expressions.


isExistsSubQuery

protected boolean isExistsSubQuery
Whether this query is to be used as a as set for the Exists function.
e.g WHERE EXISTS(QUERY)
.


distinctResults

protected boolean distinctResults
Whether to make results distinct.


selected

protected java.util.List<java.lang.String> selected
Expression(s) for selected fields/columns.


hasAggregateExpression

protected boolean hasAggregateExpression
whether there is an aggregate expression present in the select


joins

protected java.util.List<QueryStatement.Join> joins
inner/left/right joins


joinsToTableAliases

protected java.util.List<org.datanucleus.store.mapped.DatastoreIdentifier> joinsToTableAliases
Internal List of table aliases, to ensure that we don't have duplicate JOINs From vs To


crossJoins

protected java.util.List<org.datanucleus.store.mapped.expression.LogicSetExpression> crossJoins
Cross joins. Will be output as (FROM) TABLE1,TABLE2,TABLE3


whereExpr

protected org.datanucleus.store.mapped.expression.BooleanExpression whereExpr
Expression for the WHERE clause.


groupingExpressions

protected java.util.List<org.datanucleus.store.mapped.expression.ScalarExpression> groupingExpressions
Expression(s) for the GROUP BY clause.


havingExpr

protected org.datanucleus.store.mapped.expression.BooleanExpression havingExpr
Expression for any HAVING clause.


orderingExpressions

protected org.datanucleus.store.mapped.expression.ScalarExpression[] orderingExpressions
Expressions for any ORDER BY clause.


orderingDirections

protected boolean[] orderingDirections
Directions for any ORDER BY expressions (1 for each orderingExpressions entry).


updateExprs

protected org.datanucleus.store.mapped.expression.ScalarExpression[] updateExprs
Update condition


rangeOffset

protected long rangeOffset
The offset for any range restriction.


rangeCount

protected long rangeCount
The number of records to be retrieved in any range restriction.


extensions

protected java.util.HashMap<java.lang.String,java.lang.Object> extensions
Map of extensions, keyed by the extension name.


stmtText

protected org.datanucleus.store.mapped.expression.StatementText stmtText
Statement text for this Query Statement. Created by toXXXStatementText()

Constructor Detail

QueryStatement

public QueryStatement(org.datanucleus.store.mapped.DatastoreContainerObject mainTable,
                      org.datanucleus.store.mapped.DatastoreIdentifier alias,
                      org.datanucleus.ClassLoaderResolver clr)
Constructor, allowing the specification of the alias of the main table.

Parameters:
mainTable - The main table for this statement.
alias - The alias for the main table
clr - ClassLoader resolver.
Method Detail

setCandidateInformation

public 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.

Specified by:
setCandidateInformation in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
cls - The candidate class
alias - The alias

getCandidateClass

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

Specified by:
getCandidateClass in interface org.datanucleus.store.mapped.expression.QueryExpression
Returns:
Candidate class

getCandidateAlias

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

Specified by:
getCandidateAlias in interface org.datanucleus.store.mapped.expression.QueryExpression
Returns:
Candidate alias

reset

public void reset()
Resets the compiled expression statement.

Specified by:
reset in interface org.datanucleus.store.mapped.expression.QueryExpression

setParent

public void setParent(org.datanucleus.store.mapped.expression.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 outer SELECT, and this QueryExpression is the inner SELECT.

Specified by:
setParent in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
parentQueryExpr - the parent of this query

getParent

public org.datanucleus.store.mapped.expression.QueryExpression getParent()
Accessor for the parent QueryExpression if this is a nested expression.

Specified by:
getParent in interface org.datanucleus.store.mapped.expression.QueryExpression
Returns:
Parent expression

getClassLoaderResolver

public org.datanucleus.ClassLoaderResolver getClassLoaderResolver()
Accessor for the class-loader resolver.

Specified by:
getClassLoaderResolver in interface org.datanucleus.store.mapped.expression.QueryExpression
Returns:
The ClassLoader resolver.

getStoreManager

public org.datanucleus.store.mapped.MappedStoreManager getStoreManager()
Accessor for the Store Manager.

Specified by:
getStoreManager in interface org.datanucleus.store.mapped.expression.QueryExpression
Returns:
The Store Manager.

setDistinctResults

public void setDistinctResults(boolean distinctResults)
Mutator for whether the query returns distinct results.

Specified by:
setDistinctResults in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
distinctResults - Whether to return distinct

setExistsSubQuery

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

Specified by:
setExistsSubQuery in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
isExistsSubQuery - The isExistsSubQuery to set.

union

public void union(org.datanucleus.store.mapped.expression.QueryExpression expr)
Method to union this query statement with another query statement.

Specified by:
union in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
expr - The other query statement to union

addExtension

public 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.

Specified by:
addExtension in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
key - Extension key
value - Value for the key

getValueForExtension

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

Specified by:
getValueForExtension in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
key - Key for the extension
Returns:
Value for the extension (if any)

getExtensions

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

Specified by:
getExtensions in interface org.datanucleus.store.mapped.expression.QueryExpression
Returns:
Extensions

selectDatastoreIdentity

public int[] selectDatastoreIdentity(java.lang.String alias,
                                     boolean unionQueries)
Select the datastore identity of the primary table of the query.

Specified by:
selectDatastoreIdentity in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
alias - Alias to use for the selected datastore identity column (if any)
unionQueries - Whether to apply to the primary table of any unioned tables
Returns:
Index of the column in the select (or null if not datastore mapping)

selectVersion

public int[] selectVersion(java.lang.String alias,
                           boolean unionQueries)
Select the version column of the primary table of the query.

Specified by:
selectVersion in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
alias - Alias to use for the selected version column (if any)
unionQueries - Whether to also select the version column of the primary table of any unioned queries
Returns:
Index of the column in the select (or null if no version mapping)

selectField

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

Specified by:
selectField in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
fieldName - Name of the field to select.
alias - Alias to use for the selected field column(s) (if any).
unionQueries - Whether to also select the field column(s) of the primary table of any unioned queries
Returns:
Index of the column(s) in the select (or null of no field of this name present).

select

public int[] select(org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping)
Select the columns for a mapping.

Specified by:
select in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
mapping - The mapping
Returns:
The index of the columns in the select

select

public int[] select(org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping,
                    boolean unionQueries)
select a new column, add to union queries, if unionQueries is true

Specified by:
select in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
mapping - The mapping
unionQueries - Whether to add to any union
Returns:
The index of the columns in the select

select

public int[] select(org.datanucleus.store.mapped.DatastoreIdentifier tableAlias,
                    org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping)
Select columns of the specified mapping for the table identifier.

Specified by:
select in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
tableAlias - The alias for the table
mapping - The mapping
Returns:
The index of the columns in the select

select

public int[] select(org.datanucleus.store.mapped.DatastoreIdentifier tableAlias,
                    org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping,
                    boolean unionQueries)
select columns, add to union queries, if unionQueries is true

Specified by:
select in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
tableAlias - The alias for the table
mapping - The mapping
unionQueries - Whether to add to any union
Returns:
The index of the column in the select

selectScalarExpression

public int selectScalarExpression(org.datanucleus.store.mapped.expression.ScalarExpression expr)
Select an expression.

Specified by:
selectScalarExpression in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
expr - The expression to add to the select statement
Returns:
The index of the expression in the select

selectScalarExpression

public int selectScalarExpression(org.datanucleus.store.mapped.expression.ScalarExpression expr,
                                  boolean unionQueries)
Select an expression.

Specified by:
selectScalarExpression in interface org.datanucleus.store.mapped.expression.QueryExpression
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

getNumberOfScalarExpressions

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

Specified by:
getNumberOfScalarExpressions in interface org.datanucleus.store.mapped.expression.QueryExpression
Returns:
The number of columns in the SELECT

hasNucleusTypeExpression

public boolean hasNucleusTypeExpression()
Whether this query will return a meta data expression (containing NUCLEUS_TYPE).

Specified by:
hasNucleusTypeExpression in interface org.datanucleus.store.mapped.expression.QueryExpression
Returns:
true if a meta data expression is returned by this query

getMainTableExpression

public org.datanucleus.store.mapped.expression.LogicSetExpression getMainTableExpression()
Accessor for the main table of this statement.

Specified by:
getMainTableExpression in interface org.datanucleus.store.mapped.expression.QueryExpression
Returns:
Returns the main table expression

getMainTableAlias

public org.datanucleus.store.mapped.DatastoreIdentifier getMainTableAlias()
Accessor for the main table identifier alias.

Specified by:
getMainTableAlias in interface org.datanucleus.store.mapped.expression.QueryExpression
Returns:
Alias for the main table

getTableExpression

public org.datanucleus.store.mapped.expression.LogicSetExpression getTableExpression(org.datanucleus.store.mapped.DatastoreIdentifier alias)
Accessor for the table with the specified "alias". Returns null if the table is not utilised in this query expression.

Specified by:
getTableExpression in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
alias - Alias for the table required
Returns:
The table expression

newTableExpression

public org.datanucleus.store.mapped.expression.LogicSetExpression newTableExpression(org.datanucleus.store.mapped.DatastoreContainerObject table,
                                                                                     org.datanucleus.store.mapped.DatastoreIdentifier alias)
Method to return the table expression for a new table, and add to the managed table expressions for this query.

Specified by:
newTableExpression in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
table - The table
alias - Alias for the table
Returns:
The table expression

newTableExpression

public org.datanucleus.store.mapped.expression.LogicSetExpression[] newTableExpression(org.datanucleus.store.mapped.DatastoreContainerObject table,
                                                                                       org.datanucleus.store.mapped.DatastoreIdentifier alias,
                                                                                       boolean unionQueries)
Method to return the table expression for a new table, and add to the managed table expressions for this query.

Specified by:
newTableExpression in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
table - The table
alias - Alias for the table
unionQueries - Whether to apply to all unioned query statements.
Returns:
The table expression

innerJoin

public void innerJoin(org.datanucleus.store.mapped.expression.ScalarExpression expr,
                      org.datanucleus.store.mapped.expression.ScalarExpression expr2,
                      org.datanucleus.store.mapped.expression.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.

Specified by:
innerJoin in interface org.datanucleus.store.mapped.expression.QueryExpression
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

public void innerJoin(org.datanucleus.store.mapped.expression.ScalarExpression expr,
                      org.datanucleus.store.mapped.expression.ScalarExpression expr2,
                      org.datanucleus.store.mapped.expression.LogicSetExpression tblExpr,
                      boolean equals)
Method to do an inner join to another table.

Specified by:
innerJoin in interface org.datanucleus.store.mapped.expression.QueryExpression
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

public void leftOuterJoin(org.datanucleus.store.mapped.expression.ScalarExpression expr,
                          org.datanucleus.store.mapped.expression.ScalarExpression expr2,
                          org.datanucleus.store.mapped.expression.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.

Specified by:
leftOuterJoin in interface org.datanucleus.store.mapped.expression.QueryExpression
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

public void leftOuterJoin(org.datanucleus.store.mapped.expression.ScalarExpression expr,
                          org.datanucleus.store.mapped.expression.ScalarExpression expr2,
                          org.datanucleus.store.mapped.expression.LogicSetExpression tblExpr,
                          boolean equals)
Method to do a left outer join to another table.

Specified by:
leftOuterJoin in interface org.datanucleus.store.mapped.expression.QueryExpression
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

public void rightOuterJoin(org.datanucleus.store.mapped.expression.ScalarExpression expr,
                           org.datanucleus.store.mapped.expression.ScalarExpression expr2,
                           org.datanucleus.store.mapped.expression.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.

Specified by:
rightOuterJoin in interface org.datanucleus.store.mapped.expression.QueryExpression
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

public void rightOuterJoin(org.datanucleus.store.mapped.expression.ScalarExpression expr,
                           org.datanucleus.store.mapped.expression.ScalarExpression expr2,
                           org.datanucleus.store.mapped.expression.LogicSetExpression tblExpr,
                           boolean equals)
Method to do a right outer join to another table.

Specified by:
rightOuterJoin in interface org.datanucleus.store.mapped.expression.QueryExpression
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

hasCrossJoin

public boolean hasCrossJoin(org.datanucleus.store.mapped.expression.LogicSetExpression tableExpr)
Method to return if the query statement has a cross join involving the supplied table expression. Navigates up through any parent query expression if necessary.

Specified by:
hasCrossJoin in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
tableExpr - table expression
Returns:
whether there is a cross join with this table

crossJoin

public void crossJoin(org.datanucleus.store.mapped.expression.LogicSetExpression tableExpr,
                      boolean unionQueries)
Method to add a cross-join to the supplied table. Cross joins are output in the statement as
FROM TABLE1,TABLE2,TABLE3

Specified by:
crossJoin in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
tableExpr - table expression
unionQueries - Whether to apply the alias to unions of this query.

andCondition

public void andCondition(org.datanucleus.store.mapped.expression.BooleanExpression condition,
                         boolean unionQueries)
add an condition to the query and queries involved in the union if unionQuery is true

Specified by:
andCondition in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
condition - the Boolean expression
unionQueries - whether to apply the condition in all queries unified by the union clause

andCondition

public void andCondition(org.datanucleus.store.mapped.expression.BooleanExpression condition)
Method to add an additional WHERE clause to the query.

Specified by:
andCondition in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
condition - The where clause expression

iorCondition

public void iorCondition(org.datanucleus.store.mapped.expression.BooleanExpression condition,
                         boolean unionQueries)
add an condition to the query and queries involved in the union if unionQuery is true

Specified by:
iorCondition in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
condition - the Boolean expression
unionQueries - whether to apply the condition in all queries unified by the union clause

iorCondition

public void iorCondition(org.datanucleus.store.mapped.expression.BooleanExpression condition)
Method to add an IOR condition to the WHERE clause of the statement.

Specified by:
iorCondition in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
condition - The WHERE clause expression

addGroupingExpression

public void addGroupingExpression(org.datanucleus.store.mapped.expression.ScalarExpression expr)
Method to add a grouping expression to the query. Adds the grouping to any unioned queries

Specified by:
addGroupingExpression in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
expr - The expression

setHaving

public void setHaving(org.datanucleus.store.mapped.expression.BooleanExpression expr)
Mutator for the "having" expression.

Specified by:
setHaving in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
expr - Boolean expression for the having clause

setOrdering

public void setOrdering(org.datanucleus.store.mapped.expression.ScalarExpression[] exprs,
                        boolean[] descending)
Mutator for the ordering criteria.

Specified by:
setOrdering in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
exprs - The expressions to order by
descending - Whether each expression is ascending/descending

setRangeConstraint

public 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.

Specified by:
setRangeConstraint in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
offset - The offset to start from
count - The number of records to return

addOrderingColumnsToSelect

protected void addOrderingColumnsToSelect()
Convenience method to add any necessary columns to the SELECT that are needed by the ordering constraint.


generateOrderingStatement

protected org.datanucleus.store.mapped.expression.StatementText generateOrderingStatement()
Convenience method to generate the ordering statement to add to the overall query statement.

Returns:
The ordering statement

setUpdates

public void setUpdates(org.datanucleus.store.mapped.expression.ScalarExpression[] exprs)
Method to set the UPDATE clause of the statement.

Specified by:
setUpdates in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
exprs - The update clause expression

toDeleteStatementText

public org.datanucleus.store.mapped.expression.StatementText toDeleteStatementText()
Method to convert the criteria into a delete statement text.
 DELETE FROM TBL THIS WHERE THIS.COL3 = VAL3
 

Specified by:
toDeleteStatementText in interface org.datanucleus.store.mapped.expression.QueryExpression
Returns:
The StatementText for the DELETE

toUpdateStatementText

public org.datanucleus.store.mapped.expression.StatementText toUpdateStatementText()
Method to convert the criteria into an update statement text. TODO This could generate more than 1 statement if the updated fields are stored in more than 1 table
 UPDATE TBL THIS SET THIS.COL1 = VAL1, THIS.COL2 = VAL2 WHERE THIS.COL3 = VAL3
 

Specified by:
toUpdateStatementText in interface org.datanucleus.store.mapped.expression.QueryExpression
Returns:
The StatementText for the UPDATE

toStatementText

public org.datanucleus.store.mapped.expression.StatementText toStatementText(boolean lock)
Method to convert the criteria into the statement text.

Specified by:
toStatementText in interface org.datanucleus.store.mapped.expression.QueryExpression
Parameters:
lock - whether to lock the instances using this statement
Returns:
The StatementText

assertNotFrozen

protected void assertNotFrozen()
Assert if the statement text is already generated.

Throws:
org.datanucleus.exceptions.NucleusException - Thrown if the statement is already generated


Copyright © 2009. All Rights Reserved.