Package org.apache.empire.db
Class DBCommandExpr
java.lang.Object
org.apache.empire.db.DBObject
org.apache.empire.db.DBExpr
org.apache.empire.db.DBCommandExpr
- Direct Known Subclasses:
DBCombinedCmd,DBCommand
This abstract class handles the creation of the SQL-Commands.
There are inner classes to construct different SQL-Commands.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classThis class wraps a column of sql command in a special command column object.protected static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DBCommandExpr.DBCmdQueryprotected List<DBOrderByExpr>static final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intFields inherited from class org.apache.empire.db.DBExpr
CTX_ALIAS, CTX_ALL, CTX_DEFAULT, CTX_FULLNAME, CTX_NAME, CTX_NOPARENTHESIS, CTX_VALUE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddListExpr(DBSQLBuilder sql, List<? extends DBExpr> list, long context, String separator) Internally used to build a string from a list of database expressionsvoidaddSQL(DBSQLBuilder sql, long context) Creates the SQL-Command.voidClears a limit or offset set by calling limit() or offset()voidClears the list of order by expressions.clone()Creates a clone of this class.protected DBSQLBuildercreateSQLBuilder(String initalSQL) creates a new DBSQLBuilderprotected DBColumnExprgetCmdColumn(DBColumnExpr col) wraps a column expression such that is specific for to this command and detached from its source.abstract DataTypeReturns 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 returnedfinal DBMSHandlergetDbms()returns the DBMSHandler this command belongs tofinal StringgetInsertInto(DBTable table) Create the insert into SQL-Command which copies data from a select statement to a destination table.final StringgetInsertInto(DBTable table, List<DBColumnExpr> columns) Create the insert into SQL-Command which copies data from a select statement to a destination table.protected StringgetInsertInto(DBTable table, DBColumnExpr[] select, List<DBColumnExpr> columns) Create the insert into SQL-Command which copies data from a select statement to a destination table.Returns a copy of the defined order-bys.abstract DBCmdParamsabstract Object[]returns an array holding all parameter values in the order of their occurrence.final Stringreturns an SQL select command for querying records.final StringgetSelect(int flags) returns an SQL select command for querying records.abstract voidgetSelect(DBSQLBuilder sql, int flags) returns an SQL select commandabstract List<DBColumnExpr>returns a list of expressions for the SELECT part of the sql statementabstract DBColumnExpr[]Returns the list of all select expressions as an array Used internally onlybooleanReturns whether or not the command has order by setabstract booleanreturns whether or not the command has any select expressionabstract booleanhasSelectExpr(DBColumnExpr expr) returns whether or not the command has a specific select expressionintersect(DBCommandExpr other) Constructs a new DBCombinedCmd object with this object, the key word= "INTERSECT" and the selected DBCommandExpr.abstract booleanisValid()limitRows(int numRows) set the maximum number of rows to return when executing a query command A negative value will remove the limit.protected final booleannot(int flags, int flag) Checks if a flag is NOT setprotected final booleannotEmpty(Collection<?> list) Checks if a collection is not null or emptyorderBy(DBColumnExpr... exprs) Adds a list of columns to the orderBy clause in ascending orderorderBy(DBColumnExpr expr, boolean desc) Adds an order by with ascending or descending orderorderBy(DBOrderByExpr... exprs) Adds an order by expression the commandorderByUpper(DBColumnExpr... exprs) Adds a list of columns to the orderBy clause in ascending orderorderByUpper(DBColumnExpr expr, boolean desc) Adds a case insensitive order by with ascending or descending orderresult()Returns a ColumnExpr for the result of the query If the command must have exactly one select column otherwise a NotSupportedException is thrown;skipRows(int numRows) sets the offset of the first row to return when executing a query command.union(DBCommandExpr other) Constructs a new DBCombinedCmd object with this object, the key word= "UNION" and the selected DBCommandExpr.unionAll(DBCommandExpr other) Constructs a new DBCombinedCmd object with this object, the key word= "UNION ALL" and the selected DBCommandExpr.Methods inherited from class org.apache.empire.db.DBExpr
addReferencedColumnsMethods inherited from class org.apache.empire.db.DBObject
checkParamNull, getDatabase
-
Field Details
-
SF_DEFAULT
public static final int SF_DEFAULT- See Also:
-
SF_SKIP_SELECT
public static final int SF_SKIP_SELECT- See Also:
-
SF_SKIP_FROM
public static final int SF_SKIP_FROM- See Also:
-
SF_SKIP_WHERE
public static final int SF_SKIP_WHERE- See Also:
-
SF_SKIP_GROUP
public static final int SF_SKIP_GROUP- See Also:
-
SF_SKIP_ORDER
public static final int SF_SKIP_ORDER- See Also:
-
SF_SKIP_LIMIT
public static final int SF_SKIP_LIMIT- See Also:
-
cmdQuery
-
orderBy
-
-
Constructor Details
-
DBCommandExpr
Constructs an empty DBCommandExpr object- Parameters:
dbms- the database handler
-
-
Method Details
-
not
protected final boolean not(int flags, int flag) Checks if a flag is NOT set- Parameters:
flags- the flagsflag- the flag to check in flags- Returns:
- true if the bit provided in flag is not set in flags or false otherwise
-
notEmpty
Checks if a collection is not null or empty- Parameters:
list- the collection to check- Returns:
- true if the collection is not empty or false if empty
-
getDbms
returns the DBMSHandler this command belongs to- Returns:
- the DBMSHandler
-
clone
Creates a clone of this class. -
isValid
public abstract boolean isValid() -
hasSelectExpr
public abstract boolean hasSelectExpr()returns whether or not the command has any select expression- Returns:
- true if the command has any select expression of false otherwise
-
hasSelectExpr
returns whether or not the command has a specific select expression- Parameters:
expr- the column expr- Returns:
- true if the command contains the given select expression of false otherwise
-
getSelectExprList
Returns the list of all select expressions as an array Used internally only- Returns:
- the select expression array
-
getSelectExpressions
returns a list of expressions for the SELECT part of the sql statement- Returns:
- the select expression list
-
getSelect
returns an SQL select command- Parameters:
sql- the sql builder to add the command toflags- bitwise context flags for sql building (see "Select Context Flags")
-
getSelect
returns an SQL select command for querying records.- Parameters:
flags- bitwise context flags for sql building (see "Select Context Flags")- Returns:
- the SQL-Command
-
getSelect
returns an SQL select command for querying records.- Returns:
- the SQL-Command
-
getParams
-
getParamValues
returns an array holding all parameter values in the order of their occurrence. To ensure the correct order, getSelect() must be called first.- Returns:
- an array of command parameter values
-
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- Returns:
- the DataType of the selected expression or DataType.UNKNOWN
-
result
Returns a ColumnExpr for the result of the query If the command must have exactly one select column otherwise a NotSupportedException is thrown;- Returns:
- the result expression
-
addSQL
Creates the SQL-Command. -
union
Constructs a new DBCombinedCmd object with this object, the key word= "UNION" and the selected DBCommandExpr.- Parameters:
other- the second DBCommandExpr- Returns:
- the new DBCombinedCmd object
- See Also:
-
unionAll
Constructs a new DBCombinedCmd object with this object, the key word= "UNION ALL" and the selected DBCommandExpr.- Parameters:
other- the second DBCommandExpr- Returns:
- the new DBCombinedCmd object
- See Also:
-
intersect
Constructs a new DBCombinedCmd object with this object, the key word= "INTERSECT" and the selected DBCommandExpr.- Parameters:
other- the second DBCommandExpr- Returns:
- the new DBCombinedCmd object
-
hasOrderBy
public boolean hasOrderBy()Returns whether or not the command has order by set- Returns:
- flag whether an order by is provided
-
getOrderBy
Returns a copy of the defined order-bys.- Returns:
- list of order-bys
-
clearOrderBy
public void clearOrderBy()Clears the list of order by expressions. -
orderBy
Adds an order by expression the command- Parameters:
exprs- vararg of orderBy expressions- Returns:
- itself (this)
- See Also:
-
orderBy
Adds an order by with ascending or descending order- Parameters:
expr- the expression for orderingdesc- if true, the results from select statement will sort top down- Returns:
- itself (this)
-
orderBy
Adds a list of columns to the orderBy clause in ascending order- Parameters:
exprs- vararg of order by expressions- Returns:
- itself (this)
-
orderByUpper
Adds a case insensitive order by with ascending or descending order- Parameters:
expr- the expression for orderingdesc- if true, the results from select statement will sort top down- Returns:
- itself (this)
-
orderByUpper
Adds a list of columns to the orderBy clause in ascending order- Parameters:
exprs- vararg of order by expressions- Returns:
- itself (this)
-
limitRows
set the maximum number of rows to return when executing a query command A negative value will remove the limit.- Parameters:
numRows- the number of rows to limit- Returns:
- itself (this)
-
skipRows
sets the offset of the first row to return when executing a query command. A negative value will remove the offset.- Parameters:
numRows- the number of rows to skip- Returns:
- itself (this)
-
clearLimit
public void clearLimit()Clears a limit or offset set by calling limit() or offset() -
getInsertInto
Create the insert into SQL-Command which copies data from a select statement to a destination table.- Parameters:
table- the tablecolumns- the columns- Returns:
- the insert into SQL-Command
-
getInsertInto
Create the insert into SQL-Command which copies data from a select statement to a destination table.- Parameters:
table- the table- Returns:
- the insert into SQL-Command
-
createSQLBuilder
creates a new DBSQLBuilder- Parameters:
initalSQL- the initial sql fragment- Returns:
- the new DBSQLBuilder
-
getCmdColumn
wraps a column expression such that is specific for to this command and detached from its source.- Parameters:
col- the column expression to wrap- Returns:
- column expression that is specific for to this command
-
addListExpr
protected void addListExpr(DBSQLBuilder sql, List<? extends DBExpr> list, long context, String separator) Internally used to build a string from a list of database expressions- Parameters:
sql- the sql target bufferlist- the list of expressions to add to the sqlcontext- the sql command contextseparator- string to use as separator between list items
-
getInsertInto
Create the insert into SQL-Command which copies data from a select statement to a destination table.- Parameters:
table- the table to insertselect- the selected columnscolumns- the list of column expressions- Returns:
- the insert into SQL-Command
-