org.apache.empire.db
Class DBCommandExpr

java.lang.Object
  extended by org.apache.empire.commons.ErrorObject
      extended by org.apache.empire.db.DBObject
          extended by org.apache.empire.db.DBExpr
              extended by org.apache.empire.db.DBCommandExpr
All Implemented Interfaces:
ErrorInfo
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.


Nested Class Summary
protected static class DBCommandExpr.DBCmdColumn
          This class wrapps a column of sql command in a special command column object.
protected static class DBCommandExpr.DBCmdQuery
           
protected static class DBCommandExpr.DBOrderByInfo
           
 
Nested classes/interfaces inherited from class org.apache.empire.commons.ErrorObject
ErrorObject.ObjectErrorInfo
 
Field Summary
protected  DBCommandExpr.DBCmdQuery cmdQuery
           
protected  java.util.List<DBCommandExpr.DBOrderByInfo> orderBy
           
 
Fields inherited from class org.apache.empire.db.DBExpr
CTX_ALIAS, CTX_ALL, CTX_DEFAULT, CTX_FULLNAME, CTX_NAME, CTX_NOPARENTHESES, CTX_VALUE, log
 
Constructor Summary
DBCommandExpr()
          Constructs an empty DBCommandExpr object
 
Method Summary
protected  void addListExpr(java.lang.StringBuilder buf, java.util.List<? extends DBExpr> list, long context, java.lang.String separator)
          Internally used to build a string from a list of database expressions
 void addSQL(java.lang.StringBuilder buf, long context)
          Creates the SQL-Command.
 void clearOrderBy()
          Clears the list of order by expressions.
 DBColumnExpr getCmdColumn(DBColumnExpr col)
           
 DBColumnExpr getCmdColumn(int i)
           
 java.lang.String getInsertInto(DBTable table)
          Create the insert into SQL-Command which copies data from a select statement to a destination table.
protected  java.lang.String getInsertInto(DBTable table, DBColumnExpr[] select, java.util.List<DBColumnExpr> columns)
          Create the insert into SQL-Command which copies data from a select statement to a destination table.
 java.lang.String getInsertInto(DBTable table, java.util.List<DBColumnExpr> columns)
          Create the insert into SQL-Command which copies data from a select statement to a destination table.
 java.lang.String getSelect()
          returns an SQL select command for querying records.
abstract  boolean getSelect(java.lang.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 orderBy(DBColumnExpr expr)
          Adds an order by with ascending order
 void orderBy(DBColumnExpr expr, boolean desc)
          Adds an order by with ascending or descending order
 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
error, error, getDatabase
 
Methods inherited from class org.apache.empire.commons.ErrorObject
clearError, clearErrorInfo, error, error, error, error, error, error, error, getErrorInfo, getErrorMessage, getErrorParams, getErrorSource, getErrorType, getMessage, hasError, internalSetError, isExceptionsEnabled, setExceptionsEnabled, success
 
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 java.util.List<DBCommandExpr.DBOrderByInfo> orderBy
Constructor Detail

DBCommandExpr

public DBCommandExpr()
Constructs an empty DBCommandExpr object

Method Detail

isValid

public abstract boolean isValid()

getSelect

public abstract boolean getSelect(java.lang.StringBuilder buf)

getSelectExprList

public abstract DBColumnExpr[] getSelectExprList()

getCmdColumn

public DBColumnExpr getCmdColumn(DBColumnExpr col)

getCmdColumn

public DBColumnExpr getCmdColumn(int i)

getSelect

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

Returns:
the SQL-Command

addListExpr

protected void addListExpr(java.lang.StringBuilder buf,
                           java.util.List<? extends DBExpr> list,
                           long context,
                           java.lang.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(java.lang.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 secend 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 secend DBCommandExpr
Returns:
the new DBCombinedCmd object

clearOrderBy

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


orderBy

public 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

orderBy

public void orderBy(DBColumnExpr expr)
Adds an order by with ascending order

Parameters:
expr - the column
See Also:
orderBy(DBColumnExpr, boolean)

getInsertInto

protected java.lang.String getInsertInto(DBTable table,
                                         DBColumnExpr[] select,
                                         java.util.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 java.lang.String getInsertInto(DBTable table,
                                            java.util.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 java.lang.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-2009 Apache Software Foundation. All Rights Reserved.