org.apache.ws.jaxme.sqls.impl

Class SQLGeneratorImpl

Implemented Interfaces:
SQLGenerator
Known Direct Subclasses:
DB2SQLGeneratorImpl, HsqlDbSQLGeneratorImpl, OraSQLGeneratorImpl

public class SQLGeneratorImpl
extends java.lang.Object
implements SQLGenerator

Default implementation of an SQL generator.
Author:
Jochen Wiedmann

Method Summary

protected String
createForeignKeyAsPartOfCreateTable(ForeignKey pKey)
protected String
createIndexAsPartOfCreateTable(Index pIndex)
protected String
createPrimaryKeyAsPartOfCreateTable(Table pTable)
protected String
getBooleanConstraint(StatementMetaData pData, BooleanConstraint pConstraint)
protected String
getBooleanConstraintPart(StatementMetaData pData, Object o)
protected String
getBooleanConstraintType(BooleanConstraint.Type pType)
protected String
getCase(StatementMetaData pData, Case pCase)
protected String
getColumnAlias(StatementMetaData pData, ColumnReference pColumn)
protected String
getColumnAlias(StatementMetaData pData, ColumnReference[] pColumn)
protected String
getCombinedConstraint(StatementMetaData pData, CombinedConstraint pConstraint)
String
getConstraint(Constraint pConstraint)
Generates the WHERE clause of a SELECT, UPDATE, or DELETE statement.
String
getConstraint(StatementMetaData pData, Constraint pConstraint)
protected String
getCreate(Column pColumn)
Collection
getCreate(ForeignKey pKey)
Generates a CREATE FOREIGN KEY statement.
Collection
getCreate(Index pIndex)
Generates a CREATE INDEX statement.
Collection
getCreate(Schema pSchema)
Generates a CREATE SCHEMA statement.
Collection
getCreate(Schema pSchema, boolean pAll)
Generates CREATE statements for the schema.
Collection
getCreate(Table pTable)
Generates a CREATE TABLE statement.
Collection
getCreate(Table pTable, boolean pAll)
Generates CREATE statements for the table.
protected String
getCreateTableHeader(Table pTable)
protected String
getDeleteQuery(DeleteStatement pQuery)
Collection
getDrop(ForeignKey pKey)
Generates a DROP FOEIGN KEY statement.
Collection
getDrop(Index pIndex)
Generates a DROP INDEX statement.
Collection
getDrop(Schema pSchema)
Generates a DROP SCHEMA statement.
Collection
getDrop(Schema pSchema, boolean pAll)
Generates DROP statements for the schema.
Collection
getDrop(Table pTable)
Generates a DROP TABLE statement.
Collection
getDrop(Table pTable, boolean pAll)
Generates DROP statements for the table.
protected String
getEscapedString(String s)
protected String
getExpression(StatementMetaData pData, Expression pExpr)
protected String
getFunction(StatementMetaData pData, Function f)
protected String
getIndent()
String
getInsertQuery(InsertStatement pQuery)
protected String
getJoinAlias(StatementMetaData pData, JoinReference pJoinReference)
String
getLineTerminator()
Returns the line terminator.
protected String
getOrderColumn(StatementMetaData pData, SelectStatement.OrderColumn pColumn)
protected String
getParts(StatementMetaData pData, Iterator pParts)
String
getQuery(Statement pStatement)
Generates an INSERT, UPDATE, DELETE or SELECT statement.
protected String
getSelectQuery(SelectStatement pQuery)
protected String
getSelectQuery(SelectStatement pQuery, StatementMetaData pData)
protected String
getSelectQueryConstraints(SelectStatement pQuery, StatementMetaData pData, StatementMetaData.LocalData pLocalData)
protected String
getSelectQueryFromClause(SelectStatement pQuery, StatementMetaData pData)
protected String
getSelectQueryOrderClause(StatementMetaData pData, SelectStatement pQuery)
protected String
getSelectQueryResultColumns(SelectStatement pQuery, StatementMetaData pData)
String
getStatementTerminator()
Returns the statement terminator.
protected String
getTableAlias(StatementMetaData pData, TableReference pTable)
protected String
getTypeName(Column.Type pType)
protected String
getUpdateQuery(UpdateStatement pQuery)
protected String
getValue(Value pValue)
String
getWhereClause(SelectStatement pQuery)
Returns the WHERE ...
protected 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 String
newStatement(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(String pLineTerminator)
Sets the line terminator.
void
setStatementTerminator(String pStatementTerminator)
Sets the statement terminator.

Method Details

createForeignKeyAsPartOfCreateTable

protected String createForeignKeyAsPartOfCreateTable(ForeignKey pKey)

createIndexAsPartOfCreateTable

protected String createIndexAsPartOfCreateTable(Index pIndex)

createPrimaryKeyAsPartOfCreateTable

protected String createPrimaryKeyAsPartOfCreateTable(Table pTable)

getBooleanConstraint

protected String getBooleanConstraint(StatementMetaData pData,
                                      BooleanConstraint pConstraint)

getBooleanConstraintPart

protected String getBooleanConstraintPart(StatementMetaData pData,
                                          Object o)

getBooleanConstraintType

protected String getBooleanConstraintType(BooleanConstraint.Type pType)

getCase

protected String getCase(StatementMetaData pData,
                         Case pCase)

getColumnAlias

protected String getColumnAlias(StatementMetaData pData,
                                ColumnReference pColumn)

getColumnAlias

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

getCombinedConstraint

protected String getCombinedConstraint(StatementMetaData pData,
                                       CombinedConstraint pConstraint)

getConstraint

public String getConstraint(Constraint pConstraint)
Generates the WHERE clause of a SELECT, UPDATE, or DELETE statement.
Specified by:
getConstraint in interface SQLGenerator

getConstraint

public String getConstraint(StatementMetaData pData,
                            Constraint pConstraint)

getCreate

protected String getCreate(Column pColumn)

getCreate

public Collection getCreate(ForeignKey pKey)
Generates a CREATE FOREIGN KEY statement.
Specified by:
getCreate in interface SQLGenerator

getCreate

public Collection getCreate(Index pIndex)
Generates a CREATE INDEX statement.
Specified by:
getCreate in interface SQLGenerator

getCreate

public Collection getCreate(Schema pSchema)
Generates a CREATE SCHEMA statement. Doesn't create CREATE TABLE or similar statements.
Specified by:
getCreate in interface SQLGenerator

getCreate

public Collection getCreate(Schema pSchema,
                            boolean pAll)
Generates CREATE statements for the schema.
Specified by:
getCreate in interface SQLGenerator
Parameters:
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.

getCreate

public Collection getCreate(Table pTable)
Generates a CREATE TABLE statement. Doesn't create CREATE INDEX or similar statements.
Specified by:
getCreate in interface SQLGenerator

getCreate

public Collection getCreate(Table pTable,
                            boolean pAll)
Generates CREATE statements for the table.
Specified by:
getCreate in interface SQLGenerator
Parameters:
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.

getCreateTableHeader

protected String getCreateTableHeader(Table pTable)

getDeleteQuery

protected String getDeleteQuery(DeleteStatement pQuery)

getDrop

public Collection getDrop(ForeignKey pKey)
Generates a DROP FOEIGN KEY statement.
Specified by:
getDrop in interface SQLGenerator

getDrop

public Collection getDrop(Index pIndex)
Generates a DROP INDEX statement.
Specified by:
getDrop in interface SQLGenerator

getDrop

public Collection getDrop(Schema pSchema)
Generates a DROP SCHEMA statement. Doesn't create DROP TABLE or similar statements.
Specified by:
getDrop in interface SQLGenerator

getDrop

public Collection getDrop(Schema pSchema,
                          boolean pAll)
Generates DROP statements for the schema.
Specified by:
getDrop in interface SQLGenerator
Parameters:
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.

getDrop

public Collection getDrop(Table pTable)
Generates a DROP TABLE statement. Doesn't create DROP INDEX or similar statements.
Specified by:
getDrop in interface SQLGenerator

getDrop

public Collection getDrop(Table pTable,
                          boolean pAll)
Generates DROP statements for the table.
Specified by:
getDrop in interface SQLGenerator
Parameters:
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.

getEscapedString

protected String getEscapedString(String s)

getExpression

protected String getExpression(StatementMetaData pData,
                               Expression pExpr)

getFunction

protected String getFunction(StatementMetaData pData,
                             Function f)

getIndent

protected String getIndent()

getInsertQuery

public String getInsertQuery(InsertStatement pQuery)

getJoinAlias

protected String getJoinAlias(StatementMetaData pData,
                              JoinReference pJoinReference)

getLineTerminator

public String getLineTerminator()
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

getOrderColumn

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

getParts

protected String getParts(StatementMetaData pData,
                          Iterator pParts)

getQuery

public String getQuery(Statement pStatement)
Generates an INSERT, UPDATE, DELETE or SELECT statement.
Specified by:
getQuery in interface SQLGenerator

getSelectQuery

protected String getSelectQuery(SelectStatement pQuery)

getSelectQuery

protected String getSelectQuery(SelectStatement pQuery,
                                StatementMetaData pData)

getSelectQueryConstraints

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

getSelectQueryFromClause

protected String getSelectQueryFromClause(SelectStatement pQuery,
                                          StatementMetaData pData)

getSelectQueryOrderClause

protected String getSelectQueryOrderClause(StatementMetaData pData,
                                           SelectStatement pQuery)

getSelectQueryResultColumns

protected String getSelectQueryResultColumns(SelectStatement pQuery,
                                             StatementMetaData pData)

getStatementTerminator

public String getStatementTerminator()
Returns the statement terminator. A non-null value will be appended to all generated statements. Defaults to null.
Specified by:
getStatementTerminator in interface SQLGenerator

getTableAlias

protected String getTableAlias(StatementMetaData pData,
                               TableReference pTable)

getTypeName

protected String getTypeName(Column.Type pType)

getUpdateQuery

protected String getUpdateQuery(UpdateStatement pQuery)

getValue

protected String getValue(Value pValue)

getWhereClause

public String getWhereClause(SelectStatement pQuery)
Returns the WHERE ... ORDER BY ... part of the SELECT statement.
Specified by:
getWhereClause in interface SQLGenerator

getWhereClause

protected String getWhereClause(StatementMetaData pData,
                                CombinedConstraint pWhereClause)

isForeignKeyPartOfCreateTable

protected boolean isForeignKeyPartOfCreateTable()
Returns whether a CREATE TABLE statement may contain a FOREIGN KEY clause.

isNonUniqueIndexPartOfCreateTable

protected boolean isNonUniqueIndexPartOfCreateTable()
Returns whether a CREATE TABLE statement may contain an INDEX clause.

isPrimaryKeyPartOfCreateTable

protected boolean isPrimaryKeyPartOfCreateTable()
Returns whether a CREATE TABLE statement may contain a PRIMARY KEY clause.

isPrimaryKeyUniqueIndex

protected boolean isPrimaryKeyUniqueIndex()

isQualifiedColumn

protected boolean isQualifiedColumn(StatementMetaData pData,
                                    ColumnReference pColumn)

isTableAliasUsingAs

protected boolean isTableAliasUsingAs()

isUniqueIndexPartOfCreateTable

protected boolean isUniqueIndexPartOfCreateTable()
Returns whether a CREATE TABLE statement may contain a UNIQUE clause.

newStatement

protected String newStatement(String pStatement)

newStatementMetaData

protected StatementMetaData newStatementMetaData(DeleteStatement pQuery)

newStatementMetaData

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

newStatementMetaData

protected StatementMetaData newStatementMetaData(SelectStatement pQuery)

newStatementMetaData

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

setLineTerminator

public void setLineTerminator(String pLineTerminator)
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

setStatementTerminator

public void setStatementTerminator(String pStatementTerminator)
Sets the statement terminator. A non-null value will be appended to all generated statements. Defaults to null.
Specified by:
setStatementTerminator in interface SQLGenerator