|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectca.sqlpower.architect.ddl.GenericDDLGenerator
public class GenericDDLGenerator
| Field Summary | |
|---|---|
protected boolean |
allowConnection
This property says whether or not the user will allow us to connect to the target system in order to determine database meta-data. |
protected java.sql.Connection |
con
This variable will be a live, non-null connection to the target database (set up by writeDDL) if allowConnection is true. |
protected static java.lang.String |
EOL
This is initialized to the System line.separator property. |
static java.lang.String |
GENERATOR_VERSION
|
protected java.util.Map<java.lang.String,ProfileFunctionDescriptor> |
profileFunctionMap
A mapping from JDBC type code (Integer values) to appliable profile functions (min,max,avg,sum,etc...) |
protected java.lang.String |
targetCatalog
The name of the catalog in the target database that the generated DDL statements should create the objects in. |
protected java.lang.String |
targetSchema
The name of the schema in the target database that the generated DDL statements should create the objects in. |
protected java.util.Map<java.lang.String,SQLObject> |
topLevelNames
As table and relationship creation statements are generated, their SQL identifiers are stored in this map (key is name, value is object having that name). |
protected java.util.Map |
typeMap
A mapping from JDBC type code (Integer values) to GenericTypeDescriptor objects which describe that data type. |
protected java.util.List |
warnings
This list contains 0 or more NameChangeWarning objects. |
| Constructor Summary | |
|---|---|
GenericDDLGenerator()
|
|
| 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 index)
Adds a DDL statement to this generator that will create the given index. |
void |
addPrimaryKey(SQLTable t)
|
protected void |
addPrimaryKeysToCreateTable(SQLTable t)
|
void |
addRelationship(SQLRelationship r)
Adds a statement for creating the given foreign key relationship in the target database. |
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. |
protected java.lang.String |
columnDefinition(SQLColumn c,
java.util.Map colNameMap)
Creates a SQL DDL snippet which consists of the column name, data type, default value, and nullability clauses. |
protected java.lang.String |
columnNullability(SQLColumn c)
|
java.lang.String |
columnType(SQLColumn c)
Columnn type |
protected java.lang.String |
createPhysicalName(java.util.Map<java.lang.String,SQLObject> dupCheck,
SQLObject so)
Generate, set, and return a valid identifier for this SQLObject. |
protected java.lang.String |
createSeqPhysicalName(java.util.Map<java.lang.String,SQLObject> dupCheck,
SQLSequence seq,
SQLColumn col)
Generate, set, and return a valid identifier for this SQLSequence. |
protected void |
createTypeMap()
Creates and populates typeMap using
DatabaseMetaData. |
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. |
void |
endStatement(DDLStatement.StatementType type,
SQLObject sqlObject)
Stores all the ddl since the last call to endStatement as a SQL statement. |
protected GenericTypeDescriptor |
failsafeGetTypeDescriptor(SQLColumn c)
Returns the type descriptor for the given column's type if that exists in this generator's typemap, else returns the default type. |
java.lang.String |
generateDDLScript(java.util.Collection<SQLTable> tables)
Generates the series of DDL Statements as in DDLGenerator.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 series of SQL DDL statements which will create the given list of tables in a target database. |
boolean |
getAllowConnection()
Gets the value of allowConnection |
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.lang.String |
getColumnDataTypeName(SQLColumn c)
Columnn type |
java.sql.Connection |
getCon()
Gets the value of con |
java.util.List<DDLStatement> |
getDdlStatements()
Returns the list of DDL statements that have been created so far. |
protected java.lang.Object |
getDefaultType()
Returns the default data type for this platform. |
java.lang.String |
getDeferrabilityClause(SQLRelationship r)
Returns the correct syntax for setting the deferrability of a foreign key relationship on this DDL Generator's target platform. |
java.lang.String |
getDeleteActionClause(SQLRelationship r)
Returns the ON DELETE clause for the given relationship, with no extra whitespace or newline characters around it. |
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.util.Map<java.lang.String,ProfileFunctionDescriptor> |
getProfileFunctionMap()
|
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()
Prints a single semicolon character (no newline). |
java.lang.String |
getTargetCatalog()
See targetCatalog. |
java.lang.String |
getTargetSchema()
See targetSchema. |
java.util.Map |
getTypeMap()
Gets the value of typeMap |
java.lang.String |
getUpdateActionClause(SQLRelationship r)
Returns the ON UPDATE clause for the given relationship, with no extra whitespace or newline characters around it. |
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)
Generates a command for dropping a foreign key which works on some platforms. |
java.lang.String |
makeDropTableSQL(java.lang.String table)
Generates a standard DROP TABLE $tablename command. |
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. |
protected void |
print(java.lang.String text)
|
protected void |
println(java.lang.String text)
|
void |
setAllowConnection(boolean argAllowConnection)
Sets the value of allowConnection |
void |
setCon(java.sql.Connection argCon)
Sets the value of con |
void |
setProfileFunctionMap(java.util.Map profileFunctionMap)
|
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 |
supportsDeferrabilityPolicy(SQLRelationship r)
Returns true if the platform supports the deferrability policy of the given relationship, false otherwise. |
boolean |
supportsDeleteAction(SQLRelationship r)
Returns true if this DDL generator supports the given relationship's delete action. |
boolean |
supportsRollback()
The generic DDL generator claims to support rollback operation, so specific platforms that don't support it should override this method. |
boolean |
supportsUpdateAction(SQLRelationship r)
Returns true if this DDL generator supports the given relationship's update action. |
java.lang.String |
toIdentifier(java.lang.String name)
Converts space to underscore in name and returns
the possibly-modified string. |
java.lang.String |
toQualifiedName(SQLIndex i)
Creates a qualified name from the physical name of the SQLIndex |
java.lang.String |
toQualifiedName(SQLTable t)
Creates a fully-qualified table name from the given table's phyiscal name and this DDL Generator's current target schema and catalog. |
java.lang.String |
toQualifiedName(java.lang.String tname)
Creates a fully-qualified table name from the given string (which is the non-qualified table name) and this DDL Generator's current target schema and catalog. |
void |
writeCreateDB(SQLDatabase db)
|
void |
writeDDLTransactionBegin()
Does nothing. |
void |
writeDDLTransactionEnd()
Does nothing. |
protected void |
writeExportedRelationships(SQLTable t)
Adds statements for creating every exported key in the given table. |
void |
writeHeader()
|
protected void |
writePrimaryKey(SQLTable t)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String GENERATOR_VERSION
protected boolean allowConnection
protected static final java.lang.String EOL
protected java.util.Map typeMap
protected java.sql.Connection con
protected java.util.Map<java.lang.String,SQLObject> topLevelNames
protected java.util.List warnings
NameChangeWarning objects. It is
populated as statements are added to the
ddlStatements list. If non-empty, this list of
warnings should be presented to the user before the generated
DDL is saved or executed (to give them a chance to fix the
warnings and try again).
protected java.lang.String targetCatalog
null as well as override getCatalogTerm()
to return null.
protected java.lang.String targetSchema
null as well as override getSchemaTerm()
to return null.
protected java.util.Map<java.lang.String,ProfileFunctionDescriptor> profileFunctionMap
| Constructor Detail |
|---|
public GenericDDLGenerator()
throws java.sql.SQLException
java.sql.SQLException| Method Detail |
|---|
public java.lang.String getName()
DDLGenerator
getName in interface DDLGeneratorpublic boolean isReservedWord(java.lang.String word)
isReservedWord in interface DDLGenerator
public java.lang.String generateDDLScript(java.util.Collection<SQLTable> tables)
throws java.sql.SQLException,
ArchitectException
DDLGeneratorDDLGenerator.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.
generateDDLScript in interface DDLGeneratortables - The collection of tables the generated script should create.
java.sql.SQLException - If there is a problem getting type info from the target DB.
ArchitectException - If there are problems with the Architect objects.
public final java.util.List<DDLStatement> generateDDLStatements(java.util.Collection<SQLTable> tables)
throws java.sql.SQLException,
ArchitectException
generateDDLStatements in interface DDLGeneratortables - the tables the generated script should create.
java.sql.SQLException - If there is a problem getting type info from the target DB.
ArchitectException - If there are problems with the Architect objects.DDLGenerator.generateDDLStatements(Collection)
public final void endStatement(DDLStatement.StatementType type,
SQLObject sqlObject)
type - the type of statementsqlObject - the object to which the statement pertainspublic void writeHeader()
public java.lang.String getStatementTerminator()
getStatementTerminator in interface DDLGeneratorpublic void writeDDLTransactionBegin()
public void writeDDLTransactionEnd()
public void writeCreateDB(SQLDatabase db)
public void dropRelationship(SQLRelationship r)
DDLGenerator
dropRelationship in interface DDLGeneratorpublic void addRelationship(SQLRelationship r)
getDeferrabilityClause(SQLRelationship)
method for the target database's way of describing the deferrability policy.
addRelationship in interface DDLGeneratorpublic boolean supportsDeleteAction(SQLRelationship r)
public java.lang.String getDeleteActionClause(SQLRelationship r)
If you are overriding this method for a platform-specific DDL generator and you need this clause to be empty, return the empty string--not null.
r - The relationship whose delete action clause to generate
public boolean supportsUpdateAction(SQLRelationship r)
public java.lang.String getUpdateActionClause(SQLRelationship r)
If you are overriding this method for a platform-specific DDL generator and you need this clause to be empty, return the empty string--not null.
r - The relationship whose update action clause to generate
public java.lang.String getDeferrabilityClause(SQLRelationship r)
UnsupportedOperationException if the platform does not
support the given relationship's deferrability policy.
r - The relationship the deferrability clause is for
public boolean supportsDeferrabilityPolicy(SQLRelationship r)
public void addColumn(SQLColumn c)
DDLGenerator
addColumn in interface DDLGeneratorc - The column to create a ADD statement for.public void dropColumn(SQLColumn c)
DDLGenerator
dropColumn in interface DDLGeneratorc - The column to create a DROP statement for.public void modifyColumn(SQLColumn c)
DDLGenerator
modifyColumn in interface DDLGeneratorc - The column to create a MODIFY or ALTER COLUMN statement for.public void dropTable(SQLTable t)
DDLGenerator
dropTable in interface DDLGenerator
protected java.lang.String columnDefinition(SQLColumn c,
java.util.Map colNameMap)
c - The column to generate the DDL snippet for.colNameMap - Dirty hack for coming up with unique physical names.
The final physical name generated in the SQL snippet will be stored
in this map. If you don't care about producing unique column names, just
pass in a freshly-created map. See createPhysicalName(Map, SQLObject)
for more information.
protected java.lang.String columnNullability(SQLColumn c)
public java.lang.String columnType(SQLColumn c)
columnType in interface DDLGeneratorpublic java.lang.String getColumnDataTypeName(SQLColumn c)
protected GenericTypeDescriptor failsafeGetTypeDescriptor(SQLColumn c)
public void addTable(SQLTable t)
throws java.sql.SQLException,
ArchitectException
DDLGenerator
addTable in interface DDLGeneratorjava.sql.SQLException
ArchitectExceptionprotected java.lang.Object getDefaultType()
protected void addPrimaryKeysToCreateTable(SQLTable t)
throws ArchitectException
ArchitectException
protected void writePrimaryKey(SQLTable t)
throws ArchitectException
ArchitectException
protected void writeExportedRelationships(SQLTable t)
throws ArchitectException
ArchitectException
protected void createTypeMap()
throws java.sql.SQLException
typeMap using
DatabaseMetaData. Subclasses for specific DB platforms will be
able to override this implementation with one that uses a
static, pre-defined type map.
java.sql.SQLExceptionprotected void println(java.lang.String text)
protected void print(java.lang.String text)
public java.lang.String toIdentifier(java.lang.String name)
name and returns
the possibly-modified string. This will not be completely
sufficient because it leaves ".", "%", and lots of other
non-alphanumeric characters alone. Subclasses might choose to
quote and leave everything alone, or whatever.
toIdentifier in interface DDLGeneratorpublic java.lang.String toQualifiedName(SQLTable t)
t - The table whose name to qualify. The parents of this table are
disregarded; only the DDL Generator's target schema and catalog matter.
public java.lang.String toQualifiedName(SQLIndex i)
public java.lang.String toQualifiedName(java.lang.String tname)
tname - The table name to qualify. Must not contain the name separator
character (usually '.').
public boolean getAllowConnection()
getAllowConnection in interface DDLGeneratorpublic void setAllowConnection(boolean argAllowConnection)
setAllowConnection in interface DDLGeneratorargAllowConnection - Value to assign to this.allowConnectionpublic java.util.Map getTypeMap()
getTypeMap in interface DDLGeneratorpublic void setTypeMap(java.util.Map argTypeMap)
setTypeMap in interface DDLGeneratorargTypeMap - Value to assign to this.typeMappublic java.util.Map<java.lang.String,ProfileFunctionDescriptor> getProfileFunctionMap()
public void setProfileFunctionMap(java.util.Map profileFunctionMap)
public java.sql.Connection getCon()
public void setCon(java.sql.Connection argCon)
argCon - Value to assign to this.conpublic java.util.List getWarnings()
warnings.
getWarnings in interface DDLGeneratorpublic java.lang.String getTargetCatalog()
targetCatalog.
getTargetCatalog in interface DDLGeneratorpublic void setTargetCatalog(java.lang.String argTargetCatalog)
targetCatalog.
setTargetCatalog in interface DDLGeneratorargTargetCatalog - Value to assign to this.targetCatalogpublic java.lang.String getTargetSchema()
targetSchema.
getTargetSchema in interface DDLGeneratorpublic void setTargetSchema(java.lang.String argTargetSchema)
targetSchema.
setTargetSchema in interface DDLGeneratorargTargetSchema - Value to assign to this.targetSchemapublic java.lang.String getCatalogTerm()
getCatalogTerm in interface DDLGeneratorpublic java.lang.String getSchemaTerm()
getSchemaTerm in interface DDLGenerator
protected java.lang.String createPhysicalName(java.util.Map<java.lang.String,SQLObject> dupCheck,
SQLObject so)
ArchitectException
protected java.lang.String createSeqPhysicalName(java.util.Map<java.lang.String,SQLObject> dupCheck,
SQLSequence seq,
SQLColumn col)
dupCheck - The Map to check for duplicate namesseq - The SQLSequence to generate, set and return a valid identifier for.col - The SQLColumn to where the side effect should occur.
ArchitectExceptionpublic java.lang.String makeDropTableSQL(java.lang.String table)
DROP TABLE $tablename command. Should work on most platforms.
makeDropTableSQL in interface DDLGeneratortable - The name of the table to be dropped.
public java.lang.String makeDropForeignKeySQL(java.lang.String fkTable,
java.lang.String fkName)
ALTER TABLE $fktable DROP FOREIGN KEY $fkname.
makeDropForeignKeySQL in interface DDLGeneratorfkTable - The name of the FK table whose relationship should be dropped.fkName - The name of the key to drop.
public java.util.List<DDLStatement> getDdlStatements()
DDLGeneratorDDLGenerator.generateDDLStatements(Collection) to populate this list.
getDdlStatements in interface DDLGeneratorpublic void dropPrimaryKey(SQLTable t)
dropPrimaryKey in interface DDLGenerator
public void addPrimaryKey(SQLTable t)
throws ArchitectException
addPrimaryKey in interface DDLGeneratorArchitectException
public void addIndex(SQLIndex index)
throws ArchitectException
addIndex in interface DDLGeneratorindex - The specification of the index to create. Note,
if the index type is STATISTIC, no DDL will be generated because
STATISTIC indices are just artificial JDBC constructs to describe
table statistics (you can't create or drop them).
ArchitectExceptionpublic boolean supportsRollback()
supportsRollback in interface DDLGenerator
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||