ca.sqlpower.architect.ddl
Class PostgresDDLGenerator

java.lang.Object
  extended by ca.sqlpower.architect.ddl.GenericDDLGenerator
      extended by ca.sqlpower.architect.ddl.PostgresDDLGenerator
All Implemented Interfaces:
DDLGenerator

public class PostgresDDLGenerator
extends GenericDDLGenerator

DDL Generator for Postgres 8.x (does not support e.g., ALTER COLUMN operations 7.[34]).


Field Summary
static java.lang.String GENERATOR_VERSION
           
 
Fields inherited from class ca.sqlpower.architect.ddl.GenericDDLGenerator
allowConnection, con, EOL, profileFunctionMap, targetCatalog, targetSchema, topLevelNames, typeMap, warnings
 
Constructor Summary
PostgresDDLGenerator()
           
 
Method Summary
 void addIndex(SQLIndex index)
          create index ddl in postgresql syntax
 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)
          Augments the default columnDefinition behaviour by adding the correct default value clause for auto-increment columns.
protected  void createTypeMap()
          Creates and populates typeMap using DatabaseMetaData, but ignores nullability as reported by the driver's type map (because all types are reported as non-nullable).
 java.lang.String getCatalogTerm()
          Returns null, even though Postgres calls this "Database." The reason is, you can't refer to objects in a different database than the default database for your current connection.
 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()
          Returns "Schema".
 java.lang.String getTargetSchema()
          Returns the previously-set target schema name, or "public" if there is no current setting.
 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.
 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.
 java.lang.String toIdentifier(java.lang.String name)
          Converts space to underscore in name and returns the possibly-modified string.
 void writeHeader()
           
 
Methods inherited from class ca.sqlpower.architect.ddl.GenericDDLGenerator
addColumn, addPrimaryKey, addPrimaryKeysToCreateTable, addRelationship, columnNullability, columnType, createPhysicalName, createSeqPhysicalName, dropColumn, dropPrimaryKey, dropRelationship, dropTable, endStatement, failsafeGetTypeDescriptor, generateDDLScript, generateDDLStatements, getAllowConnection, getColumnDataTypeName, getCon, getDdlStatements, getDefaultType, getDeferrabilityClause, getDeleteActionClause, getProfileFunctionMap, getStatementTerminator, getTargetCatalog, getTypeMap, getUpdateActionClause, getWarnings, makeDropTableSQL, print, println, setAllowConnection, setCon, setProfileFunctionMap, setTargetCatalog, setTargetSchema, setTypeMap, supportsDeferrabilityPolicy, supportsDeleteAction, supportsRollback, supportsUpdateAction, toQualifiedName, toQualifiedName, toQualifiedName, writeCreateDB, writeDDLTransactionBegin, writeDDLTransactionEnd, writeExportedRelationships, writePrimaryKey
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GENERATOR_VERSION

public static final java.lang.String GENERATOR_VERSION
See Also:
Constant Field Values
Constructor Detail

PostgresDDLGenerator

public PostgresDDLGenerator()
                     throws java.sql.SQLException
Throws:
java.sql.SQLException
Method Detail

getName

public java.lang.String getName()
Description copied from interface: DDLGenerator
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.

Specified by:
getName in interface DDLGenerator
Overrides:
getName in class GenericDDLGenerator

isReservedWord

public boolean isReservedWord(java.lang.String word)
Description copied from class: GenericDDLGenerator
Check to see if the word word is on the list of reserved words for this database

Specified by:
isReservedWord in interface DDLGenerator
Overrides:
isReservedWord in class GenericDDLGenerator
Returns:

writeHeader

public void writeHeader()
Overrides:
writeHeader in class GenericDDLGenerator

createTypeMap

protected void createTypeMap()
                      throws java.sql.SQLException
Creates and populates typeMap using DatabaseMetaData, but ignores nullability as reported by the driver's type map (because all types are reported as non-nullable).

Overrides:
createTypeMap in class GenericDDLGenerator
Throws:
java.sql.SQLException

toIdentifier

public java.lang.String toIdentifier(java.lang.String name)
Description copied from class: GenericDDLGenerator
Converts space to underscore in 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.

Specified by:
toIdentifier in interface DDLGenerator
Overrides:
toIdentifier in class GenericDDLGenerator

makeDropForeignKeySQL

public java.lang.String makeDropForeignKeySQL(java.lang.String fkTable,
                                              java.lang.String fkName)
Generates a command for dropping a foreign key. The statement looks like ALTER TABLE ONLY $fktable DROP CONSTRAINT $fkname.

Specified by:
makeDropForeignKeySQL in interface DDLGenerator
Overrides:
makeDropForeignKeySQL in class GenericDDLGenerator
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.

modifyColumn

public void modifyColumn(SQLColumn c)
Description copied from interface: DDLGenerator
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.

Specified by:
modifyColumn in interface DDLGenerator
Overrides:
modifyColumn in class GenericDDLGenerator
Parameters:
c - The column to create a MODIFY or ALTER COLUMN statement for.

getCatalogTerm

public java.lang.String getCatalogTerm()
Returns null, even though Postgres calls this "Database." The reason is, you can't refer to objects in a different database than the default database for your current connection. Also, the Postgres DatabaseMetaData always shows nulls for the catalog/database name of tables.

Specified by:
getCatalogTerm in interface DDLGenerator
Overrides:
getCatalogTerm in class GenericDDLGenerator

getSchemaTerm

public java.lang.String getSchemaTerm()
Returns "Schema".

Specified by:
getSchemaTerm in interface DDLGenerator
Overrides:
getSchemaTerm in class GenericDDLGenerator

getTargetSchema

public java.lang.String getTargetSchema()
Returns the previously-set target schema name, or "public" if there is no current setting. Public is the Postgres default when no schema is specified.

Specified by:
getTargetSchema in interface DDLGenerator
Overrides:
getTargetSchema in class GenericDDLGenerator
Returns:
the value of targetSchema

addIndex

public void addIndex(SQLIndex index)
              throws ArchitectException
create index ddl in postgresql syntax

Specified by:
addIndex in interface DDLGenerator
Overrides:
addIndex in class GenericDDLGenerator
Parameters:
index - 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).
Throws:
ArchitectException

addTable

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

Specified by:
addTable in interface DDLGenerator
Overrides:
addTable in class GenericDDLGenerator
Throws:
java.sql.SQLException
ArchitectException

columnDefinition

protected java.lang.String columnDefinition(SQLColumn c,
                                            java.util.Map colNameMap)
Augments the default columnDefinition behaviour by adding the correct default value clause for auto-increment columns. For non-autoincrement columns, the behaviour is the same as GenericDDLGenerator.columnDefinition(SQLColumn, Map).

Overrides:
columnDefinition in class GenericDDLGenerator
Parameters:
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 GenericDDLGenerator.createPhysicalName(Map, SQLObject) for more information.
Returns:
The SQL snippet that describes the given column. The returned string is not delimited at the beginning or end: you're responsible for properly putting it in the context of a valid SQL statement.


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