|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectmondrian.rolap.sql.SqlQuery
public class SqlQuery
SqlQuery allows us to build a select
statement and generate it in database-specific SQL syntax.
Notable differences in database syntax are:
select * from "emp". Access prefers brackets,
for example select * from [emp]. mySQL allows single- and
double-quotes for string literals, and therefore does not allow
identifiers to be quoted, for example select 'foo', "bar" from
emp. select from emp as e vs. select * from emp
e. select empno + 1 from emp. select * from (emp) select * from
(select * from emp) as e.NOTE: Instances of this class are NOT thread safe so the user must make sure this is accessed by only one thread at a time.
| Nested Class Summary | |
|---|---|
(package private) static class |
SqlQuery.ClauseList
|
static class |
SqlQuery.CodeSet
Collection of alternative code for alternative dialects. |
(package private) static class |
SqlQuery.FromClauseList
|
| Constructor Summary | |
|---|---|
SqlQuery(Dialect dialect)
Creates a SqlQuery using a given dialect and inheriting the formatting preferences from MondrianProperties.GenerateFormattedSql
property. |
|
SqlQuery(Dialect dialect,
boolean formatted)
Base constructor used by all other constructors to create an empty instance. |
|
| Method Summary | |
|---|---|
boolean |
addFrom(MondrianDef.RelationOrJoin relation,
String alias,
boolean failIfExists)
Adds a relation to a query, adding appropriate join conditions, unless it is already present. |
void |
addFrom(SqlQuery sqlQuery,
String alias,
boolean failIfExists)
|
boolean |
addFromQuery(String query,
String alias,
boolean failIfExists)
Adds a subquery to the FROM clause of this Query with a given alias. |
(package private) boolean |
addFromTable(String schema,
String name,
String alias,
String filter,
Map hints,
boolean failIfExists)
Adds [schema.]table AS alias to the FROM clause. |
void |
addGroupBy(String expression)
|
void |
addGroupBy(String expression,
String alias)
|
void |
addGroupingFunction(String columnExpr)
|
void |
addGroupingSet(List<String> groupingColumnsExpr)
|
void |
addHaving(String expression)
|
void |
addOrderBy(String expr,
boolean ascending,
boolean prepend,
boolean nullable)
Adds an item to the ORDER BY clause. |
void |
addOrderBy(String expr,
boolean ascending,
boolean prepend,
boolean nullable,
boolean collateNullsLast)
Adds an item to the ORDER BY clause. |
String |
addSelect(String expression,
SqlStatement.Type type)
Adds an expression to the select clause, automatically creating a column alias. |
String |
addSelect(String expression,
SqlStatement.Type type,
String alias)
Adds an expression to the select clause, with a specified type and column alias. |
String |
addSelectGroupBy(String expression,
SqlStatement.Type type)
Adds an expression to the SELECT and GROUP BY clauses. |
void |
addWhere(RolapStar.Condition joinCondition)
|
void |
addWhere(String expression)
|
void |
addWhere(String exprLeft,
String exprMid,
String exprRight)
|
SqlQuery |
cloneEmpty()
Creates an empty SqlQuery with the same environment as this
one. |
String |
getAlias(String expression)
|
int |
getCurrentSelectListSize()
|
Dialect |
getDialect()
|
static SqlQuery |
newQuery(DataSource dataSource,
String err)
|
String |
nextColumnAlias()
|
void |
registerRootRelation(MondrianDef.RelationOrJoin root)
|
void |
setAllowHints(boolean t)
Chooses whether table optimization hints may be used (assuming the dialect supports it). |
void |
setDistinct(boolean distinct)
|
void |
toBuffer(StringBuilder buf,
String prefix)
Writes this SqlQuery to a StringBuilder with each clause on a separate line, and with the specified indentation prefix. |
Pair<String,List<SqlStatement.Type>> |
toSqlAndTypes()
|
String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public SqlQuery(Dialect dialect,
boolean formatted)
dialect - Dialectformatted - Whether to generate SQL formatted on multiple linespublic SqlQuery(Dialect dialect)
MondrianProperties.GenerateFormattedSql
property.
dialect - Dialect| Method Detail |
|---|
public SqlQuery cloneEmpty()
SqlQuery with the same environment as this
one. (As per the Gang of Four 'prototype' pattern.)
public void setDistinct(boolean distinct)
public void setAllowHints(boolean t)
t - True to allow hints to be used, false otherwise
public boolean addFromQuery(String query,
String alias,
boolean failIfExists)
failIfExists, throws an exception or does not add the query
and returns false.
query - Subqueryalias - (if not null, must not be zero length).failIfExists - if true, throws exception if alias already exists
boolean addFromTable(String schema,
String name,
String alias,
String filter,
Map hints,
boolean failIfExists)
[schema.]table AS alias to the FROM clause.
schema - schema name; may be nullname - table namealias - table alias, may not be null
(if not null, must not be zero length).filter - Extra filter condition, or nullhints - table optimization hints, if anyfailIfExists - Whether to throw a RuntimeException if from clause
already contains this alias
public void addFrom(SqlQuery sqlQuery,
String alias,
boolean failIfExists)
public boolean addFrom(MondrianDef.RelationOrJoin relation,
String alias,
boolean failIfExists)
Returns whether the relation was added to the query.
relation - Relation to addalias - Alias of relation. If null, uses relation's alias.failIfExists - Whether to fail if relation is already present
public String addSelect(String expression,
SqlStatement.Type type)
public String addSelectGroupBy(String expression,
SqlStatement.Type type)
expression - Expression
public int getCurrentSelectListSize()
public String nextColumnAlias()
public String addSelect(String expression,
SqlStatement.Type type,
String alias)
expression - Expressiontype - Java type to be used to hold cursor columnalias - Column alias (or null for no alias)
public String getAlias(String expression)
public void addWhere(String exprLeft,
String exprMid,
String exprRight)
public void addWhere(RolapStar.Condition joinCondition)
public void addWhere(String expression)
public void addGroupBy(String expression)
public void addGroupBy(String expression,
String alias)
public void addHaving(String expression)
public void addOrderBy(String expr,
boolean ascending,
boolean prepend,
boolean nullable)
expr - the expr to order byascending - sort directionprepend - whether to prepend to the current list of itemsnullable - whether the expression might be null
public void addOrderBy(String expr,
boolean ascending,
boolean prepend,
boolean nullable,
boolean collateNullsLast)
expr - the expr to order byascending - sort directionprepend - whether to prepend to the current list of itemsnullable - whether the expression might be nullcollateNullsLast - whether null values should appear first or last.public String toString()
toString in class Object
public void toBuffer(StringBuilder buf,
String prefix)
buf - String builderprefix - Prefix for each linepublic Dialect getDialect()
public static SqlQuery newQuery(DataSource dataSource,
String err)
public void addGroupingSet(List<String> groupingColumnsExpr)
public void addGroupingFunction(String columnExpr)
public Pair<String,List<SqlStatement.Type>> toSqlAndTypes()
public void registerRootRelation(MondrianDef.RelationOrJoin root)
|
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||