|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jpox.store.query.QueryStatement
public class QueryStatement
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.
| Nested Class Summary | |
|---|---|
static class |
QueryStatement.Join
A join in a query. |
| Field Summary | |
|---|---|
protected java.util.List |
crossJoins
add tables/crossJoin but no joins to they, will be output as FROM TABLE1,TABLE2,TABLE3 |
protected DatastoreAdapter |
dba
|
protected DatastoreIdentifier |
defaultRangeVar
|
protected boolean |
distinctResults
|
protected java.util.List |
groupingExpressions
User-provided expressions for GROUP BY clause. |
protected boolean |
hasAggregateExpression
whether there is an aggregate expression present in the select |
protected BooleanExpression |
havingExpr
Expression for any HAVING clause. |
protected LogicSetExpression |
initialTableExpr
|
protected boolean |
isExistsSubQuery
Whether this query is to be used as a as set for the Exists function. |
protected java.util.List |
joins
inner/left/right joins |
protected java.util.List |
joinsTo
ensures that we don't have duplicate JOINs From vs To |
protected static Localiser |
LOCALISER
Localisation for messages. |
protected boolean[] |
orderingDirections
Directions for any ORDER BY expressions (1 for each orderingExpressions entry). |
protected 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 |
selected
projected in columns |
protected char |
stmtJoinsSeparator
Separate joins e.g. |
protected StatementText |
stmtText
Statement text for this Query Statement. |
protected StoreManager |
storeMgr
|
protected java.util.Map |
tableExprsByRangeVar
|
protected java.util.List |
union
union to many QueryExpressions |
protected boolean |
useInnerJoinsOnly
Flag to allow overriding of the default join type applied by JPOX. |
protected BooleanExpression |
whereExpr
filter condition |
| Constructor Summary | |
|---|---|
QueryStatement(DatastoreContainerObject initialTable,
ClassLoaderResolver clr)
Constructor. |
|
QueryStatement(DatastoreContainerObject initialTable,
DatastoreIdentifier initialRangeVar,
ClassLoaderResolver clr)
Constructor. |
|
| Method Summary | |
|---|---|
void |
addGroupingExpression(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(BooleanExpression condition)
Method to add an additional WHERE clause 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 |
protected void |
assertNotFrozen()
|
void |
crossJoin(LogicSetExpression tableExpr,
boolean unionQueries)
Method to add tables/alias but no joins to they, will be output as FROM TABLE1,TABLE2,TABLE3 |
protected StatementText |
generateOrderingStatement()
Convenience method to generate the ordering statement to add to the overall query statement. |
ClassLoaderResolver |
getClassLoaderResolver()
Accessor for the class-loader resolver. |
LogicSetExpression |
getDefaultTableExpression()
Accessor for the main table for this query statement. |
boolean |
getDistinctResults()
Accessor for whether this query will return distinct results. |
ScalarExpression[] |
getGroupingExpressions()
Accessor for the grouping expressions (if any). |
BooleanExpression |
getHavingExpression()
Accessor for the having expression (if any). |
LogicSetExpression |
getInitialTableExpr()
Accessor for the main table of this statement. |
int |
getNumberOfScalarExpressions()
Accessor for the number of ScalarExpression projected. |
ScalarExpression[] |
getOrderingExpressions()
Accessor for the ordering expressions (if any). |
StoreManager |
getStoreManager()
Accessor for the Store Manager. |
LogicSetExpression |
getTableExpression(DatastoreIdentifier rangeVar)
Accessor for the table with the specified "alias". |
boolean |
getUseInnerJoinsOnly()
Accessor for whether to only use inner joins. |
boolean |
hasCrossJoin(LogicSetExpression tableExpr)
Method to add tables/alias but no joins to they, will be output as FROM TABLE1,TABLE2,TABLE3 |
boolean |
hasMetaDataExpression()
Whether this query will return a meta data expression (containing JPOXMETADATA). |
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)
Method to add an IOR condition to the WHERE clause of the statement. |
void |
iorCondition(BooleanExpression condition,
boolean unionQueries)
add an condition to the query and queries involved in the union if unionQuery is true |
void |
join(ScalarExpression expr1,
ScalarExpression expr2,
LogicSetExpression tblExpr,
int joinType,
boolean equals)
Method to do a join to another table. |
void |
join(ScalarExpression expr1,
ScalarExpression expr2,
LogicSetExpression tblExpr,
int joinType,
boolean equals,
boolean unionQueries)
Method to add a join to another table. |
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 rangeVar)
Creates a table expression |
LogicSetExpression[] |
newTableExpression(DatastoreContainerObject mainTable,
DatastoreIdentifier rangeVar,
boolean unionQueries)
Creates a table expression |
void |
reset()
Resets the compiled expression statement. |
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 rangeVar,
JavaTypeMapping mapping)
Select columns of the specified mapping for the table identifier. |
int[] |
select(DatastoreIdentifier rangeVar,
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 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(ScalarExpression expr)
Select an expression. |
int |
selectScalarExpression(ScalarExpression expr,
boolean unionQueries)
Select an expression. |
int[] |
selectVersion(java.lang.String alias)
Select the version column of the primary table of the query. |
int[] |
selectVersion(java.lang.String alias,
boolean unionQueries)
Select the version column of the primary table of 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(BooleanExpression expr)
Mutator for the "having" expression. |
void |
setOrdering(ScalarExpression[] exprs,
boolean[] descending)
Mutator for the ordering criteria. |
void |
setRangeConstraint(long offset,
long count)
Method to add a range constraint on any SELECT. |
void |
setUseInnerJoinsOnly(boolean innerJoins)
Mutator for whether to use only inner joins. |
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. |
java.lang.String |
toString()
|
java.lang.String |
toString(boolean lock)
Stringifier |
void |
union(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, wait, wait, wait |
| Field Detail |
|---|
protected static final Localiser LOCALISER
protected final StoreManager storeMgr
protected final DatastoreAdapter dba
protected final DatastoreIdentifier defaultRangeVar
protected final LogicSetExpression initialTableExpr
protected java.util.Map tableExprsByRangeVar
protected boolean distinctResults
protected java.util.List selected
protected java.util.List joins
protected java.util.List union
protected BooleanExpression whereExpr
protected java.util.List groupingExpressions
protected BooleanExpression havingExpr
protected ScalarExpression[] orderingExpressions
protected boolean[] orderingDirections
protected StatementText stmtText
protected char stmtJoinsSeparator
protected boolean hasAggregateExpression
protected java.util.List joinsTo
protected java.util.List crossJoins
protected boolean isExistsSubQuery
e.g WHERE EXISTS(QUERY).
protected long rangeOffset
protected long rangeCount
protected boolean useInnerJoinsOnly
| Constructor Detail |
|---|
public QueryStatement(DatastoreContainerObject initialTable,
ClassLoaderResolver clr)
initialTable - The main table for this statement.clr - ClassLoader resolver
public QueryStatement(DatastoreContainerObject initialTable,
DatastoreIdentifier initialRangeVar,
ClassLoaderResolver clr)
initialTable - The main table for this statement.initialRangeVar - The alias for the main tableclr - ClassLoader resolver.| Method Detail |
|---|
protected void assertNotFrozen()
public void reset()
reset in interface QueryExpressionpublic ClassLoaderResolver getClassLoaderResolver()
getClassLoaderResolver in interface QueryExpressionpublic LogicSetExpression getInitialTableExpr()
public StoreManager getStoreManager()
getStoreManager in interface QueryExpressionpublic LogicSetExpression getTableExpression(DatastoreIdentifier rangeVar)
getTableExpression in interface QueryExpressionrangeVar - Alias for the table required
public LogicSetExpression getDefaultTableExpression()
getDefaultTableExpression in interface QueryExpression
public LogicSetExpression newTableExpression(DatastoreContainerObject mainTable,
DatastoreIdentifier rangeVar)
QueryExpression
newTableExpression in interface QueryExpressionmainTable - the main tablerangeVar - the range var
public LogicSetExpression[] newTableExpression(DatastoreContainerObject mainTable,
DatastoreIdentifier rangeVar,
boolean unionQueries)
QueryExpression
newTableExpression in interface QueryExpressionmainTable - the main tablerangeVar - the range varunionQueries - Whether to add to any union
public boolean getDistinctResults()
public void setDistinctResults(boolean distinctResults)
setDistinctResults in interface QueryExpressiondistinctResults - Whether to return distinctpublic void setExistsSubQuery(boolean isExistsSubQuery)
setExistsSubQuery in interface QueryExpressionisExistsSubQuery - The isExistsSubQuery to set.public void union(QueryExpression expr)
union in interface QueryExpressionexpr - The other query statement to unionpublic boolean getUseInnerJoinsOnly()
public void setUseInnerJoinsOnly(boolean innerJoins)
setUseInnerJoinsOnly in interface QueryExpressioninnerJoins - Whether to just use inner joins
public int[] selectDatastoreIdentity(java.lang.String alias,
boolean unionQueries)
selectDatastoreIdentity in interface QueryExpressionalias - Alias to use for the selected datastore identity column (if any)unionQueries - Whether to apply to the primary table of any unioned tables
public int[] selectVersion(java.lang.String alias,
boolean unionQueries)
selectVersion in interface QueryExpressionalias - 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
public int[] selectField(java.lang.String fieldName,
java.lang.String alias,
boolean unionQueries)
selectField in interface QueryExpressionfieldName - 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
public int[] selectVersion(java.lang.String alias)
alias - Alias to use for the selected version column (if any)
public int[] select(JavaTypeMapping mapping)
select in interface QueryExpressionmapping - The mapping
public int[] select(JavaTypeMapping mapping,
boolean unionQueries)
select in interface QueryExpressionmapping - The mappingunionQueries - Whether to add to any union
public int[] select(DatastoreIdentifier rangeVar,
JavaTypeMapping mapping)
select in interface QueryExpressionrangeVar - The range variablemapping - The mapping
public int[] select(DatastoreIdentifier rangeVar,
JavaTypeMapping mapping,
boolean unionQueries)
select in interface QueryExpressionrangeVar - The range variablemapping - The mappingunionQueries - Whether to add to any union
public int selectScalarExpression(ScalarExpression expr)
selectScalarExpression in interface QueryExpressionexpr - The expression to add to the select statement
public int selectScalarExpression(ScalarExpression expr,
boolean unionQueries)
selectScalarExpression in interface QueryExpressionexpr - The expression to add to the select statementunionQueries - whether to apply the select in all queries unified by the union clause
public int getNumberOfScalarExpressions()
getNumberOfScalarExpressions in interface QueryExpressionpublic boolean hasMetaDataExpression()
hasMetaDataExpression in interface QueryExpressionpublic boolean hasCrossJoin(LogicSetExpression tableExpr)
hasCrossJoin in interface QueryExpressiontableExpr - table expression
public void crossJoin(LogicSetExpression tableExpr,
boolean unionQueries)
crossJoin in interface QueryExpressiontableExpr - table expressionunionQueries - Whether to apply the alias to unions of this query.
public void join(ScalarExpression expr1,
ScalarExpression expr2,
LogicSetExpression tblExpr,
int joinType,
boolean equals,
boolean unionQueries)
expr1 - the left hand expressionexpr2 - the right hand expressiontblExpr - The table expression for the table to apply the joinjoinType - Type of joinequals - if the join is applied as filter, if use equals or not equalsunionQueries - Whether to apply to all unioned queries as well
public void join(ScalarExpression expr1,
ScalarExpression expr2,
LogicSetExpression tblExpr,
int joinType,
boolean equals)
expr1 - the left hand expressionexpr2 - the right hand expressiontblExpr - The table expression for the table to apply the joinjoinType - Type of joinequals - if the join is applied as filter, if use equals or not equals
public void innerJoin(ScalarExpression expr,
ScalarExpression expr2,
LogicSetExpression tblExpr,
boolean equals,
boolean unionQueries)
innerJoin in interface QueryExpressionexpr - the left hand expressionexpr2 - the right hand expressiontblExpr - theequals - if the join is applied as filter, if use equals or not equalsunionQueries - whether to apply the inner join in all queries unified by the union clause
public void innerJoin(ScalarExpression expr,
ScalarExpression expr2,
LogicSetExpression tblExpr,
boolean equals)
innerJoin in interface QueryExpressionexpr - the left hand expressionexpr2 - the right hand expressiontblExpr - The table expression for the table to apply the joinequals - if the join is applied as filter, if use equals or not equals
public void leftOuterJoin(ScalarExpression expr,
ScalarExpression expr2,
LogicSetExpression tblExpr,
boolean equals,
boolean unionQueries)
leftOuterJoin in interface QueryExpressionexpr - the left hand expressionexpr2 - the right hand expressiontblExpr - The table expression for the table to apply the joinequals - if the join is applied as filter, if use equals or not equalsunionQueries - Whether to apply to unions of this query.
public void leftOuterJoin(ScalarExpression expr,
ScalarExpression expr2,
LogicSetExpression tblExpr,
boolean equals)
leftOuterJoin in interface QueryExpressionexpr - the left hand expressionexpr2 - the right hand expressiontblExpr - The table expressionequals - if the join is applied as filter, if use equals or not equals
public void rightOuterJoin(ScalarExpression expr,
ScalarExpression expr2,
LogicSetExpression tblExpr,
boolean equals,
boolean unionQueries)
rightOuterJoin in interface QueryExpressionexpr - the left hand expressionexpr2 - the right hand expressiontblExpr - The table expression for the table to apply the joinequals - if the join is applied as filter, if use equals or not equalsunionQueries - Whether to apply to unions of this query.
public void rightOuterJoin(ScalarExpression expr,
ScalarExpression expr2,
LogicSetExpression tblExpr,
boolean equals)
rightOuterJoin in interface QueryExpressionexpr - the left hand expressionexpr2 - the right hand expressiontblExpr - The table expression for the table to apply the joinequals - if the join is applied as filter, if use equals or not equals
public void andCondition(BooleanExpression condition,
boolean unionQueries)
andCondition in interface QueryExpressioncondition - the Boolean expressionunionQueries - whether to apply the condition in all queries unified by the union clausepublic void andCondition(BooleanExpression condition)
andCondition in interface QueryExpressioncondition - The where clause expression
public void iorCondition(BooleanExpression condition,
boolean unionQueries)
iorCondition in interface QueryExpressioncondition - the Boolean expressionunionQueries - whether to apply the condition in all queries unified by the union clausepublic void iorCondition(BooleanExpression condition)
iorCondition in interface QueryExpressioncondition - The WHERE clause expressionpublic void addGroupingExpression(ScalarExpression expr)
addGroupingExpression in interface QueryExpressionexpr - The expressionpublic ScalarExpression[] getGroupingExpressions()
getGroupingExpressions in interface QueryExpressionpublic void setHaving(BooleanExpression expr)
setHaving in interface QueryExpressionexpr - Boolean expression for the having clausepublic BooleanExpression getHavingExpression()
getHavingExpression in interface QueryExpression
public void setOrdering(ScalarExpression[] exprs,
boolean[] descending)
setOrdering in interface QueryExpressionexprs - The expressions to order bydescending - Whether each expression is ascending/descendingpublic ScalarExpression[] getOrderingExpressions()
getOrderingExpressions in interface QueryExpression
public void setRangeConstraint(long offset,
long count)
setRangeConstraint in interface QueryExpressionoffset - The offset to start fromcount - The number of records to returnpublic StatementText toDeleteStatementText()
toDeleteStatementText in interface QueryExpressionprotected void addOrderingColumnsToSelect()
protected StatementText generateOrderingStatement()
public StatementText toStatementText(boolean lock)
toStatementText in interface QueryExpressionlock - whether to lock the instances using this statement
public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String toString(boolean lock)
lock - Whether to lock the rows found by this SELECT
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||