jodd.db.orm.sqlgen.chunks
Class SqlChunk

java.lang.Object
  extended by jodd.db.orm.sqlgen.chunks.SqlChunk
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
ColumnsSelectChunk, InsertChunk, MatchChunk, RawSqlChunk, ReferenceChunk, TableChunk, UpdateSetChunk, ValueChunk

public abstract class SqlChunk
extends java.lang.Object
implements java.lang.Cloneable

SQL chunk defines part of the SQL query that can be processed.


Field Summary
static int CHUNK_INSERT
           
static int CHUNK_MATCH
           
static int CHUNK_RAW
           
static int CHUNK_REFERENCE
           
static int CHUNK_SELECT_COLUMNS
           
static int CHUNK_TABLE
           
static int CHUNK_UPDATE
           
static int CHUNK_VALUE
           
protected  int chunkType
           
static int COLS_ALL
           
static int COLS_NA
           
static int COLS_ONLY_EXISTING
           
static int COLS_ONLY_IDS
           
protected  SqlChunk nextChunk
           
protected  SqlChunk previousChunk
           
protected  TemplateData templateData
           
 
Constructor Summary
protected SqlChunk(int chunkType)
           
 
Method Summary
protected  void appendMissingSpace(java.lang.StringBuilder out)
          Appends missing space if the output doesn't end with whitespace.
abstract  SqlChunk clone()
          Clones all parsed chunk data to an instance that is ready for processing.
protected  void defineParameter(java.lang.StringBuilder query, java.lang.String name, java.lang.Object value, DbEntityColumnDescriptor dec)
          Defines parameter with name and its value.
 SqlChunk getNextChunk()
          Returns next chunk.
 SqlChunk getPreviousChunk()
          Returns previous chunk.
 void init(TemplateData templateData)
          Initializes chunk.
 void insertChunkAfter(SqlChunk previous)
          Appends chunk to previous one and maintaince the double-linked list of the previous chunk.
 boolean isPreviousChunkOfSameType()
          Returns true if previous chunk is of the same type.
 boolean isPreviousChunkOfType(int type)
          Returns true if previous chunk is of provided type.
 boolean isPreviousMacroChunk()
          Returns true if previous chunk is not raw.
 boolean isPreviousRawChunk()
           
protected  DbEntityDescriptor lookupName(java.lang.String entityName)
          Lookups for entity name and throws exception if entity name not found.
protected  DbEntityDescriptor lookupTableRef(java.lang.String tableRef)
          Lookups for table reference and throws an exception if table reference not found.
protected  DbEntityDescriptor lookupType(java.lang.Class entity)
          Lookups for entity name and throws an exception if entity type is invalid.
abstract  void process(java.lang.StringBuilder out)
          Process the chunk and appends data to the output.
protected static java.lang.Class resolveClass(java.lang.Object object)
          Resolves object to a class.
protected  java.lang.String resolveTable(java.lang.String tableRef, DbEntityDescriptor ded)
          Resolves table name or alias that will be used in the query.
protected  void separateByCommaOrSpace(java.lang.StringBuilder out)
          Separates from previous chunk by comma if is of the same type.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COLS_NA

public static final int COLS_NA
See Also:
Constant Field Values

COLS_ONLY_EXISTING

public static final int COLS_ONLY_EXISTING
See Also:
Constant Field Values

COLS_ONLY_IDS

public static final int COLS_ONLY_IDS
See Also:
Constant Field Values

COLS_ALL

public static final int COLS_ALL
See Also:
Constant Field Values

chunkType

protected final int chunkType

CHUNK_RAW

public static final int CHUNK_RAW
See Also:
Constant Field Values

CHUNK_SELECT_COLUMNS

public static final int CHUNK_SELECT_COLUMNS
See Also:
Constant Field Values

CHUNK_TABLE

public static final int CHUNK_TABLE
See Also:
Constant Field Values

CHUNK_REFERENCE

public static final int CHUNK_REFERENCE
See Also:
Constant Field Values

CHUNK_MATCH

public static final int CHUNK_MATCH
See Also:
Constant Field Values

CHUNK_VALUE

public static final int CHUNK_VALUE
See Also:
Constant Field Values

CHUNK_INSERT

public static final int CHUNK_INSERT
See Also:
Constant Field Values

CHUNK_UPDATE

public static final int CHUNK_UPDATE
See Also:
Constant Field Values

previousChunk

protected SqlChunk previousChunk

nextChunk

protected SqlChunk nextChunk

templateData

protected TemplateData templateData
Constructor Detail

SqlChunk

protected SqlChunk(int chunkType)
Method Detail

getPreviousChunk

public SqlChunk getPreviousChunk()
Returns previous chunk.


getNextChunk

public SqlChunk getNextChunk()
Returns next chunk.


insertChunkAfter

public void insertChunkAfter(SqlChunk previous)
Appends chunk to previous one and maintaince the double-linked list of the previous chunk. Current surrounding connections of this chunk will be cut-off.


isPreviousChunkOfType

public boolean isPreviousChunkOfType(int type)
Returns true if previous chunk is of provided type.


isPreviousChunkOfSameType

public boolean isPreviousChunkOfSameType()
Returns true if previous chunk is of the same type.


isPreviousMacroChunk

public boolean isPreviousMacroChunk()
Returns true if previous chunk is not raw.


isPreviousRawChunk

public boolean isPreviousRawChunk()

init

public void init(TemplateData templateData)
Initializes chunk. Assigns TemplateData to chunk. If chunk needs some pre-processing, they should be done here.


process

public abstract void process(java.lang.StringBuilder out)
Process the chunk and appends data to the output.


lookupName

protected DbEntityDescriptor lookupName(java.lang.String entityName)
Lookups for entity name and throws exception if entity name not found.


lookupType

protected DbEntityDescriptor lookupType(java.lang.Class entity)
Lookups for entity name and throws an exception if entity type is invalid.


lookupTableRef

protected DbEntityDescriptor lookupTableRef(java.lang.String tableRef)
Lookups for table reference and throws an exception if table reference not found.


resolveTable

protected java.lang.String resolveTable(java.lang.String tableRef,
                                        DbEntityDescriptor ded)
Resolves table name or alias that will be used in the query.


defineParameter

protected void defineParameter(java.lang.StringBuilder query,
                               java.lang.String name,
                               java.lang.Object value,
                               DbEntityColumnDescriptor dec)
Defines parameter with name and its value.


resolveClass

protected static java.lang.Class resolveClass(java.lang.Object object)
Resolves object to a class.


appendMissingSpace

protected void appendMissingSpace(java.lang.StringBuilder out)
Appends missing space if the output doesn't end with whitespace.


separateByCommaOrSpace

protected void separateByCommaOrSpace(java.lang.StringBuilder out)
Separates from previous chunk by comma if is of the same type.


clone

public abstract SqlChunk clone()
Clones all parsed chunk data to an instance that is ready for processing.

Overrides:
clone in class java.lang.Object


Copyright © 2003-2011 Jodd Team