org.gusdb.wdk.model.implementation
Class SqlClause
java.lang.Object
org.gusdb.wdk.model.implementation.SqlClause
public class SqlClause
- extends java.lang.Object
An sql clause: a section of sql bounded by a parenthesis pair that
may contain other such sections (kids). The sections of sql within the
clause that are not within kid clauses are "pieces." A clause has
K + 1 pieces where K (>=0) is the number of kid clauses.
For example, the (contrived) sql:
(select author from (select * from books) where title = "war and peace")
Has two pieces:
'select author from '
' where title = "war and peace'
and one kid:
(select * from books)
The objective of this class is to:
- recursively construct clauses found in the sql
- for each clause:
- virtually assemble its pieces into a super-piece
- see if the super-piece contains both:
- a FROM statement
- a WHERE statement that includes PRIMARY_KEY_NAME as a value
- if such a pair is found, use the helper class SqlClausePiece to add:
- the join table's row index to the SELECT statement
- the JOIN_TABLE to the FROM statement
- the page constraints to the WHERE statement
- the join table's row index a GROUP BY statement, if present
- if any of its kid clauses get the SELECT statement modification
apply that modification as well to the parent (propagating up)
- if the clause is the outermost one, wrap it in a SELECT * FROM (...
) ORDER BY the join table's row index
Because literals never contain information we need for this analysis, and
because they can confuse things by containing "select" or "from", we
excise them at the beginning, and replace them at the end
|
Constructor Summary |
SqlClause(java.lang.String origSql,
java.lang.String joinTableName,
int pageStartIndex,
int pageEndIndex,
RDBMSPlatformI platform)
|
|
Method Summary |
java.lang.String |
getModifiedSql()
|
static void |
main(java.lang.String[] args)
|
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SqlClause
public SqlClause(java.lang.String origSql,
java.lang.String joinTableName,
int pageStartIndex,
int pageEndIndex,
RDBMSPlatformI platform)
throws WdkModelException
- Throws:
WdkModelException
getModifiedSql
public java.lang.String getModifiedSql()
throws WdkModelException
- Returns:
- the improved sql
- Throws:
WdkModelException
main
public static void main(java.lang.String[] args)