org.apache.ibatis.abator.internal.sqlmap
Class SqlMapGeneratorIterateImpl

java.lang.Object
  extended byorg.apache.ibatis.abator.internal.sqlmap.SqlMapGeneratorIterateImpl
All Implemented Interfaces:
SqlMapGenerator

public class SqlMapGeneratorIterateImpl
extends java.lang.Object
implements SqlMapGenerator

Author:
Jeff Butler

Field Summary
protected  JavaModelGenerator javaModelGenerator
          This is the java model generator associated with the current generation context.
protected  java.util.Map properties
          Contains any properties passed in from the SqlMap configuration element.
protected  java.lang.String targetPackage
          This is the target package from the SqlMap configuration element
protected  java.lang.String targetProject
          This is the target project from the SqlMap configuration element
protected  java.util.List warnings
           
 
Constructor Summary
SqlMapGeneratorIterateImpl()
          Constructs an instance of SqlMapGeneratorDefaultImpl
 
Method Summary
protected  void addAttribute(java.lang.StringBuffer sb, java.lang.String name, java.lang.String value)
          Utility method that adds an XML attribute to a StringBuffer.
protected  void addQuotedString(java.lang.StringBuffer sb, java.lang.String value, boolean spaceBefore)
          Utility method .
protected  java.lang.String formatLongString(java.lang.String s, int maxLineLength, int indentLevel)
          Utility method.
protected  java.lang.String getBaseResultMapElement(ColumnDefinitions columnDefinitions, TableConfiguration tableConfiguration, int indentLevel)
          This method should return a String which is formatted XML for the result map (without any BLOBs if they exist in the table).
protected  java.lang.String getByExampleWhereClauseFragment(int indentLevel)
          This method should return well formatted XML for the example where clause SQL fragment (an sql fragment).
protected  java.lang.String getDeleteByExample(ColumnDefinitions columnDefinitions, TableConfiguration tableConfiguration, int indentLevel)
          This method should return well formatted XML for the delete by example statement.
 java.lang.String getDeleteByExampleStatementId()
           
protected  java.lang.String getDeleteByPrimaryKey(ColumnDefinitions columnDefinitions, TableConfiguration tableConfiguration, int indentLevel)
          This method should return well formatted XML for the delete by primary key statement.
 java.lang.String getDeleteByPrimaryKeyStatementId()
           
protected  java.lang.String getDocType()
          Creates the DOCTYPE for the SqlMap
protected  java.lang.String getElementComment(int indentLevel)
          Returns a suitable comment to warn users that the element was generated, and when it was generated.
protected  java.lang.String getExampleWhereClauseId()
          Calculates the name of the example where clause element
protected  java.lang.String getFileComment(TableConfiguration tableConfiguration)
          Returns a file level comment.
 java.util.List getGeneratedXMLFiles(ColumnDefinitions columnDefinitions, TableConfiguration tableConfiguration, ProgressCallback callback)
           
protected  java.lang.String getInsertElement(ColumnDefinitions columnDefinitions, TableConfiguration tableConfiguration, int indentLevel)
          This method should return a String which is formatted XML for the insert statement.
 java.lang.String getInsertStatementId()
           
protected  java.lang.String getResultMapName(FullyQualifiedTable table)
          Calculates the name of the result map.
protected  java.lang.String getResultMapWithBLOBsElement(ColumnDefinitions columnDefinitions, TableConfiguration tableConfiguration, int indentLevel)
          This method should return a String which is formatted XML for the result map (with any BLOBs if they exist in the table).
protected  java.lang.String getSelectByExample(ColumnDefinitions columnDefinitions, TableConfiguration tableConfiguration, int indentLevel)
          This method should return well formatted XML for the select by example statement that returns all fields in the table (except BLOB fields).
 java.lang.String getSelectByExampleStatementId()
           
protected  java.lang.String getSelectByExampleWithBLOBs(ColumnDefinitions columnDefinitions, TableConfiguration tableConfiguration, int indentLevel)
          This method should return well formatted XML for the select by example statement that returns all fields in the table (including BLOB fields).
 java.lang.String getSelectByExampleWithBLOBsStatementId()
           
protected  java.lang.String getSelectByPrimaryKey(ColumnDefinitions columnDefinitions, TableConfiguration tableConfiguration, int indentLevel)
          This method should return well formatted XML for the select by primary key statement.
 java.lang.String getSelectByPrimaryKeyStatementId()
           
protected  java.lang.String getSelectKey(ColumnDefinition columnDefinition, TableConfiguration tableConfiguration, int indentLevel)
          This method should return well formatted XML for the select key element used to automatically generate keys.
protected  GeneratedXmlFile getSqlMap(ColumnDefinitions columnDefinitions, TableConfiguration tableConfiguration)
          Creates the default implementation of the Sql Map
protected  java.lang.String getSqlMapElement(ColumnDefinitions columnDefinitions, TableConfiguration tableConfiguration)
          Creates the sqlMap element (the root element, and all child elements).
protected  java.lang.String getSqlMapFileName(FullyQualifiedTable table)
          Calculates a file name for the current table.
 java.lang.String getSqlMapNamespace(FullyQualifiedTable table)
           
protected  java.lang.String getSqlMapPackage(FullyQualifiedTable table)
          Calculates the package for the current table.
protected  java.lang.String getUpdateByPrimaryKey(ColumnDefinitions columnDefinitions, TableConfiguration tableConfiguration, int indentLevel)
          This method should return well formatted XML for the update by primary key statement that updates all fields in the table (excluding BLOB fields).
 java.lang.String getUpdateByPrimaryKeyStatementId()
           
protected  java.lang.String getUpdateByPrimaryKeyWithBLOBs(ColumnDefinitions columnDefinitions, TableConfiguration tableConfiguration, int indentLevel)
          This method should return well formatted XML for the update by primary key statement that updates all fields in the table (including BLOB fields).
 java.lang.String getUpdateByPrimaryKeyWithBLOBsStatementId()
           
protected  void indent(java.lang.StringBuffer sb, int indentLevel)
          Utility method that indents the buffer by the default amount (two spaces per indent level).
protected  void newLine(java.lang.StringBuffer sb)
          Utility method.
 void setJavaModelGenerator(JavaModelGenerator javaModelGenerator)
           
 void setProperties(java.util.Map properties)
           
 void setTargetPackage(java.lang.String targetPackage)
           
 void setTargetProject(java.lang.String targetProject)
           
 void setWarnings(java.util.List warnings)
          Abator will supply a list to this method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

warnings

protected java.util.List warnings

properties

protected java.util.Map properties
Contains any properties passed in from the SqlMap configuration element.


targetPackage

protected java.lang.String targetPackage
This is the target package from the SqlMap configuration element


targetProject

protected java.lang.String targetProject
This is the target project from the SqlMap configuration element


javaModelGenerator

protected JavaModelGenerator javaModelGenerator
This is the java model generator associated with the current generation context. Methods in this interface can be used to determine the appropriate result and parameter class names.

Constructor Detail

SqlMapGeneratorIterateImpl

public SqlMapGeneratorIterateImpl()
Constructs an instance of SqlMapGeneratorDefaultImpl

Method Detail

setProperties

public void setProperties(java.util.Map properties)
Specified by:
setProperties in interface SqlMapGenerator

setTargetPackage

public void setTargetPackage(java.lang.String targetPackage)
Specified by:
setTargetPackage in interface SqlMapGenerator

setJavaModelGenerator

public void setJavaModelGenerator(JavaModelGenerator javaModelGenerator)
Specified by:
setJavaModelGenerator in interface SqlMapGenerator

getGeneratedXMLFiles

public java.util.List getGeneratedXMLFiles(ColumnDefinitions columnDefinitions,
                                           TableConfiguration tableConfiguration,
                                           ProgressCallback callback)
Specified by:
getGeneratedXMLFiles in interface SqlMapGenerator

getSqlMap

protected GeneratedXmlFile getSqlMap(ColumnDefinitions columnDefinitions,
                                     TableConfiguration tableConfiguration)
Creates the default implementation of the Sql Map

Parameters:
columnDefinitions - introspected column definitions for the current table
tableConfiguration - table configuration for the current table
Returns:
A GeneratedXMLFile for the current table

getDocType

protected java.lang.String getDocType()
Creates the DOCTYPE for the SqlMap

Returns:
the DOCTYPE

getSqlMapElement

protected java.lang.String getSqlMapElement(ColumnDefinitions columnDefinitions,
                                            TableConfiguration tableConfiguration)
Creates the sqlMap element (the root element, and all child elements).

Parameters:
columnDefinitions - introspected column definitions for the current table
tableConfiguration - table configuration for the current table
Returns:
a well formatted String containing the sqlMap element, and all child elements

getFileComment

protected java.lang.String getFileComment(TableConfiguration tableConfiguration)
Returns a file level comment. The default implementation returns null, but this can be overridden to provide a file level comment (such as a copyright notice).

Parameters:
tableConfiguration - table configuration for the current table
Returns:
a properly formatted comment

getElementComment

protected java.lang.String getElementComment(int indentLevel)
Returns a suitable comment to warn users that the element was generated, and when it was generated. The returned string should be well formatted, and indented at the specified level.

Parameters:
indentLevel - the required indent level
Returns:
a properly formatted comment

getBaseResultMapElement

protected java.lang.String getBaseResultMapElement(ColumnDefinitions columnDefinitions,
                                                   TableConfiguration tableConfiguration,
                                                   int indentLevel)
This method should return a String which is formatted XML for the result map (without any BLOBs if they exist in the table).

Parameters:
columnDefinitions - introspected column definitions for the current table
tableConfiguration - table configuration for the current table
indentLevel - the required indent level
Returns:
a well formatted String containing the resultMap element

getResultMapWithBLOBsElement

protected java.lang.String getResultMapWithBLOBsElement(ColumnDefinitions columnDefinitions,
                                                        TableConfiguration tableConfiguration,
                                                        int indentLevel)
This method should return a String which is formatted XML for the result map (with any BLOBs if they exist in the table). Typically this result map extends the base result map.

Parameters:
columnDefinitions - introspected column definitions for the current table
tableConfiguration - table configuration for the current table
indentLevel - the required indent level
Returns:
a well formatted String containing the resultMap element

getInsertElement

protected java.lang.String getInsertElement(ColumnDefinitions columnDefinitions,
                                            TableConfiguration tableConfiguration,
                                            int indentLevel)
This method should return a String which is formatted XML for the insert statement.

Parameters:
columnDefinitions - introspected column definitions for the current table
tableConfiguration - table configuration for the current table
indentLevel - the required indent level
Returns:
a well formatted String containing the insert element

getUpdateByPrimaryKeyWithBLOBs

protected java.lang.String getUpdateByPrimaryKeyWithBLOBs(ColumnDefinitions columnDefinitions,
                                                          TableConfiguration tableConfiguration,
                                                          int indentLevel)
This method should return well formatted XML for the update by primary key statement that updates all fields in the table (including BLOB fields).

Parameters:
columnDefinitions - introspected column definitions for the current table
tableConfiguration - table configuration for the current table
indentLevel - the required indent level
Returns:
a well formatted String containing the update element

getUpdateByPrimaryKey

protected java.lang.String getUpdateByPrimaryKey(ColumnDefinitions columnDefinitions,
                                                 TableConfiguration tableConfiguration,
                                                 int indentLevel)
This method should return well formatted XML for the update by primary key statement that updates all fields in the table (excluding BLOB fields).

Parameters:
columnDefinitions - introspected column definitions for the current table
tableConfiguration - table configuration for the current table
indentLevel - the required indent level
Returns:
a well formatted String containing the update element

getDeleteByPrimaryKey

protected java.lang.String getDeleteByPrimaryKey(ColumnDefinitions columnDefinitions,
                                                 TableConfiguration tableConfiguration,
                                                 int indentLevel)
This method should return well formatted XML for the delete by primary key statement.

Parameters:
columnDefinitions - introspected column definitions for the current table
tableConfiguration - table configuration for the current table
indentLevel - the required indent level
Returns:
a well formatted String containing the delete element

getDeleteByExample

protected java.lang.String getDeleteByExample(ColumnDefinitions columnDefinitions,
                                              TableConfiguration tableConfiguration,
                                              int indentLevel)
This method should return well formatted XML for the delete by example statement. This statement uses the "by example" SQL fragment

Parameters:
columnDefinitions - introspected column definitions for the current table
tableConfiguration - table configuration for the current table
indentLevel - the required indent level
Returns:
a well formatted String containing the delete element

getSelectByPrimaryKey

protected java.lang.String getSelectByPrimaryKey(ColumnDefinitions columnDefinitions,
                                                 TableConfiguration tableConfiguration,
                                                 int indentLevel)
This method should return well formatted XML for the select by primary key statement. The statement should include all fields in the table, including BLOB fields.

Parameters:
columnDefinitions - introspected column definitions for the current table
tableConfiguration - table configuration for the current table
indentLevel - the required indent level
Returns:
a well formatted String containing the select element

indent

protected void indent(java.lang.StringBuffer sb,
                      int indentLevel)
Utility method that indents the buffer by the default amount (two spaces per indent level).

Parameters:
sb - a StringBuffer to append to
indentLevel - the required indent level

addAttribute

protected void addAttribute(java.lang.StringBuffer sb,
                            java.lang.String name,
                            java.lang.String value)
Utility method that adds an XML attribute to a StringBuffer.

Parameters:
sb - the StringBuffer to append to
name - the name of the attribute
value - the value of the attribute (this method will add the enclosing quotation marks automatically)

addQuotedString

protected void addQuotedString(java.lang.StringBuffer sb,
                               java.lang.String value,
                               boolean spaceBefore)
Utility method . Adds a string surround with quotation marks to a StringBuffer

Parameters:
sb - the StringBuffer to append to
value - the value to append (the value will be surrounded by quotation marks by this method)
spaceBefore - if true, a space will be added before the value

newLine

protected void newLine(java.lang.StringBuffer sb)
Utility method. Adds a newline character to a StringBuffer.

Parameters:
sb - the StringBuffer to be appended to

formatLongString

protected java.lang.String formatLongString(java.lang.String s,
                                            int maxLineLength,
                                            int indentLevel)
Utility method. Takes a long string and breaks it into multiple lines of whose width is no longer that the specified maximum line length.

Parameters:
s - the String to be formatted
maxLineLength - the maximum line length
indentLevel - the required indent level of all lines
Returns:
the formatted String

getSelectKey

protected java.lang.String getSelectKey(ColumnDefinition columnDefinition,
                                        TableConfiguration tableConfiguration,
                                        int indentLevel)
This method should return well formatted XML for the select key element used to automatically generate keys.

Parameters:
columnDefinition - the column related to the select key statement
tableConfiguration - table configuration for the current table
indentLevel - the required indent level
Returns:
a well formatted String containing the selectKey element

getSqlMapNamespace

public java.lang.String getSqlMapNamespace(FullyQualifiedTable table)
Specified by:
getSqlMapNamespace in interface SqlMapGenerator

getResultMapName

protected java.lang.String getResultMapName(FullyQualifiedTable table)
Calculates the name of the result map. Typically this is the String "abatorgenerated_XXXXResult" where XXXX is the name of the domain object related to this table. The prefix "abatorgenerated_" is important because it allows Abator to regenerate this element on subsequent runs.

Parameters:
table - the current table
Returns:
the name of the result map

getSqlMapFileName

protected java.lang.String getSqlMapFileName(FullyQualifiedTable table)
Calculates a file name for the current table. Typically the name is "XXXX_SqlMap.xml" where XXXX is the fully qualified table name (delimited with underscores).

Parameters:
table - the current table
Returns:
tha name of the SqlMap file

getDeleteByPrimaryKeyStatementId

public java.lang.String getDeleteByPrimaryKeyStatementId()
Specified by:
getDeleteByPrimaryKeyStatementId in interface SqlMapGenerator

getDeleteByExampleStatementId

public java.lang.String getDeleteByExampleStatementId()
Specified by:
getDeleteByExampleStatementId in interface SqlMapGenerator

getInsertStatementId

public java.lang.String getInsertStatementId()
Specified by:
getInsertStatementId in interface SqlMapGenerator

getSelectByPrimaryKeyStatementId

public java.lang.String getSelectByPrimaryKeyStatementId()
Specified by:
getSelectByPrimaryKeyStatementId in interface SqlMapGenerator

getSelectByExampleStatementId

public java.lang.String getSelectByExampleStatementId()
Specified by:
getSelectByExampleStatementId in interface SqlMapGenerator

getSelectByExampleWithBLOBsStatementId

public java.lang.String getSelectByExampleWithBLOBsStatementId()
Specified by:
getSelectByExampleWithBLOBsStatementId in interface SqlMapGenerator

getUpdateByPrimaryKeyWithBLOBsStatementId

public java.lang.String getUpdateByPrimaryKeyWithBLOBsStatementId()
Specified by:
getUpdateByPrimaryKeyWithBLOBsStatementId in interface SqlMapGenerator

getUpdateByPrimaryKeyStatementId

public java.lang.String getUpdateByPrimaryKeyStatementId()
Specified by:
getUpdateByPrimaryKeyStatementId in interface SqlMapGenerator

getSqlMapPackage

protected java.lang.String getSqlMapPackage(FullyQualifiedTable table)
Calculates the package for the current table.

Parameters:
table - the current table
Returns:
the package for the SqlMap for the current table

getExampleWhereClauseId

protected java.lang.String getExampleWhereClauseId()
Calculates the name of the example where clause element

Returns:
the name of the example where clause element

getByExampleWhereClauseFragment

protected java.lang.String getByExampleWhereClauseFragment(int indentLevel)
This method should return well formatted XML for the example where clause SQL fragment (an sql fragment).

Parameters:
indentLevel - the required indent level
Returns:
a well formatted String containing the SQL element

getSelectByExample

protected java.lang.String getSelectByExample(ColumnDefinitions columnDefinitions,
                                              TableConfiguration tableConfiguration,
                                              int indentLevel)
This method should return well formatted XML for the select by example statement that returns all fields in the table (except BLOB fields).

Parameters:
columnDefinitions - introspected column definitions for the current table
tableConfiguration - table configuration for the current table
indentLevel - the required indent level
Returns:
a well formatted String containing the update element

getSelectByExampleWithBLOBs

protected java.lang.String getSelectByExampleWithBLOBs(ColumnDefinitions columnDefinitions,
                                                       TableConfiguration tableConfiguration,
                                                       int indentLevel)
This method should return well formatted XML for the select by example statement that returns all fields in the table (including BLOB fields).

Parameters:
columnDefinitions - introspected column definitions for the current table
tableConfiguration - table configuration for the current table
indentLevel - the required indent level
Returns:
a well formatted String containing the update element

setTargetProject

public void setTargetProject(java.lang.String targetProject)
Specified by:
setTargetProject in interface SqlMapGenerator

setWarnings

public void setWarnings(java.util.List warnings)
Description copied from interface: SqlMapGenerator
Abator will supply a list to this method. The implementation class may add strings to the list that will be treated as warning messages and displayed to the user. The concept of a warning is that code generation can continue, but that the results may not be what is expected.

Specified by:
setWarnings in interface SqlMapGenerator
Parameters:
warnings -