|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.xcmis.search.query.QueryBuilder
public class QueryBuilder
A component that can be used to programmatically create QueryCommand
objects. Simply call methods to build the selector clause, from clause, join
criteria, where criteria, limits, and ordering, and then obtain the query. This builder should be adequate for most queries; however,
any query that cannot be expressed by this builder can always be constructed
by directly creating the Abstract Query Model classes.
This builder is stateful and therefore should only be used by one thread at a
time. However, once a query has been built, the builder can be
cleared and used to create another query.
The order in which the methods are called are (for the most part) important.
Simply call the methods in the same order that would be most natural in a
normal SQL query. For example, the following code creates a Query object that
is equivalent to " SELECT * FROM table":
QueryCommand query = builder.selectStar().from("table").query();
Here are a few other examples:
| SQL Statement | QueryBuilder code |
|---|---|
SELECT * FROM table1
INNER JOIN table2
ON table2.c0 = table1.c0
|
query = builder.selectStar().from("table1").join("table2").on("table2.c0=table1.c0").query();
|
SELECT * FROM table1 AS t1
INNER JOIN table2 AS t2
ON t1.c0 = t2.c0
|
query = builder.selectStar().from("table1 AS t1").join("table2 AS t2").on("t1.c0=t2.c0").query();
|
SELECT * FROM table1 AS t1
INNER JOIN table2 AS t2
ON t1.c0 = t2.c0
INNER JOIN table3 AS t3
ON t1.c1 = t3.c1
|
query = builder.selectStar()
.from("table1 AS t1")
.innerJoin("table2 AS t2")
.on("t1.c0=t2.c0")
.innerJoin("table3 AS t3")
.on("t1.c1=t3.c1")
.query();
|
| Nested Class Summary | |
|---|---|
class |
QueryBuilder.AndBuilder<T>
|
class |
QueryBuilder.CastAs<ReturnType>
|
class |
QueryBuilder.CastAsRightHandSide
|
class |
QueryBuilder.ComparisonBuilder
An interface used to set the right-hand side of a constraint. |
class |
QueryBuilder.ConstraintBuilder
|
static interface |
QueryBuilder.DynamicOperandBuilder
Interface that defines a dynamic operand portion of a criteria. |
class |
QueryBuilder.JoinClause
Class used to specify a join clause of a query. |
protected class |
QueryBuilder.LowerCaser
A specialized form of the QueryBuilder.ConstraintBuilder that always wraps the
generated constraint in a LowerCase instance. |
class |
QueryBuilder.OrderByBuilder
The component used to build the order-by clause. |
static interface |
QueryBuilder.OrderByOperandBuilder
|
class |
QueryBuilder.RightHandSide
|
protected class |
QueryBuilder.SingleOrderByOperandBuilder
|
protected class |
QueryBuilder.UpperCaser
A specialized form of the QueryBuilder.ConstraintBuilder that always wraps the
generated constraint in a UpperCase instance. |
| Field Summary | |
|---|---|
protected CastSystem |
castSystem
|
protected List<Column> |
columns
|
protected Constraint |
constraint
|
protected boolean |
distinct
|
protected Query |
firstQuery
|
protected boolean |
firstQueryAll
|
protected Limit |
limit
|
protected List<Ordering> |
orderings
|
protected Source |
source
|
| Constructor Summary | |
|---|---|
QueryBuilder(CastSystem castSystem)
Create a new builder that uses the supplied execution context. |
|
| Method Summary | |
|---|---|
QueryBuilder |
clear()
Clear this builder completely to start building a new query. |
protected QueryBuilder |
clear(boolean clearFirstQuery)
Utility method that does all the work of the clear, but with a flag that defines whether to clear the first query. |
protected Column |
column(String nameExpression)
Create a Column given the supplied expression. |
QueryBuilder |
from(String tableNameWithOptionalAlias)
Specify the name of the table from which tuples should be selected. |
QueryBuilder.JoinClause |
innerJoin(String tableName)
Perform an inner join between the already defined source with the supplied table. |
QueryBuilder.JoinClause |
join(String tableName)
Perform an inner join between the already defined source with the supplied table. |
QueryBuilder.JoinClause |
leftOuterJoin(String tableName)
Perform a left outer join between the already defined source with the supplied table. |
QueryBuilder |
limit(int rowLimit)
Specify the maximum number of rows that are to be returned in the results. |
protected Selector |
namedSelector(String nameWithOptionalAlias)
Convenience method that creates a Selector object given a string
that contains the selector name and optionally an alias. |
QueryBuilder |
offset(int offset)
Specify the number of rows that results are to skip. |
QueryBuilder.OrderByBuilder |
orderBy()
Obtain a builder that will create the order-by clause (with one or more Ordering statements) for the query. |
Query |
query()
Return a QueryCommand representing the currently-built query. |
QueryBuilder.JoinClause |
rightOuterJoin(String tableName)
Perform a right outer join between the already defined source with the supplied table. |
QueryBuilder |
select(String... columnNames)
Add to the select clause the columns with the supplied names. |
QueryBuilder |
selectDistinct(String... columnNames)
Select the distinct values from the columns with the supplied names. |
QueryBuilder |
selectDistinctStar()
Select all of the distinct values from the single-valued columns. |
protected SelectorName |
selector(String name)
Convenience method that creates a selector name object using the supplied string. |
QueryBuilder |
selectStar()
Select all of the single-valued columns. |
QueryBuilder.ConstraintBuilder |
where()
Begin the WHERE clause for this query by obtaining the constraint builder. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final CastSystem castSystem
protected Source source
protected Constraint constraint
protected List<Column> columns
protected List<Ordering> orderings
protected Limit limit
protected boolean distinct
protected Query firstQuery
protected boolean firstQueryAll
| Constructor Detail |
|---|
public QueryBuilder(CastSystem castSystem)
context - the execution context
IllegalArgumentException - if the context is null| Method Detail |
|---|
public QueryBuilder clear()
protected QueryBuilder clear(boolean clearFirstQuery)
clear() as well as the many set operations.
clearFirstQuery - true if the first query should be cleared, or false if the first
query should be retained
protected SelectorName selector(String name)
name - the name of the selector; may not be null
protected Selector namedSelector(String nameWithOptionalAlias)
Selector object given a string
that contains the selector name and optionally an alias. The format of the
string parameter is name [AS alias]. Leading and trailing
whitespace are trimmed.
nameWithOptionalAlias - the name and optional alias; may not be null
protected Column column(String nameExpression)
Column given the supplied expression. The expression has
the form "[tableName.]columnName", where "
tableName" must be a valid table name or alias. If the table
name/alias is not specified, then there is expected to be a single FROM
clause with a single named selector.
nameExpression - the expression specifying the columm name and (optionally) the
table's name or alias; may not be null
IllegalArgumentException - if the table's name/alias is not specified, but the query has
more than one named sourcepublic QueryBuilder selectStar()
public QueryBuilder select(String... columnNames)
[tableName.]columnName", where "
tableName" must be a valid table name or alias. If the table
name/alias is not specified, then there is expected to be a single FROM
clause with a single named selector.
columnNames - the column expressions; may not be null
IllegalArgumentException - if the table's name/alias is not specified, but the query has
more than one named sourcepublic QueryBuilder selectDistinctStar()
public QueryBuilder selectDistinct(String... columnNames)
[tableName.]columnName", where "
tableName" must be a valid table name or alias. If the table
name/alias is not specified, then there is expected to be a single FROM
clause with a single named selector.
columnNames - the column expressions; may not be null
IllegalArgumentException - if the table's name/alias is not specified, but the query has
more than one named sourcepublic QueryBuilder from(String tableNameWithOptionalAlias)
tableName [AS alias]".
tableNameWithOptionalAlias - the name of the table, optionally including the alias
public QueryBuilder.ConstraintBuilder where()
end() on
the resulting constraint builder, or else the constraint will not be
applied to the current query.
public QueryBuilder.JoinClause join(String tableName)
tableName [AS alias]".
tableName - the name of the table, optionally including the alias
public QueryBuilder.JoinClause innerJoin(String tableName)
tableName [AS alias]".
tableName - the name of the table, optionally including the alias
public QueryBuilder.JoinClause leftOuterJoin(String tableName)
tableName [AS alias]".
tableName - the name of the table, optionally including the alias
public QueryBuilder.JoinClause rightOuterJoin(String tableName)
tableName [AS alias]".
tableName - the name of the table, optionally including the alias
public QueryBuilder limit(int rowLimit)
rowLimit - the maximum number of rows
IllegalArgumentException - if the row limit is not a positive integerpublic QueryBuilder offset(int offset)
offset - the number of rows before the results are to begin
IllegalArgumentException - if the row limit is a negative integerpublic QueryBuilder.OrderByBuilder orderBy()
Ordering statements) for the query. This method need be called
only once to build the order-by clause, but can be called multiple times
(it merely adds additional Ordering statements).
public Query query()
QueryCommand representing the currently-built query.
clear()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||