ca.sqlpower.architect.ddl
Interface DDLGenerator

All Known Implementing Classes:
DB2DDLGenerator, GenericDDLGenerator, HSQLDBDDLGenerator, MySqlDDLGenerator, OracleDDLGenerator, PostgresDDLGenerator, SQLServer2000DDLGenerator, SQLServer2005DDLGenerator, SQLServerDDLGenerator

public interface DDLGenerator

The DDLGenerator interface is a generic API for turning a SQLObject hierarchy into a series of SQL statements which create the corresponding data model in a physical database.

Version:
$Id: DDLGenerator.java 2409 2008-07-22 22:18:35Z Kevin1219 $
Author:
fuerth

Method Summary
 void addColumn(SQLColumn c)
          Appends the DDL statement for adding the given column to its parent table in this DDL Generator's target schema/catalog.
 void addIndex(SQLIndex idx)
          Appends the DDL statements for creating the given index this DDL Generator's current catalog and schema.
 void addPrimaryKey(SQLTable t)
           
 void addRelationship(SQLRelationship r)
          Appends the DDL statement for creating the given FK relationship in this DDL Generator's target schema/catalog.
 void addTable(SQLTable t)
          Appends the DDL statements for creating a table in this DDL Generator's current catalog and schema using SQLTable t as a template.
 java.lang.String columnType(SQLColumn col)
          get the datatype with scale and percision of the column, example: "decimal(10,5)"
 void dropColumn(SQLColumn c)
          Appends the DDL statement for dropping the given column from its parent table in this DDL Generator's target schema/catalog.
 void dropPrimaryKey(SQLTable t)
           
 void dropRelationship(SQLRelationship r)
          Appends the DDL statement for dropping the given FK relationship in this DDL Generator's target schema/catalog.
 void dropTable(SQLTable t)
          Appends the DDL statements for dropping the table in this DDL Generator's current catalog and schema using SQLTable t's physical name.
 java.lang.String generateDDLScript(java.util.Collection<SQLTable> tables)
          Generates the series of DDL Statements as in generateDDLStatements(Collection), then compiles them into a formatted script complete with statement terminators and transaction start and end statements (if supported by the target platform).
 java.util.List<DDLStatement> generateDDLStatements(java.util.Collection<SQLTable> tables)
          Creates a list of DDLStatement objects which create all of the tables, their columns and primary keys, and the foreign key relationships of the given database.
 boolean getAllowConnection()
          Tells the generator whether or not it can connect to the target database and ask for additional information during the generation process.
 java.lang.String getCatalogTerm()
          The name that the target database gives to the JDBC idea of "catalog." For Oracle, this would be null (no catalogs) and for SQL Server it would be "Database".
 java.util.List<DDLStatement> getDdlStatements()
          Returns the list of DDL statements that have been created so far.
 java.lang.String getName()
          Returns the name of this DDL Generator, which should be a human-readable string with the vendor and/or product name (and version if the generator doesn't work with all versions) of the database platform this generator targets.
 java.lang.String getSchemaTerm()
          The name that the target database gives to the JDBC idea of "schema." For Oracle, this would be "Schema" and for SQL Server it would be "Owner".
 java.lang.String getStatementTerminator()
          Returns the string that should be used at the end of each statement.
 java.lang.String getTargetCatalog()
          See #targetCatalog.
 java.lang.String getTargetSchema()
          See #targetSchema.
 java.util.Map getTypeMap()
          Gets the value of typeMap
 java.util.List getWarnings()
          Returns #warnings.
 boolean isReservedWord(java.lang.String word)
          Check to see if the word word is on the list of reserved words for this database
 java.lang.String makeDropForeignKeySQL(java.lang.String fkTable, java.lang.String fkName)
          Creates and returns a DDL statement which will drop a foreign key relationship in this DDL Generator's current catalog and schema.
 java.lang.String makeDropTableSQL(java.lang.String table)
          Creates and returns a DDL statement which will drop the given table in this DDL Generator's current catalog and schema.
 void modifyColumn(SQLColumn c)
          Appends the DDL statement for modifying the given column's datatype and nullability in its parent table in this DDL Generator's target schema/catalog.
 void setAllowConnection(boolean argAllowConnection)
          See getAllowConnection().
 void setTargetCatalog(java.lang.String argTargetCatalog)
          See #targetCatalog.
 void setTargetSchema(java.lang.String argTargetSchema)
          See #targetSchema.
 void setTypeMap(java.util.Map argTypeMap)
          Sets the value of typeMap
 boolean supportsRollback()
          Returns true if this DDL generator supports the rollback operation to return the database to some previous state.
 java.lang.String toIdentifier(java.lang.String name)
          Converts an arbitrary string (which may contain spaces, mixed case, punctuation, and so on) into a valid identifier in the target database system.
 

Method Detail

getName

java.lang.String getName()
Returns the name of this DDL Generator, which should be a human-readable string with the vendor and/or product name (and version if the generator doesn't work with all versions) of the database platform this generator targets.


generateDDLStatements

java.util.List<DDLStatement> generateDDLStatements(java.util.Collection<SQLTable> tables)
                                                   throws java.sql.SQLException,
                                                          ArchitectException
Creates a list of DDLStatement objects which create all of the tables, their columns and primary keys, and the foreign key relationships of the given database.

Parameters:
source - The database to generate a DDL representation of.
Returns:
The list of DDL statements that can create the given database, in the order they should be executed.
Throws:
java.sql.SQLException - If there is a problem getting type info from the target DB.
ArchitectException - If there are problems with the Architect objects.

generateDDLScript

java.lang.String generateDDLScript(java.util.Collection<SQLTable> tables)
                                   throws java.sql.SQLException,
                                          ArchitectException
Generates the series of DDL Statements as in generateDDLStatements(Collection), then compiles them into a formatted script complete with statement terminators and transaction start and end statements (if supported by the target platform). This script is appropriate to feed into a target database using a vendor-supplied tool for executing SQL scripts.

Parameters:
tables - The collection of tables the generated script should create.
Returns:
The String representation of the generated DDL script.
Throws:
java.sql.SQLException - If there is a problem getting type info from the target DB.
ArchitectException - If there are problems with the Architect objects.

dropColumn

void dropColumn(SQLColumn c)
Appends the DDL statement for dropping the given column from its parent table in this DDL Generator's target schema/catalog.

Parameters:
c - The column to create a DROP statement for.

addColumn

void addColumn(SQLColumn c)
Appends the DDL statement for adding the given column to its parent table in this DDL Generator's target schema/catalog.

Parameters:
c - The column to create a ADD statement for.

modifyColumn

void modifyColumn(SQLColumn c)
Appends the DDL statement for modifying the given column's datatype and nullability in its parent table in this DDL Generator's target schema/catalog.

Parameters:
c - The column to create a MODIFY or ALTER COLUMN statement for.

addRelationship

void addRelationship(SQLRelationship r)
Appends the DDL statement for creating the given FK relationship in this DDL Generator's target schema/catalog.

Parameters:
c - The relationship to create a FOREIGN KEY statement for.

dropRelationship

void dropRelationship(SQLRelationship r)
Appends the DDL statement for dropping the given FK relationship in this DDL Generator's target schema/catalog.

Parameters:
c - The relationship to create a DROP FOREIGN KEY statement for.

dropTable

void dropTable(SQLTable t)
Appends the DDL statements for dropping the table in this DDL Generator's current catalog and schema using SQLTable t's physical name.


addTable

void addTable(SQLTable t)
              throws java.sql.SQLException,
                     ArchitectException
Appends the DDL statements for creating a table in this DDL Generator's current catalog and schema using SQLTable t as a template.

Throws:
java.sql.SQLException
ArchitectException

addIndex

void addIndex(SQLIndex idx)
              throws ArchitectException
Appends the DDL statements for creating the given index this DDL Generator's current catalog and schema.

Throws:
ArchitectException

getDdlStatements

java.util.List<DDLStatement> getDdlStatements()
Returns the list of DDL statements that have been created so far. Call generateDDLStatements(Collection) to populate this list.


toIdentifier

java.lang.String toIdentifier(java.lang.String name)
Converts an arbitrary string (which may contain spaces, mixed case, punctuation, and so on) into a valid identifier in the target database system. The implementation should mangle the input string to the minimum degree necessary to make the given string into a valid identifier on the target system.


makeDropTableSQL

java.lang.String makeDropTableSQL(java.lang.String table)
Creates and returns a DDL statement which will drop the given table in this DDL Generator's current catalog and schema.

Parameters:
table - The name of the table to be dropped.
Returns:
A SQL statement which will drop the table.

makeDropForeignKeySQL

java.lang.String makeDropForeignKeySQL(java.lang.String fkTable,
                                       java.lang.String fkName)
Creates and returns a DDL statement which will drop a foreign key relationship in this DDL Generator's current catalog and schema.

Parameters:
fkTable - The name of the FK table whose relationship should be dropped.
fkName - The name of the key to drop.
Returns:
a SQL statement which will drop the key.

getAllowConnection

boolean getAllowConnection()
Tells the generator whether or not it can connect to the target database and ask for additional information during the generation process. For instance, to populate the type map.


setAllowConnection

void setAllowConnection(boolean argAllowConnection)
See getAllowConnection().


getTypeMap

java.util.Map getTypeMap()
Gets the value of typeMap

Returns:
the value of typeMap

setTypeMap

void setTypeMap(java.util.Map argTypeMap)
Sets the value of typeMap

Parameters:
argTypeMap - Value to assign to this.typeMap

getWarnings

java.util.List getWarnings()
Returns #warnings.


getTargetCatalog

java.lang.String getTargetCatalog()
See #targetCatalog.

Returns:
the value of targetCatalog

setTargetCatalog

void setTargetCatalog(java.lang.String argTargetCatalog)
See #targetCatalog.

Parameters:
argTargetCatalog - Value to assign to this.targetCatalog

getTargetSchema

java.lang.String getTargetSchema()
See #targetSchema.

Returns:
the value of targetSchema

setTargetSchema

void setTargetSchema(java.lang.String argTargetSchema)
See #targetSchema.

Parameters:
argTargetSchema - Value to assign to this.targetSchema

getCatalogTerm

java.lang.String getCatalogTerm()
The name that the target database gives to the JDBC idea of "catalog." For Oracle, this would be null (no catalogs) and for SQL Server it would be "Database".


getSchemaTerm

java.lang.String getSchemaTerm()
The name that the target database gives to the JDBC idea of "schema." For Oracle, this would be "Schema" and for SQL Server it would be "Owner".


dropPrimaryKey

void dropPrimaryKey(SQLTable t)

addPrimaryKey

void addPrimaryKey(SQLTable t)
                   throws ArchitectException
Throws:
ArchitectException

getStatementTerminator

java.lang.String getStatementTerminator()
Returns the string that should be used at the end of each statement. For many platforms, this is a semicolon.


isReservedWord

boolean isReservedWord(java.lang.String word)
Check to see if the word word is on the list of reserved words for this database

Returns:

columnType

java.lang.String columnType(SQLColumn col)
get the datatype with scale and percision of the column, example: "decimal(10,5)"

Parameters:
col -
Returns:

supportsRollback

boolean supportsRollback()
Returns true if this DDL generator supports the rollback operation to return the database to some previous state.



Copyright © 2003-2007 SQL Power Group Inc. www.sqlpower.ca