com.healthmarketscience.sqlbuilder
Class JdbcEscape

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.JdbcEscape
All Implemented Interfaces:
Appendee
Direct Known Subclasses:
JdbcScalarFunction

public class JdbcEscape
extends Expression

Outputs SQL and a prefix enclosed within JDBC escape syntax "{<prefix> <sql>}".

Author:
James Ahlborn

Nested Class Summary
static class JdbcEscape.Type
          Enum which defines the escape types supported.
 
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
JdbcEscape(JdbcEscape.Type type, SqlObject val)
           
 
Method Summary
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.
 void appendTo(AppendableExt app)
           
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.
protected  void collectSchemaObjects(ValidationContext vContext)
          Used during Query.validate() calls to collect the dbschema objects referenced in a query.
static JdbcEscape date(Date d)
           
 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).
 boolean isEmpty()
          Returns true iff the output of this instance would be an empty expression, false otherwise.
protected  void openParen(AppendableExt app)
          Appends an open parenthesis to the given AppendableExt if disableParens is true, otherwise does nothing.
static JdbcEscape time(Date d)
           
static JdbcEscape timestamp(Date d)
           
 
Methods inherited from class com.healthmarketscience.sqlbuilder.Expression
setDisableParens
 
Methods inherited from class com.healthmarketscience.sqlbuilder.SqlObject
collectSchemaObjects, 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

JdbcEscape

public JdbcEscape(JdbcEscape.Type type,
                  SqlObject val)
Method Detail

hasParens

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

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


collectSchemaObjects

protected void collectSchemaObjects(ValidationContext vContext)
Description copied from class: SqlObject
Used during Query.validate() calls to collect the dbschema objects referenced in a query. Any subclass of this class should add all referenced tables and columns to the appropriate collections.

Specified by:
collectSchemaObjects in class SqlObject
Parameters:
vContext - handle to the current validation context

appendTo

public void appendTo(AppendableExt app)
              throws IOException
Specified by:
appendTo in interface Appendee
Overrides:
appendTo in class AppendeeObject
Throws:
IOException

date

public static JdbcEscape date(Date d)
Returns:
a JDBC escaped value with the date portion of the given Date

time

public static JdbcEscape time(Date d)
Returns:
a JDBC escaped value with the time portion of the given Date

timestamp

public static JdbcEscape timestamp(Date d)
Returns:
a JDBC escaped value with the date-time portion of the given Date (including milliseconds)

isDisableParens

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


isEmpty

public boolean isEmpty()
Returns true iff the output of this instance would be an empty expression, false otherwise.

Default implementation returns false.


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–2017 Health Market Science. All rights reserved.