org.apache.empire.db
Class DBCommand

java.lang.Object
  extended by org.apache.empire.commons.ErrorObject
      extended by org.apache.empire.db.DBObject
          extended by org.apache.empire.db.DBExpr
              extended by org.apache.empire.db.DBCommandExpr
                  extended by org.apache.empire.db.DBCommand
All Implemented Interfaces:
java.lang.Cloneable, ErrorInfo
Direct Known Subclasses:
DBCommandOracle, DBDatabaseDriverHSql.DBCommandHSql, DBDatabaseDriverMSSQL.DBCommandMSSQL, DBDatabaseDriverMySQL.DBCommandMySQL

public abstract class DBCommand
extends DBCommandExpr
implements java.lang.Cloneable

This abstract class handles the creation of the SQL-Commands. There are methods to create SQL-Commandos, like update, insert, delete and select.


Nested Class Summary
static class DBCommand.DBCmdParameter
           
 
Field Summary
 
Fields inherited from class org.apache.empire.db.DBExpr
CTX_ALIAS, CTX_ALL, CTX_DEFAULT, CTX_FULLNAME, CTX_NAME, CTX_NOPARENTHESES, CTX_VALUE
 
Method Summary
 DBCommand.DBCmdParameter addCmdParam(java.lang.Object item)
          Adds an object to in the list of Parameters and returns a parameter object.
 void addJoins(java.util.List<DBJoinExpr> joinExprList)
          Adds a list of join expressions to the command.
 void addReferencedColumns(java.util.Set<DBColumn> list)
          Adds Columns
 void addWhereConstraints(java.util.List<DBCompareExpr> constraints)
          Adds a list of constraints to the command.
 void clear()
          Clears the entire command object.
 void clearGroupBy()
          Clears the list of group by constraints.
 void clearHaving()
          Clears the list of having constraints.
 void clearJoin()
          Clears the list of join expressions.
 void clearSelect()
          Clears the list of selected columns.
 void clearSelectDistinct()
          Clears the select distinct option.
 void clearSet()
          Clears the list of set expressions.
 void clearWhere()
          Clears the list of where constraints.
 DBCommand clone()
          Creates a clone of this class.
 java.lang.Object[] getCmdParams()
          Returns the list of parameter values for a prepared statement.
 DBDatabase getDatabase()
          Returns the current DBDatabase object.
 java.lang.String getDelete(DBTable table)
          Creates the delete SQL-Command.
 java.lang.String getInsert()
          Creates the insert SQL-Command.
 java.util.List<DBJoinExpr> getJoins()
          Returns a copy of the defined joins.
 boolean getSelect(java.lang.StringBuilder buf)
           
 DBColumnExpr[] getSelectExprList()
          Returns a array of all DBColumnExpr object of the Vector: 'select'.
 java.lang.String getUpdate()
          Creates the update SQL-Command.
 java.util.List<DBCompareExpr> getWhereConstraints()
          Returns a copy of the defined where clauses.
 void groupBy(DBColumnExpr expr)
          Adds a column to the group by phrase of an sql statement.
 void groupBy(DBColumnExpr[] exprList)
          Adds a list columns to the group by phrase of an sql statement.
 void groupBy(DBColumnExpr expr1, DBColumnExpr expr2)
          Adds two columns to the group by phrase of an sql statement.
 void groupBy(DBColumnExpr expr1, DBColumnExpr expr2, DBColumnExpr expr3)
          Adds three columns to the group by phrase of an sql statement.
 boolean hasJoinOn(DBRowSet rowset)
          Returns true if the command has a join on the given table or false otherwise.
 boolean hasSelectExpr()
          Returns true if the command has constaints or false if not.
 boolean hasWhereConstraints()
          Returns true if the command has constaints or false if not.
 void having(DBCompareExpr expr)
          Sets a having contraint.
 boolean isSelectDistinct()
          Returns whether or not the select statement will be distinct or not.
 boolean isValid()
           
 boolean isValidQuery()
          Returns whether the command object can produce a select sql-statement.
 boolean isValidUpdate()
          Returns whether the command object can produce a update sql-statement.
 DBJoinExpr join(DBColumnExpr left, DBColumn right)
          Adds an inner join based on two columns to the list of join expressions.
 DBJoinExpr join(DBColumnExpr left, DBColumn right, DBJoinType joinType)
          Adds a join based on two columns to the list of join expressions.
 void join(DBJoinExpr join)
          Adds a join to the list of join expressions.
 DBJoinExpr join(DBRowSet rowset, DBCompareExpr cmp)
          Adds an inner join based on a compare expression to the command.
 DBJoinExpr join(DBRowSet rowset, DBCompareExpr cmp, DBJoinType joinType)
          Adds a join based on a compare expression to the command.
 void select(java.util.Collection<DBColumnExpr> columns)
          Adds a list of column expression to the select clause
 void select(DBColumnExpr expr)
          Adds a DBColumnExpr object to the Vector: 'select'.
 void select(DBColumnExpr[] exprList)
          This helper function adds an array of DBColumnExpr objects to list of select-columns.
 void select(DBColumnExpr expr1, DBColumnExpr expr2)
          This helper function adds two DBColumnExpr objects to the Vector: 'select'
 void select(DBColumnExpr expr1, DBColumnExpr expr2, DBColumnExpr expr3)
          This helper function adds three DBColumnExpr objects to the Vector: 'select'.
 void select(DBColumnExpr expr1, DBColumnExpr expr2, DBColumnExpr expr3, DBColumnExpr expr4)
          This helper function adds four DBColumnExpr objects to the Vector: 'select'.
 void select(DBColumnExpr expr1, DBColumnExpr expr2, DBColumnExpr expr3, DBColumnExpr expr4, DBColumnExpr expr5)
          This helper function adds five DBColumnExpr objects to the Vector: 'select'.
 void select(java.util.List<DBColumn> columns)
          Adds a list of column expression to the select clause
 void selectDistinct()
          Sets whether or not the select statement should contain the distinct directive .
 void set(DBSetExpr expr)
          Inserts DBSetExpr objects to the Vector 'set'.
 boolean setCmdParam(int index, java.lang.Object item)
          Sets a object to in the list of Parameters.
 void where(DBCompareExpr expr)
          Adds a compare expression to the list of constraints.
 
Methods inherited from class org.apache.empire.db.DBCommandExpr
addSQL, clearOrderBy, getCmdColumn, getCmdColumn, getInsertInto, getInsertInto, getSelect, intersect, orderBy, orderBy, union
 
Methods inherited from class org.apache.empire.db.DBExpr
getValueClass
 
Methods inherited from class org.apache.empire.commons.ErrorObject
clearError, getErrorMessage, getErrorParams, getErrorSource, getErrorType, getMessage, hasError, isExceptionsEnabled, setExceptionsEnabled
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

clone

public DBCommand clone()
Creates a clone of this class.

Overrides:
clone in class java.lang.Object

getDatabase

public DBDatabase getDatabase()
Returns the current DBDatabase object.

Specified by:
getDatabase in class DBObject
Returns:
the current DBDatabase object

isValid

public boolean isValid()
Specified by:
isValid in class DBCommandExpr

isValidQuery

public boolean isValidQuery()
Returns whether the command object can produce a select sql-statement.

Returns:
true if at least one select expression has been set

isValidUpdate

public boolean isValidUpdate()
Returns whether the command object can produce a update sql-statement.

Returns:
true if a set expression has been set.

selectDistinct

public void selectDistinct()
Sets whether or not the select statement should contain the distinct directive .


isSelectDistinct

public boolean isSelectDistinct()
Returns whether or not the select statement will be distinct or not.

Returns:
true if the select will contain the distinct directive or false otherwise.

select

public void select(DBColumnExpr expr)
Adds a DBColumnExpr object to the Vector: 'select'.

Parameters:
expr - the DBColumnExpr object

select

public void select(DBColumnExpr expr1,
                   DBColumnExpr expr2)
This helper function adds two DBColumnExpr objects to the Vector: 'select'

Parameters:
expr1 - the first DBColumnExpr object
expr2 - the second DBColumnExpr object

select

public void select(DBColumnExpr expr1,
                   DBColumnExpr expr2,
                   DBColumnExpr expr3)
This helper function adds three DBColumnExpr objects to the Vector: 'select'.


select

public void select(DBColumnExpr expr1,
                   DBColumnExpr expr2,
                   DBColumnExpr expr3,
                   DBColumnExpr expr4)
This helper function adds four DBColumnExpr objects to the Vector: 'select'.


select

public void select(DBColumnExpr expr1,
                   DBColumnExpr expr2,
                   DBColumnExpr expr3,
                   DBColumnExpr expr4,
                   DBColumnExpr expr5)
This helper function adds five DBColumnExpr objects to the Vector: 'select'.


select

public void select(DBColumnExpr[] exprList)
This helper function adds an array of DBColumnExpr objects to list of select-columns.


select

public void select(java.util.Collection<DBColumnExpr> columns)
Adds a list of column expression to the select clause


select

public void select(java.util.List<DBColumn> columns)
Adds a list of column expression to the select clause


set

public void set(DBSetExpr expr)
Inserts DBSetExpr objects to the Vector 'set'.

Parameters:
expr - the DBSetExpr object(s)

setCmdParam

public boolean setCmdParam(int index,
                           java.lang.Object item)
Sets a object to in the list of Parameters.


addCmdParam

public DBCommand.DBCmdParameter addCmdParam(java.lang.Object item)
Adds an object to in the list of Parameters and returns a parameter object.


join

public void join(DBJoinExpr join)
Adds a join to the list of join expressions.

Parameters:
join - the join expression

join

public DBJoinExpr join(DBColumnExpr left,
                       DBColumn right,
                       DBJoinType joinType)
Adds a join based on two columns to the list of join expressions.

Parameters:
left - the left join value
right - the right join
joinType - type of join (INNER, LEFT, RIGHT)

join

public DBJoinExpr join(DBColumnExpr left,
                       DBColumn right)
Adds an inner join based on two columns to the list of join expressions.

Parameters:
left - the left join value
right - the right join

join

public DBJoinExpr join(DBRowSet rowset,
                       DBCompareExpr cmp,
                       DBJoinType joinType)
Adds a join based on a compare expression to the command.

Parameters:
rowset - table of view which to join
cmp - the compare expression with wich to join the table
joinType - type of join (INNER, LEFT, RIGHT)

join

public DBJoinExpr join(DBRowSet rowset,
                       DBCompareExpr cmp)
Adds an inner join based on a compare expression to the command.

Parameters:
rowset - table of view which to join
cmp - the compare expression with wich to join the table

addJoins

public void addJoins(java.util.List<DBJoinExpr> joinExprList)
Adds a list of join expressions to the command.

Parameters:
joinExprList - list of join expressions

hasJoinOn

public boolean hasJoinOn(DBRowSet rowset)
Returns true if the command has a join on the given table or false otherwise.

Returns:
true if the command has a join on the given table or false otherwise

where

public void where(DBCompareExpr expr)
Adds a compare expression to the list of constraints. If another restriction already exists for the same column it will be replaced.

Parameters:
expr - the DBCompareExpr object

hasWhereConstraints

public boolean hasWhereConstraints()
Returns true if the command has constaints or false if not.

Returns:
true if constraints have been set on the command

getWhereConstraints

public java.util.List<DBCompareExpr> getWhereConstraints()
Returns a copy of the defined where clauses.

Returns:
vector of where clauses

getJoins

public java.util.List<DBJoinExpr> getJoins()
Returns a copy of the defined joins.

Returns:
vector of joins

addWhereConstraints

public void addWhereConstraints(java.util.List<DBCompareExpr> constraints)
Adds a list of constraints to the command.

Parameters:
constraints - list of constraints

having

public void having(DBCompareExpr expr)
Sets a having contraint.

Parameters:
expr - the DBCompareExpr object

groupBy

public void groupBy(DBColumnExpr[] exprList)
Adds a list columns to the group by phrase of an sql statement.

Parameters:
exprList - array of columns by which to group the rows

groupBy

public void groupBy(DBColumnExpr expr)
Adds a column to the group by phrase of an sql statement.

Parameters:
expr - the DBCompareExpr object

groupBy

public void groupBy(DBColumnExpr expr1,
                    DBColumnExpr expr2)
Adds two columns to the group by phrase of an sql statement.


groupBy

public void groupBy(DBColumnExpr expr1,
                    DBColumnExpr expr2,
                    DBColumnExpr expr3)
Adds three columns to the group by phrase of an sql statement.


hasSelectExpr

public boolean hasSelectExpr()
Returns true if the command has constaints or false if not.

Returns:
true if constraints have been set on the command

getSelect

public boolean getSelect(java.lang.StringBuilder buf)
Specified by:
getSelect in class DBCommandExpr

getSelectExprList

public DBColumnExpr[] getSelectExprList()
Returns a array of all DBColumnExpr object of the Vector: 'select'.

Specified by:
getSelectExprList in class DBCommandExpr
Returns:
a array of all DBColumnExpr object of the Vector: 'select'

clearSelectDistinct

public void clearSelectDistinct()
Clears the select distinct option.


clearSelect

public void clearSelect()
Clears the list of selected columns.


clearSet

public void clearSet()
Clears the list of set expressions.


clearJoin

public void clearJoin()
Clears the list of join expressions.


clearWhere

public void clearWhere()
Clears the list of where constraints.


clearHaving

public void clearHaving()
Clears the list of having constraints.


clearGroupBy

public void clearGroupBy()
Clears the list of group by constraints.


clear

public void clear()
Clears the entire command object.


addReferencedColumns

public void addReferencedColumns(java.util.Set<DBColumn> list)
Adds Columns

Specified by:
addReferencedColumns in class DBExpr
Parameters:
list - list to which all used column expressions must be added

getCmdParams

public java.lang.Object[] getCmdParams()
Returns the list of parameter values for a prepared statement.

Returns:
the list of parameter values for a prepared statement

getUpdate

public java.lang.String getUpdate()
Creates the update SQL-Command.

Returns:
the update SQL-Command

getInsert

public java.lang.String getInsert()
Creates the insert SQL-Command.

Returns:
the insert SQL-Command

getDelete

public java.lang.String getDelete(DBTable table)
Creates the delete SQL-Command.

Returns:
the delete SQL-Command