| java.lang.Object jimm.datavision.source.Query jimm.datavision.source.sql.SQLQuery
All known Subclasses: jimm.datavision.source.sql.SubreportQuery, jimm.datavision.source.ncsql.NCQuery,
SQLQuery | public class SQLQuery extends Query (Code) | | Queries build SQL query strings. They contain tables, joins, and
where clauses.
author: Jim Menard, jimm@io.com See Also: ParserHelper |
Method Summary | |
protected void | addParameter(StringBuffer buf, String prevWord, String idAsString) Given a parameter id string, add its value(s) to the parameter list
and add prepared statement placeholders in the query buffer. | protected void | addParameterForDisplay(StringBuffer buf, String prevWord, String idAsString) Given a parameter id string, add it and a possible modified previous
word to buf. | protected void | addTable(Table t) Adds the table t to tables, but only if t
is not null and is not already in tables. | protected void | buildFrom(StringBuffer str) | protected void | buildJoins(StringBuffer str) | protected void | buildOrderBy(StringBuffer str) | protected void | buildSelect(StringBuffer str) | protected void | buildUserWhereClause(StringBuffer str, boolean forDisplay) | protected void | buildWhereClause(StringBuffer str, boolean forDisplay) | public void | findSelectablesUsed() Builds collections of the report tables and selectable fields actually used
in the report. | public int | getNumTables() Returns the number of tables in the query. | public Collection | getTablesUsed() Returns a collection containing the tables used by this query. | protected String | getWhereClauseForDisplay() Returns the where clause string; may be null . | protected String | getWhereClauseForPreparedStatement() Returns the where clause string; may be null . | public String | prepare(String clause) Given a clause (really any string), replace all formulas and parameters
with their values. | protected String | queryAsString(boolean forDisplay) Returns the query as either a human-readable SQL statement or a SQL
string suitable for building a prepared statement. | public String | quoted(String name) Quotes those parts of a table or column name that need to be quoted. | public void | setParameters(PreparedStatement stmt) Given a prepared statement created with the text returned by
toPreparedStatementString , plug in all the parameter
and formula values. | public String | toPreparedStatementString() Returns the query as a SQL string suitable for building a prepared
statement. | public String | toString() Returns the query as a human-readable SQL statement, including parameter,
formula, and user column display strings. |
SQLQuery | public SQLQuery(Report report)(Code) | | Constructor.
Parameters: report - the report for which this query will generate SQL |
addParameter | protected void addParameter(StringBuffer buf, String prevWord, String idAsString)(Code) | | Given a parameter id string, add its value(s) to the parameter list
and add prepared statement placeholders in the query buffer. Appends
the previous word to the buffer. The previous word may be modified
if the circumstances call for it. For example, we want to turn
"foo in {?Range Parameter}" into "foo between ? and ?". The value
of prevWord here would be "in". We would append "between"
to the buffer and return the "word" "? and ".
Parameters: buf - a string buffer containing the SQL query so far Parameters: prevWord - the previous word Parameters: idAsString - the parameter id |
addParameterForDisplay | protected void addParameterForDisplay(StringBuffer buf, String prevWord, String idAsString)(Code) | | Given a parameter id string, add it and a possible modified previous
word to buf. Does not modify preparedStmtValues
list.
Parameters: buf - a string buffer containing the SQL query so far Parameters: prevWord - the previous word Parameters: idAsString - the parameter id See Also: SQLQuery.addParameter |
addTable | protected void addTable(Table t)(Code) | | Adds the table t to tables, but only if t
is not null and is not already in tables. We
compare tables by name instead of value (pointer) because different table
object may refer to the same table, for example if one is from the report
and the other is from a subreport.
Parameters: t - a Table |
buildUserWhereClause | protected void buildUserWhereClause(StringBuffer str, boolean forDisplay)(Code) | | |
buildWhereClause | protected void buildWhereClause(StringBuffer str, boolean forDisplay)(Code) | | |
findSelectablesUsed | public void findSelectablesUsed()(Code) | | Builds collections of the report tables and selectable fields actually used
in the report.
|
getNumTables | public int getNumTables()(Code) | | Returns the number of tables in the query. Does not recalculate the
columns or tables used; we assume this is being called after the query
has been run, or at least after findSelectablesUsed has
been called.
This method is only used for testing, so far.
|
getTablesUsed | public Collection getTablesUsed()(Code) | | Returns a collection containing the tables used by this query.
the collection of tables used by this query |
getWhereClauseForDisplay | protected String getWhereClauseForDisplay()(Code) | | Returns the where clause string; may be null . If there are
any column names contained in curly braces, we remove the curly braces.
Formulas, parameters, and user colums remain as-is.
Implementation note: we can't use StringUtils.replaceDelimited
because we modify the symbol that appears before some of the
delimited items.
the where clause string; may be null See Also: SQLQuery.getWhereClause |
getWhereClauseForPreparedStatement | protected String getWhereClauseForPreparedStatement()(Code) | | Returns the where clause string; may be null . If there
are any parameter values, we return '?' in their place and save the
values for later use.
This code may also modify the clause. For example, a parameter can
change the previous comparison operator ("=", "is") based on its arity.
the where clause string; may be null See Also: SQLQuery.getWhereClause |
prepare | public String prepare(String clause)(Code) | | Given a clause (really any string), replace all formulas and parameters
with their values. Anything else in curly braces must be a column; we
remove the curly braces and quote the name.
Implementation note: we can't use StringUtils.replaceDelimited
because we modify the symbol that appears before some of the
delimited items.
|
queryAsString | protected String queryAsString(boolean forDisplay)(Code) | | Returns the query as either a human-readable SQL statement or a SQL
string suitable for building a prepared statement.
Parameters: forDisplay - if true return a human-readable string,else return a SQL string suitable for building a prepared statement a SQL string |
quoted | public String quoted(String name)(Code) | | Quotes those parts of a table or column name that need to be quoted.
Different databases and JDBC drivers treat case sensitively differently.
We use the database metadata case sensitivity values to determine which
parts of the name need to be quoted.
Parameters: name - a table or column name a quoted version of the name |
toPreparedStatementString | public String toPreparedStatementString()(Code) | | Returns the query as a SQL string suitable for building a prepared
statement.
a SQL query string |
toString | public String toString()(Code) | | Returns the query as a human-readable SQL statement, including parameter,
formula, and user column display strings.
a SQL query string |
|
|