org.apache.empire.db
Class DBDDLGenerator<T extends DBDatabaseDriver>

java.lang.Object
  extended by org.apache.empire.db.DBDDLGenerator<T>
Direct Known Subclasses:
DerbyDDLGenerator, H2DDLGenerator, HSqlDDLGenerator, MSSqlDDLGenerator, MySQLDDLGenerator, OracleDDLGenerator, PostgreDDLGenerator, SQLiteDDLGenerator

public abstract class DBDDLGenerator<T extends DBDatabaseDriver>
extends Object


Field Summary
protected  String alterColumnPhrase
           
protected  String databaseObjectName
           
protected  String DATATYPE_BLOB
           
protected  String DATATYPE_BOOLEAN
           
protected  String DATATYPE_CHAR
           
protected  String DATATYPE_CLOB
           
protected  String DATATYPE_DATE
           
protected  String DATATYPE_DECIMAL
           
protected  String DATATYPE_FLOAT
           
protected  String DATATYPE_INT_BIG
           
protected  String DATATYPE_INT_SMALL
           
protected  String DATATYPE_INTEGER
           
protected  String DATATYPE_TIMESTAMP
           
protected  String DATATYPE_UNIQUEID
           
protected  String DATATYPE_VARCHAR
           
protected  T driver
           
protected  boolean namePrimaryKeyConstraint
           
 
Constructor Summary
protected DBDDLGenerator(T driver)
           
 
Method Summary
protected  void addAlterTableStmt(DBColumn col, StringBuilder sql, DBSQLScript script)
           
protected  void addCreateIndexStmt(DBIndex index, StringBuilder sql, DBSQLScript script)
           
protected  void addCreateRelationStmt(DBRelation rel, StringBuilder sql, DBSQLScript script)
           
protected  void addCreateTableStmt(DBTable table, StringBuilder sql, DBSQLScript script)
           
protected  void addCreateViewStmt(DBView v, StringBuilder sql, DBSQLScript script)
           
protected  void alterTable(DBTableColumn col, DBCmdType type, DBSQLScript script)
          Appends the DDL-Script for altering a table to an SQL-Script
protected  boolean appendColumnDataType(DataType type, double size, DBTableColumn c, StringBuilder sql)
          appends the data type of a column
protected  void appendColumnDesc(DBTableColumn c, boolean alter, StringBuilder sql)
          Appends a table column definition to a ddl statement
protected  void appendElementName(StringBuilder sql, String name)
           
protected  void createDatabase(DBDatabase db, DBSQLScript script)
          Appends the DDL-Script for creating the given database to an SQL-Script
This includes the generation of all tables, views and relations.
protected  void createIndex(DBTable t, DBIndex idx, DBSQLScript script)
          Appends the DDL-Script for creating a single index to an SQL-Script
protected  void createRelation(DBRelation r, DBSQLScript script)
          Appends the DDL-Script for creating the given foreign-key relation to an SQL-Script
protected  void createTable(DBTable t, DBSQLScript script)
          Appends the DDL-Script for creating the given table to an SQL-Script
protected  void createTableIndexes(DBTable t, DBIndex pk, DBSQLScript script)
          Appends the DDL-Script for creating all indexes of table (except the primary key) to an SQL-Script
protected  void createView(DBView v, DBSQLScript script)
          Appends the DDL-Script for creating the given view to an SQL-Script
protected  boolean detectQuoteName(String name)
           
protected  void dropDatabase(DBDatabase db, DBSQLScript script)
          Appends the DDL-Script for dropping a database to the given script object
protected  void dropObject(String name, String objType, DBSQLScript script)
          Appends the DDL-Script for dropping a database object to an SQL-Script
 void getDDLScript(DBCmdType type, DBObject dbo, DBSQLScript script)
          Appends the required DLL commands to create, drop or alter an object to the supplied DBDQLScript.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

driver

protected T extends DBDatabaseDriver driver

DATATYPE_INT_SMALL

protected String DATATYPE_INT_SMALL

DATATYPE_INTEGER

protected String DATATYPE_INTEGER

DATATYPE_INT_BIG

protected String DATATYPE_INT_BIG

DATATYPE_CHAR

protected String DATATYPE_CHAR

DATATYPE_VARCHAR

protected String DATATYPE_VARCHAR

DATATYPE_DATE

protected String DATATYPE_DATE

DATATYPE_TIMESTAMP

protected String DATATYPE_TIMESTAMP

DATATYPE_BOOLEAN

protected String DATATYPE_BOOLEAN

DATATYPE_DECIMAL

protected String DATATYPE_DECIMAL

DATATYPE_FLOAT

protected String DATATYPE_FLOAT

DATATYPE_CLOB

protected String DATATYPE_CLOB

DATATYPE_BLOB

protected String DATATYPE_BLOB

DATATYPE_UNIQUEID

protected String DATATYPE_UNIQUEID

namePrimaryKeyConstraint

protected boolean namePrimaryKeyConstraint

alterColumnPhrase

protected String alterColumnPhrase

databaseObjectName

protected String databaseObjectName
Constructor Detail

DBDDLGenerator

protected DBDDLGenerator(T driver)
Method Detail

addCreateTableStmt

protected void addCreateTableStmt(DBTable table,
                                  StringBuilder sql,
                                  DBSQLScript script)

addCreateIndexStmt

protected void addCreateIndexStmt(DBIndex index,
                                  StringBuilder sql,
                                  DBSQLScript script)

addCreateRelationStmt

protected void addCreateRelationStmt(DBRelation rel,
                                     StringBuilder sql,
                                     DBSQLScript script)

addCreateViewStmt

protected void addCreateViewStmt(DBView v,
                                 StringBuilder sql,
                                 DBSQLScript script)

addAlterTableStmt

protected void addAlterTableStmt(DBColumn col,
                                 StringBuilder sql,
                                 DBSQLScript script)

appendColumnDataType

protected boolean appendColumnDataType(DataType type,
                                       double size,
                                       DBTableColumn c,
                                       StringBuilder sql)
appends the data type of a column

Parameters:
type - the type
size - the size
sql - the builder that we will append to
Returns:
true if further column attributes may be added or false otherwise

appendColumnDesc

protected void appendColumnDesc(DBTableColumn c,
                                boolean alter,
                                StringBuilder sql)
Appends a table column definition to a ddl statement

Parameters:
c - the column which description to append
alter - true if altering an existing column or false otherwise
sql - the sql builder object

getDDLScript

public void getDDLScript(DBCmdType type,
                         DBObject dbo,
                         DBSQLScript script)
Appends the required DLL commands to create, drop or alter an object to the supplied DBDQLScript.

Parameters:
type - operation to perform (CREATE, DROP, ALTER)
dbo - the object for which to perform the operation (DBDatabase, DBTable, DBView, DBColumn, DBRelation)
script - the script to which to add the DDL command(s)

createDatabase

protected void createDatabase(DBDatabase db,
                              DBSQLScript script)
Appends the DDL-Script for creating the given database to an SQL-Script
This includes the generation of all tables, views and relations.

Parameters:
db - the database to create
script - the sql script to which to append the dll command(s)

dropDatabase

protected void dropDatabase(DBDatabase db,
                            DBSQLScript script)
Appends the DDL-Script for dropping a database to the given script object

Parameters:
db - the database to drop
script - the sql script to which to append the dll command(s)

createTable

protected void createTable(DBTable t,
                           DBSQLScript script)
Appends the DDL-Script for creating the given table to an SQL-Script

Parameters:
t - the table to create
script - the sql script to which to append the dll command(s)

createTableIndexes

protected void createTableIndexes(DBTable t,
                                  DBIndex pk,
                                  DBSQLScript script)
Appends the DDL-Script for creating all indexes of table (except the primary key) to an SQL-Script

Parameters:
t - the table to create
pk - the primary key index to ignore
script - the sql script to which to append the dll command(s)

createIndex

protected void createIndex(DBTable t,
                           DBIndex idx,
                           DBSQLScript script)
Appends the DDL-Script for creating a single index to an SQL-Script

Parameters:
t - the table
idx - the index to create
script - the sql script to which to append the dll command(s)

createRelation

protected void createRelation(DBRelation r,
                              DBSQLScript script)
Appends the DDL-Script for creating the given foreign-key relation to an SQL-Script

Parameters:
r - the relation to create
script - the sql script to which to append the dll command(s)

alterTable

protected void alterTable(DBTableColumn col,
                          DBCmdType type,
                          DBSQLScript script)
Appends the DDL-Script for altering a table to an SQL-Script

Parameters:
col - the column which to add, modify or drop
type - the type of operation to perform (CREATE | MODIFY | DROP)
script - the sql script to which to append the dll command(s)

createView

protected void createView(DBView v,
                          DBSQLScript script)
Appends the DDL-Script for creating the given view to an SQL-Script

Parameters:
v - the view to create
script - the sql script to which to append the dll command(s)

dropObject

protected void dropObject(String name,
                          String objType,
                          DBSQLScript script)
Appends the DDL-Script for dropping a database object to an SQL-Script

Parameters:
name - the name of the object to delete
objType - the type of object to delete (TABLE, COLUMN, VIEW, RELATION, etc)
script - the sql script to which to append the dll command(s)

detectQuoteName

protected boolean detectQuoteName(String name)

appendElementName

protected void appendElementName(StringBuilder sql,
                                 String name)


Copyright © 2008–2014 Apache Software Foundation. All rights reserved.