org.apache.empire.db
Class DBCommandExpr

java.lang.Object
  extended by org.apache.empire.db.DBObject
      extended by org.apache.empire.db.DBExpr
          extended by org.apache.empire.db.DBCommandExpr
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
DBCombinedCmd, DBCommand

public abstract class DBCommandExpr
extends DBExpr

This abstract class handles the creation of the SQL-Commands. There are inner classes to construct different SQL-Commands.

See Also:
Serialized Form

Nested Class Summary
protected static class DBCommandExpr.DBCmdColumn
          This class wraps a column of sql command in a special command column object.
protected static class DBCommandExpr.DBCmdQuery
           
 
Field Summary
protected  DBCommandExpr.DBCmdQuery cmdQuery
           
protected  List<DBOrderByExpr> orderBy
           
 
Fields inherited from class org.apache.empire.db.DBExpr
CTX_ALIAS, CTX_ALL, CTX_DEFAULT, CTX_FULLNAME, CTX_NAME, CTX_NOPARENTHESES, CTX_VALUE
 
Constructor Summary
DBCommandExpr()
          Constructs an empty DBCommandExpr object
 
Method Summary
protected  void addListExpr(StringBuilder buf, List<? extends DBExpr> list, long context, String separator)
          Internally used to build a string from a list of database expressions
 void addSQL(StringBuilder buf, long context)
          Creates the SQL-Command.
 void clearLimit()
          Clears a limit or offset set by calling limit() or offset()
 void clearOrderBy()
          Clears the list of order by expressions.
protected  DBColumnExpr getCmdColumn(DBColumnExpr col)
          returns column expression that is specific for to this command and detached from its source.
 String getInsertInto(DBTable table)
          Create the insert into SQL-Command which copies data from a select statement to a destination table.
protected  String getInsertInto(DBTable table, DBColumnExpr[] select, List<DBColumnExpr> columns)
          Create the insert into SQL-Command which copies data from a select statement to a destination table.
 String getInsertInto(DBTable table, List<DBColumnExpr> columns)
          Create the insert into SQL-Command which copies data from a select statement to a destination table.
abstract  Object[] getParamValues()
          returns an array holding all parameter values in the order of their occurrence.
 String getSelect()
          returns an SQL select command for querying records.
abstract  void getSelect(StringBuilder buf)
           
abstract  DBColumnExpr[] getSelectExprList()
           
 DBCommandExpr intersect(DBCommandExpr other)
          Constructs a new DBCombinedCmd object with this object, the key word= "INTERSECT" and the selected DBCommandExpr.
abstract  boolean isValid()
           
 void limitRows(int numRows)
          set the maximum number of rows to return when executing a query command A negative value will remove the limit.
 void orderBy(DBColumnExpr... exprs)
          Adds a list of columns to the orderBy clause in ascending order
 void orderBy(DBColumnExpr expr, boolean desc)
          Adds an order by with ascending or descending order
 void orderBy(DBOrderByExpr... exprs)
          Adds an order by expression the command
 void skipRows(int numRows)
          sets the offset of the first row to return when executing a query command.
 DBCommandExpr union(DBCommandExpr other)
          Constructs a new DBCombinedCmd object with this object, the key word= "UNION" and the selected DBCommandExpr.
 
Methods inherited from class org.apache.empire.db.DBExpr
addReferencedColumns, getObjectValue, getValueClass
 
Methods inherited from class org.apache.empire.db.DBObject
getDatabase
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cmdQuery

protected DBCommandExpr.DBCmdQuery cmdQuery

orderBy

protected List<DBOrderByExpr> orderBy
Constructor Detail

DBCommandExpr

public DBCommandExpr()
Constructs an empty DBCommandExpr object

Method Detail

isValid

public abstract boolean isValid()

getSelect

public abstract void getSelect(StringBuilder buf)

getSelectExprList

public abstract DBColumnExpr[] getSelectExprList()

getParamValues

public abstract Object[] getParamValues()
returns an array holding all parameter values in the order of their occurrence. To ensure the correct order, getSelect() should be called first.

Returns:
an array of command parameter values

getCmdColumn

protected DBColumnExpr getCmdColumn(DBColumnExpr col)
returns column expression that is specific for to this command and detached from its source.


getSelect

public final String getSelect()
returns an SQL select command for querying records.

Returns:
the SQL-Command

addListExpr

protected void addListExpr(StringBuilder buf,
                           List<? extends DBExpr> list,
                           long context,
                           String separator)
Internally used to build a string from a list of database expressions

Parameters:
buf - the sql target buffer
list - list of database objects
context - the sql command context
separator - string to use as separator between list items

addSQL

public void addSQL(StringBuilder buf,
                   long context)
Creates the SQL-Command.

Specified by:
addSQL in class DBExpr
Parameters:
buf - the SQL-Command
context - the current SQL-Command context

union

public DBCommandExpr union(DBCommandExpr other)
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:
DBCombinedCmd

intersect

public DBCommandExpr intersect(DBCommandExpr other)
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

clearOrderBy

public void clearOrderBy()
Clears the list of order by expressions.


orderBy

public void orderBy(DBOrderByExpr... exprs)
Adds an order by expression the command

Parameters:
exprs - vararg of orderBy expressions
See Also:
orderBy(DBColumnExpr, boolean)

limitRows

public void limitRows(int numRows)
set the maximum number of rows to return when executing a query command A negative value will remove the limit.


skipRows

public void skipRows(int numRows)
sets the offset of the first row to return when executing a query command. A negative value will remove the offset.


clearLimit

public void clearLimit()
Clears a limit or offset set by calling limit() or offset()


orderBy

public final void orderBy(DBColumnExpr... exprs)
Adds a list of columns to the orderBy clause in ascending order

Parameters:
exprs - vararg of column expressions

orderBy

public final void orderBy(DBColumnExpr expr,
                          boolean desc)
Adds an order by with ascending or descending order

Parameters:
expr - the DBColumnExpr object
desc - if true, the results from select statement will sort top down

getInsertInto

protected String getInsertInto(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:
the insert into SQL-Command

getInsertInto

public final String getInsertInto(DBTable table,
                                  List<DBColumnExpr> columns)
Create the insert into SQL-Command which copies data from a select statement to a destination table.

Parameters:
table - the table
columns - the columns
Returns:
the insert into SQL-Command

getInsertInto

public final String getInsertInto(DBTable table)
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


Copyright © 2008-2012 Apache Software Foundation. All Rights Reserved.