com.healthmarketscience.sqlbuilder
Class Query<ThisType extends Query<ThisType>>

java.lang.Object
  extended by com.healthmarketscience.common.util.AppendeeObject
      extended by com.healthmarketscience.sqlbuilder.SqlObject
          extended by com.healthmarketscience.sqlbuilder.CustomizableSqlObject
              extended by com.healthmarketscience.sqlbuilder.Query<ThisType>
All Implemented Interfaces:
Appendee, Verifiable<ThisType>
Direct Known Subclasses:
AlterTableQuery, BaseCreateQuery, BaseCTEQuery, BaseGrantQuery, DropQuery, SetOperationQuery

public abstract class Query<ThisType extends Query<ThisType>>
extends CustomizableSqlObject
implements Verifiable<ThisType>

Base class for all query statements which adds a validation facility. The query classes are designed for "builder" type use, so all return values are the query object itself.

Author:
James Ahlborn

Field Summary
 
Fields inherited from class com.healthmarketscience.sqlbuilder.SqlObject
ALL_SYMBOL, NULL_VALUE, QUESTION_MARK
 
Constructor Summary
protected Query()
           
 
Method Summary
 void appendTo(AppendableExt app)
           
protected abstract  void appendTo(AppendableExt app, SqlContext newContext)
          Appends the sql query to the given AppendableExt within the given, modifiable SqlContext.
protected  void collectSchemaObjects(ValidationContext vContext)
          Used during Query.validate() calls to collect the dbschema objects referenced in a query.
protected  ThisType getThisType()
           
protected  void prependTo(AppendableExt app)
          Called by appendTo(AppendableExt) before appendTo(AppendableExt,SqlContext) within the original SqlContext.
 ThisType validate()
          Runs validation on this verifiable object.
 void validate(ValidationContext vContext)
          Runs validation on this verifiable object using a previously collected ValidationContext.
protected  void validateTables(ValidationContext vContext)
          Verifies that any columns referenced in the query have their respective tables also referenced in the query.
 
Methods inherited from class com.healthmarketscience.sqlbuilder.CustomizableSqlObject
addCustomization, customAppendTo, customAppendTo, maybeAppendTo, maybeAppendTo
 
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

Query

protected Query()
Method Detail

validate

public final ThisType validate()
                                                throws ValidationException
Description copied from interface: Verifiable
Runs validation on this verifiable object.

Specified by:
validate in interface Verifiable<ThisType extends Query<ThisType>>
Returns:
a handle to this instance
Throws:
ValidationException

validate

public void validate(ValidationContext vContext)
              throws ValidationException
Description copied from interface: Verifiable
Runs validation on this verifiable object using a previously collected ValidationContext.

In general, this method will only be called internally, not by users.

Specified by:
validate in interface Verifiable<ThisType extends Query<ThisType>>
Parameters:
vContext - handle to the current, filled-in validation context
Throws:
ValidationException

validateTables

protected void validateTables(ValidationContext vContext)
                       throws ValidationException
Verifies that any columns referenced in the query have their respective tables also referenced in the query.

Parameters:
vContext - handle to the current validation context
Throws:
ValidationException

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.

Overrides:
collectSchemaObjects in class CustomizableSqlObject
Parameters:
vContext - handle to the current validation context

appendTo

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

getThisType

protected final ThisType getThisType()
Returns:
the handle to this object as the subclass type

prependTo

protected void prependTo(AppendableExt app)
                  throws IOException
Called by appendTo(AppendableExt) before appendTo(AppendableExt,SqlContext) within the original SqlContext.

Throws:
IOException

appendTo

protected abstract void appendTo(AppendableExt app,
                                 SqlContext newContext)
                          throws IOException
Appends the sql query to the given AppendableExt within the given, modifiable SqlContext. This method is invoked by the appendTo(AppendableExt) method within the context of calls to SqlContext.pushContext(com.healthmarketscience.common.util.AppendableExt) and SqlContext.popContext(com.healthmarketscience.common.util.AppendableExt, com.healthmarketscience.sqlbuilder.SqlContext), so the implementation is free to modify the given SqlContext.

Parameters:
app - the target for the sql query generation
newContext - modifiable SqlContext for nested Appendees
Throws:
IOException


Copyright © 2006–2017 Health Market Science. All rights reserved.