public abstract class DBCommand extends DBCommandExpr implements Cloneable
DBCommandExpr.DBCmdColumn, DBCommandExpr.DBCmdQuery
Modifier and Type | Field and Description |
---|---|
protected Vector<DBCmdParam> |
cmdParams |
protected List<DBColumnExpr> |
groupBy |
protected List<DBCompareExpr> |
having |
protected List<DBJoinExpr> |
joins |
protected static org.slf4j.Logger |
log |
protected List<DBColumnExpr> |
select |
protected boolean |
selectDistinct |
protected List<DBSetExpr> |
set |
protected List<DBCompareExpr> |
where |
cmdQuery, orderBy
CTX_ALIAS, CTX_ALL, CTX_DEFAULT, CTX_FULLNAME, CTX_NAME, CTX_NOPARENTHESES, CTX_VALUE
Modifier | Constructor and Description |
---|---|
protected |
DBCommand(DBDatabase db)
Constructs a new DBCommand object and set the specified DBDatabase object.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addFrom(StringBuilder buf) |
protected void |
addGrouping(StringBuilder buf) |
void |
addJoins(List<DBJoinExpr> joinExprList)
Adds a list of join expressions to the command.
|
protected void |
addOrder(StringBuilder buf) |
DBCmdParam |
addParam()
Adds an command parameter which will be used in a prepared statement.
|
DBCmdParam |
addParam(DataType type,
Object value)
Adds an command parameter which will be used in a prepared statement.
|
DBCmdParam |
addParam(DBColumnExpr colExpr,
Object value)
Adds an command parameter which will be used in a prepared statement.
|
DBCmdParam |
addParam(Object value)
Adds an command parameter which will be used in a prepared statement.
|
void |
addReferencedColumns(Set<DBColumn> list)
Adds Columns
|
protected void |
addSelect(StringBuilder buf) |
protected void |
addWhere(StringBuilder buf) |
protected void |
addWhere(StringBuilder buf,
long context) |
void |
addWhereConstraints(List<DBCompareExpr> constraints)
Adds a list of constraints to the command.
|
protected void |
checkDatabase(DBExpr expr) |
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.
|
DBDatabase |
getDatabase()
Returns the current DBDatabase object.
|
String |
getDelete(DBTable table)
Creates the delete SQL-Command.
|
String |
getInsert()
Creates the insert SQL-Command.
|
List<DBJoinExpr> |
getJoins()
Returns a copy of the defined joins.
|
Object[] |
getParamValues()
Returns an array of parameter values for a prepared statement.
|
protected List<DBRowSet> |
getRowSetList()
Gets a list of all tables referenced by the query.
|
void |
getSelect(StringBuilder buf) |
DBColumnExpr[] |
getSelectExprList()
Returns a array of all select DBColumnExpr for this command
|
String |
getUpdate()
Creates the update SQL-Command.
|
List<DBCompareExpr> |
getWhereConstraints()
Returns a copy of the defined where clauses.
|
void |
groupBy(Collection<? extends DBColumnExpr> columns)
Adds a collection of columns to the group by phrase of an sql statement.
|
void |
groupBy(DBColumnExpr... exprs)
Adds a list of columns to the group by phrase of an sql statement.
|
boolean |
hasConstraintOn(DBRowSet rowset)
Returns true if the command has a constraint on the given table or false otherwise.
|
boolean |
hasJoinOn(DBColumn column)
Returns true if the command has a join on the given column or false otherwise.
|
boolean |
hasJoinOn(DBRowSet rowset)
Returns true if the command has a join on the given table or false otherwise.
|
boolean |
hasSelectExpr() |
protected boolean |
hasSetExprOn(DBColumn column)
Checks whether a column is in the list of set expressions
|
boolean |
hasWhereConstraints()
Returns true if the command has constraints or false if not.
|
void |
having(DBCompareExpr expr)
adds a constraint to the having clause.
|
protected boolean |
isPreparedStatementsEnabled()
returns true if prepared statements are enabled for this database
|
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.
|
DBColumnJoinExpr |
join(DBColumnExpr left,
DBColumn right)
Adds an inner join based on two columns to the list of join expressions.
|
DBColumnJoinExpr |
join(DBColumnExpr left,
DBColumnExpr 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.
|
DBCompareJoinExpr |
join(DBRowSet rowset,
DBCompareExpr cmp)
Adds an inner join based on a compare expression to the command.
|
DBCompareJoinExpr |
join(DBRowSet rowset,
DBCompareExpr cmp,
DBJoinType joinType)
Adds a join based on a compare expression to the command.
|
DBCrossJoinExpr |
join(DBRowSet left,
DBRowSet right)
Adds a cross join for two tables or views
|
protected void |
notifyParamUsage(DBCmdParam param)
internally used to reorder the command params to match their order of occurance
|
protected void |
removeConstraintOn(List<DBCompareExpr> list,
DBColumnExpr col)
removes a constraint on a particular column to the 'where' or 'having' collections
|
void |
removeHavingConstraintOn(DBColumnExpr col)
removes a constraint on a particular column from the where clause
|
boolean |
removeJoinsOn(DBColumn column)
removes all joins to a given column
|
boolean |
removeJoinsOn(DBRowSet rowset)
removes all joins to a given table or view
|
void |
removeWhereConstraintOn(DBColumnExpr col)
removes a constraint on a particular column from the where clause
|
protected void |
resetParamUsage()
internally used to reset the command param usage count.
|
void |
select(Collection<? extends DBColumnExpr> columns)
Adds a collection of columns to the select phrase of an sql statement.
|
void |
select(DBColumnExpr... exprs)
Adds a list of columns to the select phrase of an sql statement.
|
void |
select(DBColumnExpr expr)
Adds a DBColumnExpr object to the Vector: 'select'.
|
void |
selectDistinct()
Sets whether or not the select statement should contain
the distinct directive .
|
void |
selectQualified(Collection<? extends DBColumn> columns)
Adds a collection of columns to the select phrase of an sql statement.
|
void |
selectQualified(DBColumn... columns)
Adds a list of columns with their qualified name to the select phrase of an sql statement.
|
void |
set(DBSetExpr... exprs)
Adds a list of set expressions to this command
Use column.to(...) to create a set expression
|
void |
set(DBSetExpr expr)
Adds a single set expressions to this command
Use column.to(...) to create a set expression
|
protected void |
setConstraint(List<DBCompareExpr> list,
DBCompareExpr expr)
adds a constraint to the 'where' or 'having' collections
|
protected boolean |
useCmdParam(DBColumn col,
Object value)
returns true if a cmdParam should be used for the given column or false otherwise
|
void |
where(DBCompareExpr... exprs)
Adds a list of constraints to the where phrase of the sql statement
If another restriction already exists for the same column it will be replaced.
|
void |
where(DBCompareExpr expr)
Adds a constraint to the where phrase of the sql statement
If another restriction already exists for the same column it will be replaced.
|
addListExpr, addSQL, clearLimit, clearOrderBy, getCmdColumn, getInsertInto, getInsertInto, getInsertInto, getSelect, intersect, limitRows, orderBy, orderBy, orderBy, skipRows, union, unionAll
getObjectValue, getValueClass
protected static final org.slf4j.Logger log
protected boolean selectDistinct
protected List<DBColumnExpr> select
protected List<DBJoinExpr> joins
protected List<DBCompareExpr> where
protected List<DBCompareExpr> having
protected List<DBColumnExpr> groupBy
protected Vector<DBCmdParam> cmdParams
protected DBCommand(DBDatabase db)
db
- the current database objectprotected void resetParamUsage()
protected void notifyParamUsage(DBCmdParam param)
public DBDatabase getDatabase()
getDatabase
in class DBObject
public boolean isValid()
isValid
in class DBCommandExpr
public boolean isValidQuery()
public boolean isValidUpdate()
public void selectDistinct()
public boolean isSelectDistinct()
public void select(DBColumnExpr expr)
expr
- the DBColumnExpr objectpublic final void select(DBColumnExpr... exprs)
exprs
- an vararg of DBColumnExpr's to selectpublic final void select(Collection<? extends DBColumnExpr> columns)
columns
- the column expressions to addpublic void selectQualified(DBColumn... columns)
exprs
- one or more columns to selectpublic final void selectQualified(Collection<? extends DBColumn> columns)
columns
- the column expressions to addprotected boolean isPreparedStatementsEnabled()
protected boolean useCmdParam(DBColumn col, Object value)
public void set(DBSetExpr expr)
expr
- the DBSetExpr object(s)public final void set(DBSetExpr... exprs)
expr
- the DBSetExpr object(s)protected boolean hasSetExprOn(DBColumn column)
column
- true
if there is a set expressionpublic DBCmdParam addParam(DataType type, Object value)
type
- the data type of the parametervalue
- the initial parameter valuepublic final DBCmdParam addParam(DBColumnExpr colExpr, Object value)
colExpr
- the column expression for which to create the parametervalue
- the initial parameter valuepublic final DBCmdParam addParam(Object value)
public final DBCmdParam addParam()
public void join(DBJoinExpr join)
join
- the join expressionpublic final DBCrossJoinExpr join(DBRowSet left, DBRowSet right)
left
- the left RowSetright
- the right RowSetpublic final DBColumnJoinExpr join(DBColumnExpr left, DBColumnExpr right, DBJoinType joinType)
left
- the left join valueright
- the right joinjoinType
- type of join (DBJoinType.INNER
, DBJoinType.LEFT
, DBJoinType.RIGHT
)public final DBColumnJoinExpr join(DBColumnExpr left, DBColumn right)
left
- the left join valueright
- the right joinpublic final DBCompareJoinExpr join(DBRowSet rowset, DBCompareExpr cmp, DBJoinType joinType)
rowset
- table or view to joincmp
- the compare expression with wich to join the tablejoinType
- type of join (DBJoinType.INNER
, DBJoinType.LEFT
, DBJoinType.RIGHT
)public final DBCompareJoinExpr join(DBRowSet rowset, DBCompareExpr cmp)
rowset
- table of view which to joincmp
- the compare expression with wich to join the tablepublic void addJoins(List<DBJoinExpr> joinExprList)
joinExprList
- list of join expressionspublic boolean hasJoinOn(DBRowSet rowset)
rowset
- rowset table or view to joinpublic boolean hasConstraintOn(DBRowSet rowset)
rowset
- rowset table or view to joinpublic boolean hasJoinOn(DBColumn column)
column
- the column to testpublic boolean removeJoinsOn(DBRowSet rowset)
rowset
- the table or view for which to remove all joinspublic boolean removeJoinsOn(DBColumn column)
column
- the column for which to remove all joinspublic void where(DBCompareExpr expr)
expr
- the DBCompareExpr objectpublic final void where(DBCompareExpr... exprs)
expr
- the DBCompareExpr objectpublic boolean hasWhereConstraints()
public List<DBCompareExpr> getWhereConstraints()
public void removeWhereConstraintOn(DBColumnExpr col)
col
- the column expression for which to remove the constraintpublic List<DBJoinExpr> getJoins()
public void addWhereConstraints(List<DBCompareExpr> constraints)
constraints
- list of constraintspublic void having(DBCompareExpr expr)
expr
- the DBCompareExpr objectpublic void removeHavingConstraintOn(DBColumnExpr col)
col
- the column expression for which to remove the constraintpublic void groupBy(DBColumnExpr... exprs)
exprs
- vararg of columns by which to group the rowspublic final void groupBy(Collection<? extends DBColumnExpr> columns)
columns
- the column expressions to addpublic boolean hasSelectExpr()
public void getSelect(StringBuilder buf)
getSelect
in class DBCommandExpr
public DBColumnExpr[] getSelectExprList()
getSelectExprList
in class DBCommandExpr
null
if there are no selectspublic void clearSelectDistinct()
public void clearSelect()
public void clearSet()
public void clearJoin()
public void clearWhere()
public void clearHaving()
public void clearGroupBy()
public void clear()
protected void setConstraint(List<DBCompareExpr> list, DBCompareExpr expr)
list
- the 'where' or 'having' listexpr
- the DBCompareExpr objectprotected void removeConstraintOn(List<DBCompareExpr> list, DBColumnExpr col)
list
- the 'where' or 'having' listcol
- the column expression for which to remove the constraintprotected List<DBRowSet> getRowSetList()
public void addReferencedColumns(Set<DBColumn> list)
addReferencedColumns
in class DBExpr
list
- list to which all used column expressions must be addedpublic Object[] getParamValues()
getParamValues
in class DBCommandExpr
public String getUpdate()
public String getInsert()
public String getDelete(DBTable table)
table
- the table objectprotected void addSelect(StringBuilder buf)
protected void addFrom(StringBuilder buf)
protected void addWhere(StringBuilder buf, long context)
protected final void addWhere(StringBuilder buf)
protected void addGrouping(StringBuilder buf)
protected void addOrder(StringBuilder buf)
protected void checkDatabase(DBExpr expr)
Copyright © 2008–2018 Apache Software Foundation. All rights reserved.