|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.objectwave.persist.sqlConstruction.SQLObject | +--com.objectwave.persist.sqlConstruction.SQLSelect
A class that handles the creation of SQL Select statements. For example:
SQLSelect sql = new SQLSelect("TABLENAME");
com.objectwave.persist.SQLAssembler
,
com.objectwave.persist.RDBBroker
Nested Class Summary | |
static class |
SQLSelect.Test
|
Field Summary | |
java.util.ArrayList |
columnList
|
java.lang.StringBuffer |
columnListBuffer
|
static char |
nextAlias
|
Fields inherited from class com.objectwave.persist.sqlConstruction.SQLObject |
availableForPool, table |
Constructor Summary | |
SQLSelect()
|
|
SQLSelect(java.lang.String tableName)
Create a SQLSelect to find information from the specified table. |
|
SQLSelect(java.lang.String tableName,
boolean exclusiveReadLock)
|
Method Summary | |
void |
addColumnList(java.lang.String aVal)
Used for adding one element May update the instance variable 'first' to indicate that at least one column has been added to the column list buffer. |
protected void |
addColumnList(java.lang.String[] columns)
Add a list of columns to our list of columns. |
void |
addOrderBy(java.util.Vector paths,
Persistence source)
This can not be called until the SQL is completely built...other than the Order by clause. |
protected void |
addOrderByImpl(java.lang.String orderByColumn,
boolean descend)
Assemble a string buffer that will represent the order by part of a Sql statement. |
void |
addWhereClause(java.lang.String clause)
Add the clause to our list of where clauses. |
void |
clean()
When returning the object to the ObjectPool, the object must be 'clean'. |
void |
clearColumnList()
Empty the list of columns. |
java.lang.StringBuffer |
createWhereClause(java.lang.String compareStatment,
java.lang.String columnName)
Add the alias to the column name & append the compare statement. |
java.lang.String |
findColumnName(Persistence p,
java.lang.String path)
Find the aliased column name that matchs the path. |
java.lang.String |
findColumnName(Persistence p,
java.lang.String path,
java.lang.String alias)
Find the aliased column name that matchs the path. |
protected void |
formatForUpdateClause(java.lang.StringBuffer buf)
|
protected void |
formatOrderBy(java.lang.StringBuffer buf)
The point at which the order by portion of the Sql statement is added to our statement. |
protected java.lang.StringBuffer |
formatSelectList(java.lang.StringBuffer buf)
Format the beginning of the select statement. |
protected void |
formatTableList(java.lang.StringBuffer buf)
Format the list of tables that will be participating in this query. |
protected void |
formatWhereClause(java.lang.StringBuffer buf)
Constrain the result set with the where clause elements. |
protected static char |
generateNextAlias()
Create new alias and return it. |
protected char |
genNextAlias()
Create new alias, update this object to know of this new alias, and return the char alias value. |
char |
getAlias()
Alias are used to eliminate problems when the same database column name is found on two tables in a single select statement. |
protected java.lang.String |
getColumnName(java.lang.String tableName,
java.lang.String colName)
Find out what the alias is for the provided table and append it to the 'colName'. |
protected static char |
getNextAlias()
Use the static member 'nextAlias' to keep track of the next available alias. |
protected int |
getRecordSize()
The number of columns that are found by this select statement. |
protected int |
getRowLimit()
The result set is limited to the result of this method. |
java.lang.StringBuffer |
getSqlStatement()
|
java.util.Vector |
getWhereClause()
Get the elements that will make up the where clause. |
protected void |
initializeAttributes(java.lang.String tableName,
boolean exclusiveReadLock)
Initialize the instance variables to their default values. |
void |
insertAnyOfClause(java.lang.String compareWith,
java.lang.String column,
java.util.Vector values)
Special support for dealing with 'any of (values,...)' clauses. |
void |
insertConstraintWhereClause(java.lang.String compareStatement,
java.lang.String columnName)
Very similar to insertWhereClause except the value has already been formatted. |
protected void |
insertTable(java.lang.String tableName,
boolean exclusiveReadLock)
Add a table to our list of tables. |
void |
insertWhereClause(java.lang.String column,
java.lang.Object value)
The default where clause will do an '=' comparison. |
void |
insertWhereClause(java.lang.String compareWith,
java.lang.String column)
|
void |
insertWhereClause(java.lang.String compareWith,
java.lang.String column,
java.lang.Object value)
Add a where clause to the current select statement. |
void |
joinWith(SQLSelect sqlObj,
java.lang.String sourceCol,
java.lang.String withCol,
java.lang.String compareOperator)
Method used to add additional join columns for multiple primary key support. |
void |
joinWith(java.lang.String attribLink,
SQLSelect sqlObj,
java.lang.String sourceCol,
java.lang.String withCol)
Join with another formatted sql statement. |
void |
joinWith(java.lang.String attribLink,
SQLSelect sqlObj,
java.lang.String sourceCol,
java.lang.String withCol,
java.lang.String compareOperator)
Joins the receiver with sqlObj. |
protected static void |
refreshNextAlias()
Update the static member nextAlias to contain the next available table alias. |
void |
setAlias(char c)
Alias' are used to prevent name collisions with columns from multiple tables. |
void |
setAsDelete(boolean value)
Change this query to a delete statement. |
void |
setCount(boolean value)
A state variable that indicates that this select is merely doing a count of matching elements. |
void |
setDistinct(boolean value)
Sets the Distinct attribute of the SQLSelect object |
static void |
setNextAlias(char aValue)
Table aliasing allows for the joining of tables with out worry of column name overlap. |
void |
setOrderBy(boolean value)
A state variable that indicates if there are order by constraints on this select. |
void |
setRowLimit(int limit)
Limit the result set the provided number of rows. |
void |
setTableName(java.lang.String tableName)
A sql select could span multiple tables. |
Methods inherited from class com.objectwave.persist.sqlConstruction.SQLObject |
formatValue, getDefaultFormatter, getObjectFormatter, isAvailableForPool, setAvailableForPool, setObjectFormatter |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static char nextAlias
public java.util.ArrayList columnList
public java.lang.StringBuffer columnListBuffer
Constructor Detail |
public SQLSelect()
public SQLSelect(java.lang.String tableName)
tableName
- The name of the table from which this statement is
selecting data.public SQLSelect(java.lang.String tableName, boolean exclusiveReadLock)
tableName
- The name of the table from which this statement is
selecting data.exclusiveReadLock
- Lock the table using database level locking.Method Detail |
public static void setNextAlias(char aValue)
aValue
- The new NextAlias valueprotected static char getNextAlias()
protected static char generateNextAlias()
protected static void refreshNextAlias()
public void setTableName(java.lang.String tableName)
setTableName
in class SQLObject
tableName
- The new TableName valuepublic void setAsDelete(boolean value)
value
- true would have this statement start with 'delete' instead of
'select'.public void setRowLimit(int limit)
limit
- The number of rows to limit in the result set.public void setAlias(char c)
c
- The new Alias valuegetAlias()
public void setCount(boolean value)
value
- boolean true if we are to find only a count of elements that
would match our constraints.public void setDistinct(boolean value)
value
- The new Distinct valuepublic void setOrderBy(boolean value)
value
- true if this select statement is to include order by
constraints.public char getAlias()
public java.lang.StringBuffer getSqlStatement()
getSqlStatement
in interface SQLAssembler
public java.util.Vector getWhereClause()
protected int getRowLimit()
protected int getRecordSize()
protected java.lang.String getColumnName(java.lang.String tableName, java.lang.String colName)
tableName
- Hopefully the name of one of the tables in the sqlObj.colName
- The column name without any alias.
#findAttributes
public void clean()
clean
in class SQLObject
public void addColumnList(java.lang.String aVal)
aVal
- The feature to be added to the ColumnList attributepublic void addWhereClause(java.lang.String clause)
clause
- String of the clause. Ex. "a.tableField = 'aValue'"public void clearColumnList()
public void addOrderBy(java.util.Vector paths, Persistence source)
source
- Persistence This is usually the persistent object for which
we are queryingpaths
- The feature to be added to the OrderBy attributepublic void insertAnyOfClause(java.lang.String compareWith, java.lang.String column, java.util.Vector values)
column
- The column name. The left hand side of the comparison.values
- java.util.Vector The objects to place in the any of clause.compareWith
- public void insertWhereClause(java.lang.String column, java.lang.Object value)
insertWhereClause
in class SQLObject
column
- The column name. The left hand side of the comparison.value
- The right hand side of the comparison.public void insertWhereClause(java.lang.String compareWith, java.lang.String column, java.lang.Object value)
compareWith
- The comparison operator. Ex. '=', ' <=', etc...column
- The column name. The left hand side of the comparison.value
- The right hand side of the comparison.public void insertWhereClause(java.lang.String compareWith, java.lang.String column)
compareWith
- column
- public final java.lang.StringBuffer createWhereClause(java.lang.String compareStatment, java.lang.String columnName)
compareStatment
- String A string like "!= 9".columnName
- The column name. The left hand side of the comparison.
public void insertConstraintWhereClause(java.lang.String compareStatement, java.lang.String columnName)
columnName
- The column name. The left hand side of the comparison.compareStatement
- public void joinWith(java.lang.String attribLink, SQLSelect sqlObj, java.lang.String sourceCol, java.lang.String withCol)
sqlObj
- Another sql select representing the table to which this is
joining.sourceCol
- A column on this SQLSelect that will join with a column on
the parameter SQLSelect.withCol
- A column on the parameter SQLSelect that will join with a
column on this SQLSelect.attribLink
- public void joinWith(java.lang.String attribLink, SQLSelect sqlObj, java.lang.String sourceCol, java.lang.String withCol, java.lang.String compareOperator)
sqlObj
- Another sql select representing the table to which this is
joining.sourceCol
- A column on this SQLSelect that will join with a column on
the parameter SQLSelect.withCol
- A column on the parameter SQLSelect that will join with a
column on this SQLSelect.attribLink
- compareOperator
- public void joinWith(SQLSelect sqlObj, java.lang.String sourceCol, java.lang.String withCol, java.lang.String compareOperator)
sourceCol
- A column on this SQLSelect that will join with a column on
the parameter SQLSelect.withCol
- A column on the parameter SQLSelect that will join with a
column on this SQLSelect.compareOperator
- sqlObj
- public java.lang.String findColumnName(Persistence p, java.lang.String path)
p
- The source object from which the path statement will begin it's
search.path
-
#findAttributes
public java.lang.String findColumnName(Persistence p, java.lang.String path, java.lang.String alias)
p
- The source object from which the path statement will begin it's
search.path
- alias
-
#findAttributes
protected void initializeAttributes(java.lang.String tableName, boolean exclusiveReadLock)
tableName
- The name of the table on which this select will be
centered.exclusiveReadLock
- protected void addColumnList(java.lang.String[] columns)
columns
- The column names include in the select statement.protected void formatForUpdateClause(java.lang.StringBuffer buf)
buf
- The buffer containing the statment being built.protected void addOrderByImpl(java.lang.String orderByColumn, boolean descend)
orderByColumn
- A database column that is part of the query.descend
- The feature to be added to the OrderByImpl attributeprotected void formatOrderBy(java.lang.StringBuffer buf)
buf
- The buffer containing the statment being built.protected java.lang.StringBuffer formatSelectList(java.lang.StringBuffer buf)
buf
- The buffer containing the statment being built.
protected void formatTableList(java.lang.StringBuffer buf)
buf
- The buffer containing the statment being built.protected void formatWhereClause(java.lang.StringBuffer buf)
buf
- The buffer containing the statment being built.protected char genNextAlias()
protected void insertTable(java.lang.String tableName, boolean exclusiveReadLock)
exclusiveReadLock
- boolean Indicating if the table should be locked.tableName
- String Name of the table.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |