org.apache.ws.jaxme.sqls.impl
Class SQLGeneratorImpl

java.lang.Object
  extended by org.apache.ws.jaxme.sqls.impl.SQLGeneratorImpl
All Implemented Interfaces:
SQLGenerator
Direct Known Subclasses:
DB2SQLGeneratorImpl, HsqlDbSQLGeneratorImpl, OraSQLGeneratorImpl

public class SQLGeneratorImpl
extends java.lang.Object
implements SQLGenerator

Default implementation of an SQL generator.

Author:
Jochen Wiedmann

Constructor Summary
SQLGeneratorImpl()
           
 
Method Summary
protected  java.lang.String createForeignKeyAsPartOfCreateTable(ForeignKey pKey)
           
protected  java.lang.String createIndexAsPartOfCreateTable(Index pIndex)
           
protected  java.lang.String createPrimaryKeyAsPartOfCreateTable(Table pTable)
           
protected  java.lang.String getBooleanConstraint(StatementMetaData pData, BooleanConstraint pConstraint)
           
protected  java.lang.String getBooleanConstraintPart(StatementMetaData pData, java.lang.Object o)
           
protected  java.lang.String getBooleanConstraintType(BooleanConstraint.Type pType)
           
protected  java.lang.String getCase(StatementMetaData pData, Case pCase)
           
protected  java.lang.String getColumnAlias(StatementMetaData pData, ColumnReference pColumn)
           
protected  java.lang.String getColumnAlias(StatementMetaData pData, ColumnReference[] pColumn)
           
protected  java.lang.String getCombinedConstraint(StatementMetaData pData, CombinedConstraint pConstraint)
           
 java.lang.String getConstraint(Constraint pConstraint)
          Generates the WHERE clause of a SELECT, UPDATE, or DELETE statement.
 java.lang.String getConstraint(StatementMetaData pData, Constraint pConstraint)
           
protected  java.lang.String getCreate(Column pColumn)
           
 java.util.Collection getCreate(ForeignKey pKey)
          Generates a CREATE FOREIGN KEY statement.
 java.util.Collection getCreate(Index pIndex)
          Generates a CREATE INDEX statement.
 java.util.Collection getCreate(Schema pSchema)
          Generates a CREATE SCHEMA statement.
 java.util.Collection getCreate(Schema pSchema, boolean pAll)
          Generates CREATE statements for the schema.
 java.util.Collection getCreate(Table pTable)
          Generates a CREATE TABLE statement.
 java.util.Collection getCreate(Table pTable, boolean pAll)
          Generates CREATE statements for the table.
protected  java.lang.String getCreateTableHeader(Table pTable)
           
protected  java.lang.String getDeleteQuery(DeleteStatement pQuery)
           
 java.util.Collection getDrop(ForeignKey pKey)
          Generates a DROP FOEIGN KEY statement.
 java.util.Collection getDrop(Index pIndex)
          Generates a DROP INDEX statement.
 java.util.Collection getDrop(Schema pSchema)
          Generates a DROP SCHEMA statement.
 java.util.Collection getDrop(Schema pSchema, boolean pAll)
          Generates DROP statements for the schema.
 java.util.Collection getDrop(Table pTable)
          Generates a DROP TABLE statement.
 java.util.Collection getDrop(Table pTable, boolean pAll)
          Generates DROP statements for the table.
protected  java.lang.String getEscapedString(java.lang.String s)
           
protected  java.lang.String getExpression(StatementMetaData pData, Expression pExpr)
           
protected  java.lang.String getFunction(StatementMetaData pData, Function f)
           
protected  java.lang.String getIndent()
           
 java.lang.String getInsertQuery(InsertStatement pQuery)
           
protected  java.lang.String getJoinAlias(StatementMetaData pData, JoinReference pJoinReference)
           
 java.lang.String getLineTerminator()
          Returns the line terminator.
protected  java.lang.String getOrderColumn(StatementMetaData pData, SelectStatement.OrderColumn pColumn)
           
protected  java.lang.String getParts(StatementMetaData pData, java.util.Iterator pParts)
           
 java.lang.String getQuery(Statement pStatement)
          Generates an INSERT, UPDATE, DELETE or SELECT statement.
protected  java.lang.String getSelectQuery(SelectStatement pQuery)
           
protected  java.lang.String getSelectQuery(SelectStatement pQuery, StatementMetaData pData)
           
protected  java.lang.String getSelectQueryConstraints(SelectStatement pQuery, StatementMetaData pData, StatementMetaData.LocalData pLocalData)
           
protected  java.lang.String getSelectQueryFromClause(SelectStatement pQuery, StatementMetaData pData)
           
protected  java.lang.String getSelectQueryOrderClause(StatementMetaData pData, SelectStatement pQuery)
           
protected  java.lang.String getSelectQueryResultColumns(SelectStatement pQuery, StatementMetaData pData)
           
 java.lang.String getStatementTerminator()
          Returns the statement terminator.
protected  java.lang.String getTableAlias(StatementMetaData pData, TableReference pTable)
           
protected  java.lang.String getTypeName(Column.Type pType)
           
protected  java.lang.String getUpdateQuery(UpdateStatement pQuery)
           
protected  java.lang.String getValue(Value pValue)
           
 java.lang.String getWhereClause(SelectStatement pQuery)
          Returns the WHERE ...
protected  java.lang.String getWhereClause(StatementMetaData pData, CombinedConstraint pWhereClause)
           
protected  boolean isForeignKeyPartOfCreateTable()
          Returns whether a CREATE TABLE statement may contain a FOREIGN KEY clause.
protected  boolean isNonUniqueIndexPartOfCreateTable()
          Returns whether a CREATE TABLE statement may contain an INDEX clause.
protected  boolean isPrimaryKeyPartOfCreateTable()
          Returns whether a CREATE TABLE statement may contain a PRIMARY KEY clause.
protected  boolean isPrimaryKeyUniqueIndex()
          Returns whether the primary key requires special handling (in which case isPrimaryKeyPartOfCreateTable() and createPrimaryKeyAsPartOfCreateTable(Table) are used) or nor (in which case isUniqueIndexPartOfCreateTable() and createIndexAsPartOfCreateTable(Index) apply).
protected  boolean isQualifiedColumn(StatementMetaData pData, ColumnReference pColumn)
           
protected  boolean isTableAliasUsingAs()
           
protected  boolean isUniqueIndexPartOfCreateTable()
          Returns whether a CREATE TABLE statement may contain a UNIQUE clause.
protected  java.lang.String newStatement(java.lang.String pStatement)
           
protected  StatementMetaData newStatementMetaData(DeleteStatement pQuery)
           
protected  StatementMetaData newStatementMetaData(InsertStatement pQuery, ColumnReference[] pColumns)
           
protected  StatementMetaData newStatementMetaData(SelectStatement pQuery)
           
protected  StatementMetaData newStatementMetaData(UpdateStatement pQuery, ColumnReference[] pColumns)
           
 void setLineTerminator(java.lang.String pLineTerminator)
          Sets the line terminator.
 void setStatementTerminator(java.lang.String pStatementTerminator)
          Sets the statement terminator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLGeneratorImpl

public SQLGeneratorImpl()
Method Detail

getStatementTerminator

public java.lang.String getStatementTerminator()
Description copied from interface: SQLGenerator

Returns the statement terminator. A non-null value will be appended to all generated statements. Defaults to null.

Specified by:
getStatementTerminator in interface SQLGenerator

setStatementTerminator

public void setStatementTerminator(java.lang.String pStatementTerminator)
Description copied from interface: SQLGenerator

Sets the statement terminator. A non-null value will be appended to all generated statements. Defaults to null.

Specified by:
setStatementTerminator in interface SQLGenerator

getLineTerminator

public java.lang.String getLineTerminator()
Description copied from interface: SQLGenerator

Returns the line terminator. A non-null value indicates that the generated statements should be made human readable by splitting them over multiple lines. A null value ensures that a statement consists of a single line only. Defaults to "\n".

Specified by:
getLineTerminator in interface SQLGenerator

setLineTerminator

public void setLineTerminator(java.lang.String pLineTerminator)
Description copied from interface: SQLGenerator

Sets the line terminator. A non-null value indicates that the generated statements should be made human readable by splitting them over multiple lines. A null value ensures that a statement consists of a single line only. Defaults to "\n".

Specified by:
setLineTerminator in interface SQLGenerator

newStatement

protected java.lang.String newStatement(java.lang.String pStatement)

getCreate

public java.util.Collection getCreate(Schema pSchema)
Description copied from interface: SQLGenerator

Generates a CREATE SCHEMA statement. Doesn't create CREATE TABLE or similar statements.

Specified by:
getCreate in interface SQLGenerator

getDrop

public java.util.Collection getDrop(Schema pSchema)
Description copied from interface: SQLGenerator

Generates a DROP SCHEMA statement. Doesn't create DROP TABLE or similar statements.

Specified by:
getDrop in interface SQLGenerator

getIndent

protected java.lang.String getIndent()

getTypeName

protected java.lang.String getTypeName(Column.Type pType)

getCreate

protected java.lang.String getCreate(Column pColumn)

isPrimaryKeyUniqueIndex

protected boolean isPrimaryKeyUniqueIndex()

Returns whether the primary key requires special handling (in which case isPrimaryKeyPartOfCreateTable() and createPrimaryKeyAsPartOfCreateTable(Table) are used) or nor (in which case isUniqueIndexPartOfCreateTable() and createIndexAsPartOfCreateTable(Index) apply).


isPrimaryKeyPartOfCreateTable

protected boolean isPrimaryKeyPartOfCreateTable()

Returns whether a CREATE TABLE statement may contain a PRIMARY KEY clause.


isUniqueIndexPartOfCreateTable

protected boolean isUniqueIndexPartOfCreateTable()

Returns whether a CREATE TABLE statement may contain a UNIQUE clause.


isNonUniqueIndexPartOfCreateTable

protected boolean isNonUniqueIndexPartOfCreateTable()

Returns whether a CREATE TABLE statement may contain an INDEX clause.


isForeignKeyPartOfCreateTable

protected boolean isForeignKeyPartOfCreateTable()

Returns whether a CREATE TABLE statement may contain a FOREIGN KEY clause.


createPrimaryKeyAsPartOfCreateTable

protected java.lang.String createPrimaryKeyAsPartOfCreateTable(Table pTable)

createIndexAsPartOfCreateTable

protected java.lang.String createIndexAsPartOfCreateTable(Index pIndex)

createForeignKeyAsPartOfCreateTable

protected java.lang.String createForeignKeyAsPartOfCreateTable(ForeignKey pKey)

getCreateTableHeader

protected java.lang.String getCreateTableHeader(Table pTable)

getCreate

public java.util.Collection getCreate(Table pTable)
Description copied from interface: SQLGenerator

Generates a CREATE TABLE statement. Doesn't create CREATE INDEX or similar statements.

Specified by:
getCreate in interface SQLGenerator

getDrop

public java.util.Collection getDrop(Table pTable)
Description copied from interface: SQLGenerator

Generates a DROP TABLE statement. Doesn't create DROP INDEX or similar statements.

Specified by:
getDrop in interface SQLGenerator

getInsertQuery

public java.lang.String getInsertQuery(InsertStatement pQuery)

getValue

protected java.lang.String getValue(Value pValue)

getUpdateQuery

protected java.lang.String getUpdateQuery(UpdateStatement pQuery)

getDeleteQuery

protected java.lang.String getDeleteQuery(DeleteStatement pQuery)

isQualifiedColumn

protected boolean isQualifiedColumn(StatementMetaData pData,
                                    ColumnReference pColumn)

getFunction

protected java.lang.String getFunction(StatementMetaData pData,
                                       Function f)

getColumnAlias

protected java.lang.String getColumnAlias(StatementMetaData pData,
                                          ColumnReference pColumn)

getColumnAlias

protected java.lang.String getColumnAlias(StatementMetaData pData,
                                          ColumnReference[] pColumn)

isTableAliasUsingAs

protected boolean isTableAliasUsingAs()

getTableAlias

protected java.lang.String getTableAlias(StatementMetaData pData,
                                         TableReference pTable)

getJoinAlias

protected java.lang.String getJoinAlias(StatementMetaData pData,
                                        JoinReference pJoinReference)

getEscapedString

protected java.lang.String getEscapedString(java.lang.String s)

getParts

protected java.lang.String getParts(StatementMetaData pData,
                                    java.util.Iterator pParts)

getCase

protected java.lang.String getCase(StatementMetaData pData,
                                   Case pCase)

getBooleanConstraintPart

protected java.lang.String getBooleanConstraintPart(StatementMetaData pData,
                                                    java.lang.Object o)

getExpression

protected java.lang.String getExpression(StatementMetaData pData,
                                         Expression pExpr)

getBooleanConstraintType

protected java.lang.String getBooleanConstraintType(BooleanConstraint.Type pType)

getBooleanConstraint

protected java.lang.String getBooleanConstraint(StatementMetaData pData,
                                                BooleanConstraint pConstraint)

getCombinedConstraint

protected java.lang.String getCombinedConstraint(StatementMetaData pData,
                                                 CombinedConstraint pConstraint)

getConstraint

public java.lang.String getConstraint(StatementMetaData pData,
                                      Constraint pConstraint)

getWhereClause

protected java.lang.String getWhereClause(StatementMetaData pData,
                                          CombinedConstraint pWhereClause)

getSelectQuery

protected java.lang.String getSelectQuery(SelectStatement pQuery)

getSelectQueryResultColumns

protected java.lang.String getSelectQueryResultColumns(SelectStatement pQuery,
                                                       StatementMetaData pData)

getSelectQueryFromClause

protected java.lang.String getSelectQueryFromClause(SelectStatement pQuery,
                                                    StatementMetaData pData)

getSelectQueryConstraints

protected java.lang.String getSelectQueryConstraints(SelectStatement pQuery,
                                                     StatementMetaData pData,
                                                     StatementMetaData.LocalData pLocalData)

getSelectQuery

protected java.lang.String getSelectQuery(SelectStatement pQuery,
                                          StatementMetaData pData)

getOrderColumn

protected java.lang.String getOrderColumn(StatementMetaData pData,
                                          SelectStatement.OrderColumn pColumn)

getSelectQueryOrderClause

protected java.lang.String getSelectQueryOrderClause(StatementMetaData pData,
                                                     SelectStatement pQuery)

getQuery

public java.lang.String getQuery(Statement pStatement)
Description copied from interface: SQLGenerator

Generates an INSERT, UPDATE, DELETE or SELECT statement.

Specified by:
getQuery in interface SQLGenerator

getCreate

public java.util.Collection getCreate(Schema pSchema,
                                      boolean pAll)
Description copied from interface: SQLGenerator

Generates CREATE statements for the schema.

Specified by:
getCreate in interface SQLGenerator
pAll - If this parameter is set to true, then the method is equivalent to SQLGenerator.getCreate(Schema). Otherwise the returned collection will also include CREATE statements for all the tables and indexes in the schema. These additional statements are created by invoking SQLGenerator.getCreate(Table,boolean) for all the tables in the schema.


getDrop

public java.util.Collection getDrop(Schema pSchema,
                                    boolean pAll)
Description copied from interface: SQLGenerator

Generates DROP statements for the schema.

Specified by:
getDrop in interface SQLGenerator
pAll - If this parameter is set to true, then the method is equivalent to SQLGenerator.getDrop(Schema). Otherwise the returned collection will also include DROP statements for all the tables and indexes in the schema. These additional statements are created by invoking SQLGenerator.getDrop(Table,boolean) for all the tables in the schema.


getCreate

public java.util.Collection getCreate(Table pTable,
                                      boolean pAll)
Description copied from interface: SQLGenerator

Generates CREATE statements for the table.

Specified by:
getCreate in interface SQLGenerator
pAll - If this parameter is set to true, then the method is equivalent to SQLGenerator.getCreate(Table). Otherwise the returned collection will also include CREATE statements for the indexes, which are defined on the table. These additional statements are created by invoking SQLGenerator.getCreate(Index) and SQLGenerator.getCreate(ForeignKey) for all the indexes in the schema.


getDrop

public java.util.Collection getDrop(Table pTable,
                                    boolean pAll)
Description copied from interface: SQLGenerator

Generates DROP statements for the table.

Specified by:
getDrop in interface SQLGenerator
pAll - If this parameter is set to true, then the method is equivalent to SQLGenerator.getDrop(Table). Otherwise the returned collection will also include DROP statements for the indexes, which are defined on the table. These additional statements are created by invoking SQLGenerator.getDrop(Index) and SQLGenerator.getDrop(ForeignKey) for all the indexes in the schema.


getCreate

public java.util.Collection getCreate(Index pIndex)
Description copied from interface: SQLGenerator

Generates a CREATE INDEX statement.

Specified by:
getCreate in interface SQLGenerator

getDrop

public java.util.Collection getDrop(Index pIndex)
Description copied from interface: SQLGenerator

Generates a DROP INDEX statement.

Specified by:
getDrop in interface SQLGenerator

getCreate

public java.util.Collection getCreate(ForeignKey pKey)
Description copied from interface: SQLGenerator

Generates a CREATE FOREIGN KEY statement.

Specified by:
getCreate in interface SQLGenerator

getDrop

public java.util.Collection getDrop(ForeignKey pKey)
Description copied from interface: SQLGenerator

Generates a DROP FOEIGN KEY statement.

Specified by:
getDrop in interface SQLGenerator

newStatementMetaData

protected StatementMetaData newStatementMetaData(SelectStatement pQuery)

newStatementMetaData

protected StatementMetaData newStatementMetaData(DeleteStatement pQuery)

newStatementMetaData

protected StatementMetaData newStatementMetaData(UpdateStatement pQuery,
                                                 ColumnReference[] pColumns)

newStatementMetaData

protected StatementMetaData newStatementMetaData(InsertStatement pQuery,
                                                 ColumnReference[] pColumns)

getWhereClause

public java.lang.String getWhereClause(SelectStatement pQuery)
Description copied from interface: SQLGenerator

Returns the WHERE ... ORDER BY ... part of the SELECT statement.

Specified by:
getWhereClause in interface SQLGenerator

getConstraint

public java.lang.String getConstraint(Constraint pConstraint)
Description copied from interface: SQLGenerator

Generates the WHERE clause of a SELECT, UPDATE, or DELETE statement.

Specified by:
getConstraint in interface SQLGenerator