org.apache.empire.db.expr.column
Class DBCaseExpr

java.lang.Object
  extended by org.apache.empire.db.DBObject
      extended by org.apache.empire.db.DBExpr
          extended by org.apache.empire.db.DBColumnExpr
              extended by org.apache.empire.db.expr.column.DBCaseExpr
All Implemented Interfaces:
Serializable, ColumnExpr

public class DBCaseExpr
extends DBColumnExpr

This class is used to add the "case when ?=A then X else Y end" statement to the SQL-Command.

There is no need to explicitly create instances of this class.
Instead use DBColumnExpr.when(DBCompareExpr, Object)

Author:
doebele
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.empire.db.DBColumnExpr
attributes, beanPropertyName, DBCOLATTR_TITLE, DBCOLATTR_TYPE, options
 
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
DBCaseExpr(DBCompareExpr compExpr, DBColumnExpr trueExpr, DBColumnExpr elseExpr)
          Constructs a DBCaseExpr
 
Method Summary
 void addReferencedColumns(Set<DBColumn> list)
          Internal function to obtain all DBColumnExpr-objects used by this expression.
 void addSQL(StringBuilder sql, long context)
          Used to build the SQL command.
 Element addXml(Element parent, long flags)
          Add a description of this column with relevant metadata to the supplied parent XML Element.
 DBDatabase getDatabase()
          Returns the database object to which this object belongs to.
 DataType getDataType()
          Returns the data type of this column expression.
 String getName()
          Returns the column name for this column expression.
 DBColumn getUpdateColumn()
          Returns the underlying physical column which may be used for updates.
 boolean isAggregate()
          Indicates wheter this function is an aggregate (sum, min, max, avg, ...) or not
 
Methods inherited from class org.apache.empire.db.DBColumnExpr
abs, append, as, as, asc, avg, cmp, coalesce, convertTo, convertTo, count, countDistinct, day, decode, decode, decode, decode, decode, decode, desc, detectDataType, divideBy, getAttribute, getBeanPropertyName, getControlType, getExprFromPhrase, getExprFromPhrase, getOptions, getSourceColumn, getTitle, in, indexOf, indexOf, indexOf, is, isBetween, isGreaterThan, isLessOrEqual, isMoreOrEqual, isNot, isNotBetween, isSmallerThan, length, like, like, likeLower, likeUpper, lower, max, min, minus, minus, month, multiplyWith, notIn, notLike, nvl, parenthesis, plus, plus, replace, reverse, round, setAttribute, setBeanPropertyName, setControlType, setOptions, setTitle, substring, substring, substring, substring, substring, substring, sum, toChar, toChar, trim, trimLeft, trimRight, trunc, upper, when, year
 
Methods inherited from class org.apache.empire.db.DBExpr
getObjectValue, getValueClass
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBCaseExpr

public DBCaseExpr(DBCompareExpr compExpr,
                  DBColumnExpr trueExpr,
                  DBColumnExpr elseExpr)
Constructs a DBCaseExpr

Parameters:
compExpr - the condition to be evaluated
trueExpr - the expression returned if the condition is true
elseExpr - the expression returned if the condition is false (may be null)
Method Detail

getDatabase

public DBDatabase getDatabase()
Description copied from class: DBObject
Returns the database object to which this object belongs to. For the database object itself this function will return the this pointer.

Specified by:
getDatabase in class DBObject
Returns:
the database object

getDataType

public DataType getDataType()
Description copied from class: DBColumnExpr
Returns the data type of this column expression.

Specified by:
getDataType in interface ColumnExpr
Specified by:
getDataType in class DBColumnExpr
Returns:
the expressions data type
See Also:
DataType

getName

public String getName()
Description copied from class: DBColumnExpr
Returns the column name for this column expression. The name must contain only alphanumeric characters and the underscore. For SQL functions this name may be generated. However subsequent calls to this function for the same object instance must return the same string.

Specified by:
getName in interface ColumnExpr
Specified by:
getName in class DBColumnExpr
Returns:
the column name

getUpdateColumn

public DBColumn getUpdateColumn()
Description copied from class: DBColumnExpr
Returns the underlying physical column which may be used for updates. For functions involving none or more than one physical column this function returns null.

Specified by:
getUpdateColumn in class DBColumnExpr
Returns:
the column to be used for updates if any.

isAggregate

public boolean isAggregate()
Description copied from class: DBColumnExpr
Indicates wheter this function is an aggregate (sum, min, max, avg, ...) or not

Specified by:
isAggregate in class DBColumnExpr
Returns:
true if the column expression represents an aggregate

addReferencedColumns

public void addReferencedColumns(Set<DBColumn> list)
Description copied from class: DBExpr
Internal function to obtain all DBColumnExpr-objects used by this expression.

Specified by:
addReferencedColumns in class DBExpr
Parameters:
list - list to which all used column expressions must be added

addSQL

public void addSQL(StringBuilder sql,
                   long context)
Description copied from class: DBExpr
Used to build the SQL command. SQL for this expression must be appended to StringBuilder.

Specified by:
addSQL in class DBExpr
Parameters:
sql - the string buffer used to build the sql command
context - context flag for this SQL-Command (see CTX_??? constants).

addXml

public Element addXml(Element parent,
                      long flags)
Description copied from class: DBColumnExpr
Add a description of this column with relevant metadata to the supplied parent XML Element.

Specified by:
addXml in class DBColumnExpr
Parameters:
parent - the parent element to which to append the column description
flags - currently not used
Returns:
the newly created child element


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