public abstract class DBCommand extends DBCommandExpr implements Cloneable
DBCommandExpr.DBCmdColumn, DBCommandExpr.DBCmdQuery
Modifier and Type | Field and Description |
---|---|
protected boolean |
autoPrepareStmt |
protected List<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(boolean autoPrepareStmt)
Constructs a new DBCommand object and set the specified DBDatabase object.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addDeleteForTable(StringBuilder buf,
DBRowSet table) |
protected void |
addDeleteWithJoins(StringBuilder buf,
DBRowSet table) |
protected void |
addFrom(StringBuilder buf) |
protected void |
addGrouping(StringBuilder buf) |
protected void |
addJoin(StringBuilder buf,
DBJoinExpr join,
long context,
int whichParams) |
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 |
addUpdateForTable(StringBuilder buf,
DBRowSet table) |
protected void |
addUpdateWithJoins(StringBuilder buf,
DBRowSet table) |
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 |
appendCompareColExprs(DBRowSet table,
DBCompareExpr expr,
List<DBCompareColExpr> list)
Appends all nested DBCompareColExpr for a particular RowSet to a list
|
void |
clear()
Clears the entire command object.
|
void |
clearGroupBy()
Clears the Group By clause
|
void |
clearHaving()
Removes all constraints from the Having clause
|
void |
clearJoin()
Clears the From / Join clause
|
void |
clearSelect()
Clears the list of selected columns.
|
void |
clearSelectDistinct()
Clears the select distinct option.
|
void |
clearSet()
Clears the Set clause
|
void |
clearWhere()
Removes all constraints from the Where clause
|
DBCommand |
clone()
Creates a clone of this class.
|
protected void |
completeParamUsage()
internally used to remove unused Command Params from list
Note: Only one thread my generate an SQL statement
|
DBDatabase |
getDatabase()
Returns the database object to which this object belongs to.
|
DataType |
getDataType()
Returns the DataType selected by this command if only one column is returned
If the command has more than one select expression DataType.UNKNOWN will be returned
|
String |
getDelete(DBTable table)
Creates a delete SQL-Statement
|
List<DBColumnExpr> |
getGroupBy()
Returns a copy of the defined where clauses.
|
List<DBCompareExpr> |
getHavingConstraints()
Returns a copy of the defined having clauses.
|
String |
getInsert()
Creates an insert SQL-Statement
|
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)
Creates a select SQL-Statement
|
List<DBColumnExpr> |
getSelectExpressions()
Returns all select expressions as unmodifiable list
|
DBColumnExpr[] |
getSelectExprList()
Returns an array of all select expressions
|
List<DBSetExpr> |
getSetExpressions()
Returns all set expressions as unmodifiable list
|
String |
getUpdate()
Creates an update SQL-Statement
|
List<DBCompareExpr> |
getWhereConstraints()
Returns a copy of the defined where clauses.
|
DBCommand |
groupAll()
Adds all select expressions which are not aggregates to the Group By clause
|
DBCommand |
groupBy(Collection<? extends DBColumnExpr> columns)
Adds a collection of columns to the Group By clause of an sql statement.
|
DBCommand |
groupBy(DBColumnExpr... exprs)
Adds a list of columns to the Group By clause of an sql statement.
|
DBCommand |
groupBy(DBColumnExpr columnExpr)
Adds a column expression to the Group By clause of an sql statement.
|
boolean |
hasAggegation()
Checks whether or not there are any aggregate functions in the Select
|
boolean |
hasConstraintOn(DBRowSet rowset)
Returns true if the command has a constraint on the given table or false otherwise.
|
protected boolean |
hasConstraintOn(List<DBCompareExpr> list,
DBColumnExpr colExpr)
removes a constraint on a particular column to the 'where' or 'having' collections
|
boolean |
hasGroupBy()
Returns whether or not the command has group by set
|
boolean |
hasHavingConstraintOn(DBColumnExpr col)
Checks whether the command has a constraint on a particular column expression
|
boolean |
hasHavingConstraints()
Returns true if the command has having-constraints or false if not.
|
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()
returns whether or not the command has any select expression
|
boolean |
hasSelectExpr(DBColumnExpr expr)
returns whether or not the command has a specific select expression
|
boolean |
hasSetExpr()
Returns whether or not the command has group by set
|
protected boolean |
hasSetExprOn(DBColumn column)
Checks whether a column is in the list of set expressions
|
boolean |
hasWhereConstraintOn(DBColumnExpr col)
Checks whether the command has a constraint on a particular column expression
|
boolean |
hasWhereConstraints()
Returns true if the command has constraints or false if not.
|
DBCommand |
having(DBCompareExpr expr)
adds a constraint to the having clause.
|
boolean |
isAutoPrepareStmt() |
protected boolean |
isPreparedStatementsEnabled()
returns true if prepared statements are enabled for this command
|
boolean |
isSelectDistinct()
Returns whether or not the select statement will be distinct or not.
|
boolean |
isValid()
Returns true if the this command has either Select or Set expressions
|
DBCommand |
join(DBColumn[] left,
DBColumn[] right,
DBJoinType joinType,
DBCompareExpr... addlConstraints)
Multi-Column version of column based join expression
|
DBCommand |
join(DBColumnExpr left,
DBColumn right,
DBCompareExpr... addlConstraints)
Adds an inner join based on two columns to the list of join expressions.
|
DBCommand |
join(DBColumnExpr left,
DBColumn right,
DBJoinType joinType,
DBCompareExpr... addlConstraints)
Adds a join based on two columns to the list of join expressions.
|
DBCommand |
join(DBJoinExpr join)
Adds a join to the list of join expressions.
|
DBCommand |
join(DBRowSet rowset,
DBCompareExpr cmp)
Adds an inner join based on a compare expression to the command.
|
DBCommand |
join(DBRowSet rowset,
DBCompareExpr cmp,
DBJoinType joinType)
Adds a join based on a compare expression to the command.
|
DBCommand |
join(DBRowSet left,
DBRowSet right)
Adds a cross join for two tables or views
|
DBCommand |
joinLeft(DBColumnExpr left,
DBColumn right,
DBCompareExpr... addlConstraints)
Adds a left join based on two columns to the list of join expressions.
|
DBCommand |
joinRight(DBColumnExpr left,
DBColumn right,
DBCompareExpr... addlConstraints)
Adds a right join based on two columns to the list of join expressions.
|
DBCommand |
limitRows(int limitRows)
Overridden to change return type from DBCommandExpr to DBCommand
|
protected void |
mergeSubqueryParams(Object[] subQueryParams) |
protected void |
notifyParamUsage(DBCmdParam param)
internally used to reorder the command params to match their order of occurance
|
DBCommand |
orderBy(DBColumnExpr... exprs)
Overridden to change return type from DBCommandExpr to DBCommand
|
DBCommand |
orderBy(DBColumnExpr expr,
boolean desc)
Overridden to change return type from DBCommandExpr to DBCommand
|
DBCommand |
orderBy(DBOrderByExpr... exprs)
Overridden to change return type from DBCommandExpr to DBCommand
|
DBCommand |
qualifyAll()
Makes sure all selected columns are identified by their proper names (qualified)
|
protected void |
removeAllCommandParams(List<DBCompareExpr> list)
internally used to remove all command params used in a list of constraints
|
protected void |
removeCommandParams(DBCompareExpr cmpExpr)
internally used to remove the command param used in a constraint
|
protected void |
removeConstraint(List<DBCompareExpr> list,
DBCompareExpr cmpExpr)
removes a constraint on a particular column to the 'where' or 'having' collections
|
protected void |
removeConstraintOn(List<DBCompareExpr> list,
DBColumnExpr colExpr)
removes a constraint on a particular column to the 'where' or 'having' collections
|
void |
removeHavingConstraint(DBCompareExpr cmpExpr)
removes a constraint on a particular column from the where clause
|
void |
removeHavingConstraintOn(DBColumnExpr col)
removes a constraint on a particular column from the having 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 |
removeSelect(DBColumnExpr... exprs)
removes one or more expressions from the Select expression list
|
void |
removeWhereConstraint(DBCompareExpr cmpExpr)
removes a constraint on a particular column from the where clause
|
void |
removeWhereConstraintOn(DBColumnExpr col)
removes a constraint on a particular column from the where clause
|
void |
replaceSelect(DBColumnExpr replExpr,
DBColumnExpr replWith)
replaces a select expression with another or removes a select expression
In order to remove the expression, set the replWith parameter to null
If the replace expression is not found, an ItemNotFoundException is thrown
|
protected void |
resetParamUsage()
internally used to reset the command param usage count.
|
DBCommand |
select(Collection<? extends DBColumnExpr> columns)
Adds a collection of columns to the select phrase of an sql statement.
|
DBCommand |
select(DBColumnExpr... exprs)
Adds a list of columns to the select phrase of an sql statement.
|
DBCommand |
select(DBColumnExpr expr)
Adds a DBColumnExpr object to the Select collection
|
DBCommand |
selectDistinct()
Sets whether or not the select statement should contain
the distinct directive .
|
DBCommand |
selectQualified(Collection<? extends DBColumnExpr> columns)
Adds a collection of columns to the select phrase of an sql statement.
|
DBCommand |
selectQualified(DBColumnExpr... columns)
Adds a list of columns with their qualified name to the select phrase of an sql statement.
|
DBCommand |
set(DBSetExpr... exprs)
Adds a list of set expressions to this command
Use column.to(...) to create a set expression
|
DBCommand |
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
|
DBCommand |
skipRows(int skipRows)
Overridden to change return type from DBCommandExpr to DBCommand
|
protected boolean |
useCmdParam(DBColumnExpr col,
Object value)
returns true if a cmdParam should be used for the given column or false otherwise
|
DBCommand |
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.
|
DBCommand |
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, getOrderBy, getSelect, hasOrderBy, intersect, result, union, unionAll
getObjectValue
checkParamNull
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 boolean autoPrepareStmt
protected List<DBCmdParam> cmdParams
protected DBCommand(boolean autoPrepareStmt)
db
- the current database objectpublic final boolean isAutoPrepareStmt()
public DBCommand clone()
clone
in class DBCommandExpr
public final DBDatabase getDatabase()
DBObject
getDatabase
in class DBObject
protected void resetParamUsage()
protected void completeParamUsage()
protected void notifyParamUsage(DBCmdParam param)
protected void removeCommandParams(DBCompareExpr cmpExpr)
protected void removeAllCommandParams(List<DBCompareExpr> list)
public boolean isValid()
isValid
in class DBCommandExpr
public DBCommand selectDistinct()
public boolean isSelectDistinct()
public boolean hasSelectExpr()
hasSelectExpr
in class DBCommandExpr
public boolean hasSelectExpr(DBColumnExpr expr)
hasSelectExpr
in class DBCommandExpr
public DataType getDataType()
DBCommandExpr
getDataType
in class DBCommandExpr
public DBCommand select(DBColumnExpr expr)
expr
- the DBColumnExpr objectpublic final DBCommand select(DBColumnExpr... exprs)
exprs
- an vararg of DBColumnExpr's to selectpublic final DBCommand select(Collection<? extends DBColumnExpr> columns)
columns
- the column expressions to addpublic DBCommand selectQualified(DBColumnExpr... columns)
exprs
- one or more columns to selectpublic final DBCommand selectQualified(Collection<? extends DBColumnExpr> columns)
columns
- the column expressions to addpublic DBCommand qualifyAll()
public DBColumnExpr[] getSelectExprList()
getSelectExprList
in class DBCommandExpr
null
if there is nothing to selectpublic List<DBColumnExpr> getSelectExpressions()
getSelectExpressions
in class DBCommandExpr
public void replaceSelect(DBColumnExpr replExpr, DBColumnExpr replWith)
replExpr
- replWith
- public void removeSelect(DBColumnExpr... exprs)
exprs
- the expression(s) to be removedpublic boolean hasAggegation()
public DBCommand set(DBSetExpr expr)
expr
- the DBSetExpr object(s)public final DBCommand set(DBSetExpr... exprs)
expr
- the DBSetExpr object(s)public boolean hasSetExpr()
protected boolean hasSetExprOn(DBColumn column)
column
- true
if there is a set expressionpublic List<DBSetExpr> getSetExpressions()
public 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 DBCommand join(DBJoinExpr join)
join
- the join expressionpublic final DBCommand join(DBColumnExpr left, DBColumn right, DBCompareExpr... addlConstraints)
left
- the left join valueright
- the right joinpublic final DBCommand joinLeft(DBColumnExpr left, DBColumn right, DBCompareExpr... addlConstraints)
left
- the left join valueright
- the right joinpublic final DBCommand joinRight(DBColumnExpr left, DBColumn right, DBCompareExpr... addlConstraints)
left
- the left join valueright
- the right joinpublic final DBCommand join(DBColumnExpr left, DBColumn right, DBJoinType joinType, DBCompareExpr... addlConstraints)
left
- the left join valueright
- the right joinjoinType
- type of join (DBJoinType.INNER
, DBJoinType.LEFT
, DBJoinType.RIGHT
)public final DBCommand join(DBColumn[] left, DBColumn[] right, DBJoinType joinType, DBCompareExpr... addlConstraints)
left
- the columsn on the leftright
- the columns on the rightjoinType
- the joinTypeaddlConstraints
- addlConstraintspublic final DBCommand join(DBRowSet left, DBRowSet right)
left
- the left RowSetright
- the right RowSetpublic final DBCommand join(DBRowSet rowset, DBCompareExpr cmp, DBJoinType joinType)
rowset
- table or view to joincmp
- the compare expression with which to join the tablejoinType
- type of join (DBJoinType.INNER
, DBJoinType.LEFT
, DBJoinType.RIGHT
)public final DBCommand 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 DBCommand where(DBCompareExpr expr)
expr
- the DBCompareExpr objectpublic final DBCommand where(DBCompareExpr... exprs)
expr
- the DBCompareExpr objectpublic boolean hasWhereConstraints()
public List<DBCompareExpr> getWhereConstraints()
public void removeWhereConstraint(DBCompareExpr cmpExpr)
col
- the column expression for which to remove the constraintpublic void removeWhereConstraintOn(DBColumnExpr col)
col
- the column expression for which to remove the constraintpublic boolean hasWhereConstraintOn(DBColumnExpr col)
col
- the column expression which to checkpublic List<DBJoinExpr> getJoins()
public void addWhereConstraints(List<DBCompareExpr> constraints)
constraints
- list of constraintspublic DBCommand having(DBCompareExpr expr)
expr
- the DBCompareExpr objectpublic boolean hasHavingConstraints()
public List<DBCompareExpr> getHavingConstraints()
public void removeHavingConstraint(DBCompareExpr cmpExpr)
col
- the column expression for which to remove the constraintpublic void removeHavingConstraintOn(DBColumnExpr col)
col
- the column expression for which to remove the constraintpublic boolean hasHavingConstraintOn(DBColumnExpr col)
col
- the column expression which to checkpublic boolean hasGroupBy()
public List<DBColumnExpr> getGroupBy()
public DBCommand groupBy(DBColumnExpr columnExpr)
columnExpr
- the column expressionpublic final DBCommand groupBy(DBColumnExpr... exprs)
exprs
- vararg of columns by which to group the rowspublic final DBCommand groupBy(Collection<? extends DBColumnExpr> columns)
columns
- the column expressions to addpublic final DBCommand groupAll()
public void clearSelectDistinct()
public void clearSelect()
public void clearSet()
public void clearJoin()
public void clearWhere()
public void clearHaving()
public void clearGroupBy()
public DBCommand orderBy(DBOrderByExpr... exprs)
orderBy
in class DBCommandExpr
exprs
- vararg of orderBy expressionsDBCommandExpr.orderBy(DBColumnExpr, boolean)
public DBCommand orderBy(DBColumnExpr... exprs)
orderBy
in class DBCommandExpr
exprs
- vararg of column expressionspublic DBCommand orderBy(DBColumnExpr expr, boolean desc)
orderBy
in class DBCommandExpr
expr
- the DBColumnExpr objectdesc
- if true, the results from select statement will sort top downpublic DBCommand limitRows(int limitRows)
limitRows
in class DBCommandExpr
public DBCommand skipRows(int skipRows)
skipRows
in class DBCommandExpr
public void clear()
protected boolean isPreparedStatementsEnabled()
protected boolean useCmdParam(DBColumnExpr col, Object value)
protected void setConstraint(List<DBCompareExpr> list, DBCompareExpr expr)
list
- the 'where' or 'having' listexpr
- the DBCompareExpr objectprotected void removeConstraint(List<DBCompareExpr> list, DBCompareExpr cmpExpr)
list
- the 'where' or 'having' listcol
- the column expression for which to remove the constraintprotected boolean hasConstraintOn(List<DBCompareExpr> list, DBColumnExpr colExpr)
list
- the 'where' or 'having' listcol
- the column expression for which to remove the constraintprotected void removeConstraintOn(List<DBCompareExpr> list, DBColumnExpr colExpr)
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 void getSelect(StringBuilder buf)
getSelect
in class DBCommandExpr
buf
- the string builder to add the command topublic String getInsert()
protected void appendCompareColExprs(DBRowSet table, DBCompareExpr expr, List<DBCompareColExpr> list)
table
- the rowset for which to collect the DBCompareColExprexpr
- a compare expressionlist
- public final String getUpdate()
protected void addUpdateForTable(StringBuilder buf, DBRowSet table)
protected void addUpdateWithJoins(StringBuilder buf, DBRowSet table)
public final String getDelete(DBTable table)
table
- the table objectprotected void addDeleteForTable(StringBuilder buf, DBRowSet table)
protected void addDeleteWithJoins(StringBuilder buf, DBRowSet table)
protected void addSelect(StringBuilder buf)
protected void addFrom(StringBuilder buf)
protected void addJoin(StringBuilder buf, DBJoinExpr join, long context, int whichParams)
protected void mergeSubqueryParams(Object[] subQueryParams)
protected void addWhere(StringBuilder buf, long context)
protected final void addWhere(StringBuilder buf)
protected void addGrouping(StringBuilder buf)
protected void addOrder(StringBuilder buf)
Copyright © 2008–2022 Apache Software Foundation. All rights reserved.