net.sf.jaxme.sqls.impl
Class SQLGeneratorImpl

java.lang.Object
  extended bynet.sf.jaxme.sqls.impl.SQLGeneratorImpl
All Implemented Interfaces:
SQLGenerator
Direct Known Subclasses:
DB2SQLGeneratorImpl, HsqlDbSQLGeneratorImpl

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(BooleanConstraint pConstraint)
           
protected  java.lang.String getBooleanConstraintPart(java.lang.Object o)
           
protected  java.lang.String getBooleanConstraintType(BooleanConstraint.Type pType)
           
protected  java.lang.String getColumnAlias(ColumnReference pColumn)
           
protected  java.lang.String getColumnAlias(ColumnReference[] pColumn)
           
protected  java.lang.String getCombinedConstraint(CombinedConstraint pConstraint)
           
 java.lang.String getConstraint(Constraint pConstraint)
          Generates a part of a WHERE clause.
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 getIndent()
           
 java.lang.String getInsertQuery(InsertStatement pQuery)
           
protected  java.lang.String getJoinAlias(JoinReference pJoinReference)
           
 java.lang.String getLineTerminator()
          Returns the line terminator.
 java.lang.String getQuery(Statement pStatement)
          Generates an INSERT, UPDATE, DELETE or SELECT statement.
protected  java.lang.String getSelectQuery(SelectStatement pQuery)
           
 java.lang.String getStatementTerminator()
          Returns the statement terminator.
protected  java.lang.String getTableAlias(TableReference pTable)
           
protected  java.lang.String getTypeName(Column.Type pType)
           
protected  java.lang.String getUpdateQuery(UpdateStatement pQuery)
           
protected  java.lang.String getValue(Value pValue)
           
protected  java.lang.String getWhereClause(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 isUniqueIndexPartOfCreateTable()
          Returns whether a CREATE TABLE statement may contain a UNIQUE clause.
protected  java.lang.String newStatement(java.lang.String pStatement)
           
 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)

getColumnAlias

protected java.lang.String getColumnAlias(ColumnReference pColumn)

getColumnAlias

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

getTableAlias

protected java.lang.String getTableAlias(TableReference pTable)

getJoinAlias

protected java.lang.String getJoinAlias(JoinReference pJoinReference)

getEscapedString

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

getBooleanConstraintPart

protected java.lang.String getBooleanConstraintPart(java.lang.Object o)

getBooleanConstraintType

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

getBooleanConstraint

protected java.lang.String getBooleanConstraint(BooleanConstraint pConstraint)

getCombinedConstraint

protected java.lang.String getCombinedConstraint(CombinedConstraint pConstraint)

getConstraint

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

Generates a part of a WHERE clause.

Specified by:
getConstraint in interface SQLGenerator

getWhereClause

protected java.lang.String getWhereClause(CombinedConstraint pWhereClause)

getSelectQuery

protected java.lang.String getSelectQuery(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
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.


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
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.


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
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.


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
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.


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