com.healthmarketscience.sqlbuilder
Class SimpleCaseStatement

java.lang.Object
  extended by com.healthmarketscience.common.util.AppendeeObject
      extended by com.healthmarketscience.sqlbuilder.SqlObject
          extended by com.healthmarketscience.sqlbuilder.Expression
              extended by com.healthmarketscience.sqlbuilder.BaseCaseStatement<SimpleCaseStatement>
                  extended by com.healthmarketscience.sqlbuilder.SimpleCaseStatement
All Implemented Interfaces:
Appendee, Verifiable<SimpleCaseStatement>

public class SimpleCaseStatement
extends BaseCaseStatement<SimpleCaseStatement>

Outputs a simple case statement like: "CASE <column1> WHEN <val1> THEN <result1> [ WHEN <val2> THEN <result2> WHEN ... ] [ELSE <resultN>] END" (where the values are numeric/string values).

Author:
James Ahlborn

Field Summary
 
Fields inherited from class com.healthmarketscience.sqlbuilder.Expression
EMPTY
 
Fields inherited from class com.healthmarketscience.sqlbuilder.SqlObject
ALL_SYMBOL, NULL_VALUE, QUESTION_MARK
 
Constructor Summary
SimpleCaseStatement(Column column)
           
SimpleCaseStatement(Object operand)
          Object -> SqlObject conversions handled by Converter.toColumnSqlObject(Object).
 
Method Summary
 SimpleCaseStatement addNumericWhen(Object value, Object result)
          Adds a "WHEN" clause to the "CASE" statement.
 SimpleCaseStatement addWhen(String value, Object result)
          Adds a "WHEN" clause to the "CASE" statement.
protected  void appendCustomIfNotNull(AppendableExt app, SqlObject obj)
          Appends the given custom clause to the given AppendableExt, handling null and enclosing parens.
protected  void appendNestedClauses(AppendableExt app, SqlObjectList<? extends com.healthmarketscience.sqlbuilder.NestableClause> nestedClauses)
          Appends the given nested clauses to the given AppendableExt, handling empty nested clauses and enclosing parens.
protected static boolean areEmpty(SqlObjectList<? extends com.healthmarketscience.sqlbuilder.NestableClause> nestedClauses)
          Determines if any of the given clauses are non-empty.
protected  void closeParen(AppendableExt app)
          Appends a close parenthesis to the given AppendableExt if disableParens is true, otherwise does nothing.
 boolean hasParens()
          Returns true iff the output of this instance would include surrounding parentheses, false otherwise.
protected static boolean hasParens(SqlObjectList<? extends com.healthmarketscience.sqlbuilder.NestableClause> nestedClauses)
          Determines if any of the given clauses are non-empty.
 boolean isDisableParens()
          Returns whether or not wrapping parentheses are disabled for this clause (for clauses which utilize wrapping parentheses).
protected  void openParen(AppendableExt app)
          Appends an open parenthesis to the given AppendableExt if disableParens is true, otherwise does nothing.
 
Methods inherited from class com.healthmarketscience.sqlbuilder.BaseCaseStatement
addCustomWhen, addElse, addElseNull, appendTo, collectSchemaObjects, getThisType, isEmpty, validate, validate
 
Methods inherited from class com.healthmarketscience.sqlbuilder.Expression
setDisableParens
 
Methods inherited from class com.healthmarketscience.sqlbuilder.SqlObject
doValidate, toString
 
Methods inherited from class com.healthmarketscience.common.util.AppendeeObject
toString, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleCaseStatement

public SimpleCaseStatement(Column column)
Parameters:
column - the column to reference at the beginning of the "CASE" statement

SimpleCaseStatement

public SimpleCaseStatement(Object operand)
Object -> SqlObject conversions handled by Converter.toColumnSqlObject(Object).

Parameters:
operand - the custom column to reference at the beginning of the "CASE" statement
Method Detail

addNumericWhen

public SimpleCaseStatement addNumericWhen(Object value,
                                          Object result)
Adds a "WHEN" clause to the "CASE" statement.

Value Object -> SqlObject conversions handled by Converter.toValueSqlObject(Object). Result Object -> SqlObject conversions handled by Converter.toColumnSqlObject(Object).

Parameters:
value - the value to test against the column of this "CASE" statement
result - the result to output if this "WHEN" clause is selected

addWhen

public SimpleCaseStatement addWhen(String value,
                                   Object result)
Adds a "WHEN" clause to the "CASE" statement.

Result Object -> SqlObject conversions handled by Converter.toColumnSqlObject(Object).

Parameters:
value - the value to test against the column of this "CASE" statement
result - the result to output if this "WHEN" clause is selected

isDisableParens

public boolean isDisableParens()
Returns whether or not wrapping parentheses are disabled for this clause (for clauses which utilize wrapping parentheses). Defaults to false.


hasParens

public boolean hasParens()
Returns true iff the output of this instance would include surrounding parentheses, false otherwise.

Default implementation returns !isEmpty() && !isDisableParens().


areEmpty

protected static boolean areEmpty(SqlObjectList<? extends com.healthmarketscience.sqlbuilder.NestableClause> nestedClauses)
Determines if any of the given clauses are non-empty.

Returns:
false if at least one clause is non-empty, true otherwise

hasParens

protected static boolean hasParens(SqlObjectList<? extends com.healthmarketscience.sqlbuilder.NestableClause> nestedClauses)
Determines if any of the given clauses are non-empty.

Returns:
false if at least one clause is non-empty, true otherwise

openParen

protected void openParen(AppendableExt app)
                  throws IOException
Appends an open parenthesis to the given AppendableExt if disableParens is true, otherwise does nothing.

Throws:
IOException

closeParen

protected void closeParen(AppendableExt app)
                   throws IOException
Appends a close parenthesis to the given AppendableExt if disableParens is true, otherwise does nothing.

Throws:
IOException

appendCustomIfNotNull

protected void appendCustomIfNotNull(AppendableExt app,
                                     SqlObject obj)
                              throws IOException
Appends the given custom clause to the given AppendableExt, handling null and enclosing parens.

Throws:
IOException

appendNestedClauses

protected void appendNestedClauses(AppendableExt app,
                                   SqlObjectList<? extends com.healthmarketscience.sqlbuilder.NestableClause> nestedClauses)
                            throws IOException
Appends the given nested clauses to the given AppendableExt, handling empty nested clauses and enclosing parens.

Throws:
IOException


Copyright © 2006-2012 Health Market Science. All Rights Reserved.