public abstract class DBCommand extends DBCommandExpr implements Cloneable
DBCommandExpr.DBCmdColumn, DBCommandExpr.DBCmdQuery
Modifier and Type | Field and Description |
---|---|
protected boolean |
autoPrepareStmt |
protected DBCmdParamList |
cmdParams |
protected List<DBColumnExpr> |
groupBy |
protected List<DBCompareExpr> |
having |
protected List<DBJoinExpr> |
joins |
protected static org.slf4j.Logger |
log |
protected Set<DBRowSet> |
parentTables |
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_NOPARENTHESIS, CTX_VALUE
Modifier | Constructor and Description |
---|---|
protected |
DBCommand(DBMSHandler dbms,
boolean autoPrepareStmt)
Constructs a new DBCommand object and set the specified DBDatabase object.
|
protected |
DBCommand(DBMSHandler dbms,
boolean autoPrepareStmt,
DBCmdParamList cmdParams)
Constructs a new DBCommand object and set the specified DBDatabase object.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addDeleteForTable(DBSQLBuilder sql,
DBRowSet table) |
protected void |
addDeleteWithJoins(DBSQLBuilder sql,
DBRowSet table) |
protected void |
addFrom(DBSQLBuilder sql) |
protected void |
addGrouping(DBSQLBuilder sql) |
void |
addJoins(List<DBJoinExpr> joinExprList)
Adds a list of join expressions to the command.
|
protected void |
addOrder(DBSQLBuilder sql) |
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(DBSQLBuilder sql) |
protected void |
addUpdateForTable(DBSQLBuilder sql,
DBRowSet table) |
protected void |
addUpdateWithJoins(DBSQLBuilder sql,
DBRowSet table) |
protected void |
addWhere(DBSQLBuilder sql) |
protected void |
addWhere(DBSQLBuilder sql,
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
|
protected DBSQLBuilder |
createSQLBuilder(String initalSQL)
creates a new DBSQLBuilder
|
protected DBCompareExpr |
findConstraintOn(List<DBCompareExpr> list,
DBColumnExpr colExpr)
finds a constraint on a particular column to the 'where' or 'having' collections
|
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.
|
DBCmdParams |
getParams() |
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(DBSQLBuilder sql)
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.
|
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(DBJoinExpr join,
DBJoinType joinType)
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
New in release 3.1: Use left.on(right)) instead
|
DBCommand |
joinLeft(DBColumnExpr left,
DBColumn right,
DBCompareExpr... addlConstraints)
Adds a left join based on two columns to the list of join expressions.
|
DBCommand |
joinLeft(DBJoinExpr join)
Adds a left join 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 |
joinRight(DBJoinExpr join)
Adds a left join to the list of join expressions.
|
DBCommand |
limitRows(int limitRows)
Overridden to change return type from DBCommandExpr to DBCommand
|
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 boolean |
removeConstraint(List<DBCompareExpr> list,
DBCompareExpr cmpExpr)
removes a constraint on a particular column to the 'where' or 'having' collections
|
protected DBCompareExpr |
removeConstraintOn(List<DBCompareExpr> list,
DBColumnExpr colExpr)
removes a constraint on a particular column to the 'where' or 'having' collections
|
boolean |
removeHavingConstraint(DBCompareExpr cmpExpr)
removes a constraint on a particular column from the where clause
|
DBCompareExpr |
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
|
boolean |
removeWhereConstraint(DBCompareExpr cmpExpr)
removes a constraint on a particular column from the where clause
|
DBCompareExpr |
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
|
void |
setParentTables(DBRowSet... rowSets)
Set parent tables for subquery command generation.
|
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, getDbms, getInsertInto, getInsertInto, getInsertInto, getOrderBy, getSelect, hasOrderBy, intersect, result, union, unionAll
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 DBCmdParamList cmdParams
protected DBCommand(DBMSHandler dbms, boolean autoPrepareStmt, DBCmdParamList cmdParams)
dbms
- the database handlerautoPrepareStmt
- flag whether to automatically use literal values as prepared statement paramscmdParams
- the command params listprotected DBCommand(DBMSHandler dbms, boolean autoPrepareStmt)
dbms
- the database handlerautoPrepareStmt
- flag whether to automatically use literal values as prepared statement paramsprotected DBSQLBuilder createSQLBuilder(String initalSQL)
DBCommandExpr
createSQLBuilder
in class DBCommandExpr
public final boolean isAutoPrepareStmt()
public DBCommand clone()
clone
in class DBCommandExpr
public final DBDatabase getDatabase()
DBObject
getDatabase
in class DBObject
public DBCmdParams getParams()
getParams
in class DBCommandExpr
protected void resetParamUsage()
protected void completeParamUsage()
protected void removeCommandParams(DBCompareExpr cmpExpr)
cmpExpr
- the compare expressionprotected void removeAllCommandParams(List<DBCompareExpr> list)
list
- the list of compare expressionspublic void setParentTables(DBRowSet... rowSets)
rowSets
- the parent rowsetspublic 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
expr
- the column exprpublic 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)
columns
- 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
- the expression to replacereplWith
- the expression to replace withpublic 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)
exprs
- the DBSetExpr object(s)public boolean hasSetExpr()
protected boolean hasSetExprOn(DBColumn column)
column
- the column to checktrue
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)
value
- the initial value of the added parampublic final DBCmdParam addParam()
public DBCommand join(DBJoinExpr join)
join
- the join expressionpublic final DBCommand join(DBJoinExpr join, DBJoinType joinType)
join
- the join expressionjoinType
- the type of joinpublic final DBCommand joinLeft(DBJoinExpr join)
join
- the join expressionpublic final DBCommand joinRight(DBJoinExpr join)
join
- the join expressionpublic final DBCommand join(DBColumnExpr left, DBColumn right, DBCompareExpr... addlConstraints)
left
- the left join valueright
- the right joinaddlConstraints
- additional compare expressionspublic final DBCommand joinLeft(DBColumnExpr left, DBColumn right, DBCompareExpr... addlConstraints)
left
- the left join valueright
- the right joinaddlConstraints
- additional compare expressionspublic final DBCommand joinRight(DBColumnExpr left, DBColumn right, DBCompareExpr... addlConstraints)
left
- the left join valueright
- the right joinaddlConstraints
- additional compare expressionspublic 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
)addlConstraints
- additional compare expressionspublic final DBCommand join(DBColumn[] left, DBColumn[] right, DBJoinType joinType, DBCompareExpr... addlConstraints)
left
- the columsn on the leftright
- the columns on the rightjoinType
- the joinTypeaddlConstraints
- additional compare expressionspublic 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)
exprs
- the DBCompareExpr objectpublic boolean hasWhereConstraints()
public List<DBCompareExpr> getWhereConstraints()
public boolean removeWhereConstraint(DBCompareExpr cmpExpr)
cmpExpr
- the compare expression which to removepublic DBCompareExpr 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 boolean removeHavingConstraint(DBCompareExpr cmpExpr)
cmpExpr
- the compare expression which to removepublic DBCompareExpr 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
limitRows
- the number of rows to limitpublic DBCommand skipRows(int skipRows)
skipRows
in class DBCommandExpr
skipRows
- the number of rows to skippublic void clear()
protected boolean isPreparedStatementsEnabled()
protected boolean useCmdParam(DBColumnExpr col, Object value)
col
- the column expressionvalue
- the parameter valueprotected void setConstraint(List<DBCompareExpr> list, DBCompareExpr expr)
list
- the 'where' or 'having' listexpr
- the DBCompareExpr objectprotected boolean removeConstraint(List<DBCompareExpr> list, DBCompareExpr cmpExpr)
list
- the 'where' or 'having' listcmpExpr
- the compare expression which to removeprotected DBCompareExpr removeConstraintOn(List<DBCompareExpr> list, DBColumnExpr colExpr)
list
- the 'where' or 'having' listcolExpr
- the column expression for which to remove the constraintprotected DBCompareExpr findConstraintOn(List<DBCompareExpr> list, DBColumnExpr colExpr)
list
- the 'where' or 'having' listcolExpr
- 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(DBSQLBuilder sql)
getSelect
in class DBCommandExpr
sql
- the sql 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
- the list of compare expressionspublic final String getUpdate()
protected void addUpdateForTable(DBSQLBuilder sql, DBRowSet table)
protected void addUpdateWithJoins(DBSQLBuilder sql, DBRowSet table)
public final String getDelete(DBTable table)
table
- the table objectprotected void addDeleteForTable(DBSQLBuilder sql, DBRowSet table)
protected void addDeleteWithJoins(DBSQLBuilder sql, DBRowSet table)
protected void addSelect(DBSQLBuilder sql)
protected void addFrom(DBSQLBuilder sql)
protected void addWhere(DBSQLBuilder sql, long context)
protected final void addWhere(DBSQLBuilder sql)
protected void addGrouping(DBSQLBuilder sql)
protected void addOrder(DBSQLBuilder sql)
Copyright © 2008–2023 Apache Software Foundation. All rights reserved.