Generator
Db2Generator
, DerbyGenerator
, HsqlGenerator
, MssqlGenerator
, MysqlGenerator
, OracleGenerator
, PointBaseGenerator
, PostgresqlGenerator
, SapdbGenerator
, SybaseGenerator
public abstract class AbstractGenerator extends java.lang.Object implements Generator
public class Db2Generator extends AbstractGenerator { public Db2Generator(final String globConf, final String dbConf) throws GeneratorException { super(globConf, dbConf); setTypeMapper(new Db2TypeMapper(getConf())); } }TypeMapper for DB2
public final class Db2TypeMapper extends AbstractTypeMapper { public Db2TypeMapper(final Configuration conf) { super(conf); } protected void initialize(final Configuration conf) { // numeric types this.add(new NotSupportedType("bit")); LOG.warn("Db2 does not support 'TINY' type, use SMALLINT instead."); this.add(new NoParamType("tinyint", "SMALLINT")); this.add(new NoParamType("smallint", "SMALLINT")); this.add(new NoParamType("integer", "INTEGER")); this.add(new NoParamType("bigint", "BIGINT")); } }Field for DB2
public class Db2Field extends Field { public Db2Field() { super(); } public String toDDL() throws GeneratorException { StringBuffer buff = new StringBuffer(); buff.append(getName()).append(" "); buff.append(getType().toDDL(this)); if (isIdentity()) { buff.append(" NOT NULL"); } KeyGenerator keyGen = getKeyGenerator(); if (keyGen != null && isIdentity()) { if (KeyGenerator.IDENTITY_KEY.equalsIgnoreCase(keyGen.getName())) { buff.append(" GENERATED BY DEFAULT AS IDENTITY "). append("START WITH 1 INCREMENT BY 1"); } } return buff.toString(); } }Field for DB2
public class Db2SchemaFactory extends SchemaFactory { public Db2SchemaFactory() { super(); } public Field createField() { return new Db2Field(); } }The GeneratorFactory class handles the specific database generator creation. For example:
Generator generator = GeneratorFactory. createDDLGenerator(“mysql”, “ddl.properties”, “mysql.properties”);And to generate DDL, it should specify the printer and call generateDDL method.
generator.setPrinter(System.out); Mapping mapping = new Mapping(); mapping.loadMapping("mapping.xml"); generator.generateDDL(mapping);
GLOBAL_CONFIG_NAME, GLOBAL_CONFIG_PATH
Modifier | Constructor | Description |
---|---|---|
protected |
AbstractGenerator(DDLGenConfiguration configuration) |
Constructor for AbstractGenerator.
|
Modifier and Type | Method | Description |
---|---|---|
protected void |
createForeignKeyDDL(Table table,
DDLWriter writer) |
Generate DDL for foreign key.
|
void |
createIndex(Table table,
DDLWriter writer) |
Generate DDL for indices of given table.
|
void |
createSchema() |
Extracting informations from mapping to schema, this is done by 3 steps.
|
void |
generateCreate(DDLWriter writer) |
Generate DDL for create statementof table.
|
void |
generateDDL(java.io.OutputStream output) |
Generate DDL for a mapping document.
|
void |
generateDrop(DDLWriter writer) |
Generate DDL for drop statement of table.
|
void |
generateForeignKey(DDLWriter writer) |
Generate DDL for foreign keys.
|
abstract void |
generateHeader(DDLWriter writer) |
Generate header comment.
|
void |
generateIndex(DDLWriter writer) |
Generate DDL for indices.
|
void |
generateKeyGenerator(DDLWriter writer) |
Generate DDL for key generators (sequence/trigger).
|
void |
generatePrimaryKey(DDLWriter writer) |
Generate DDL for primany keys.
|
DDLGenConfiguration |
getConfiguration() |
Get configuration of generator.
|
Mapping |
getMapping() |
Get mapping document.
|
MappingHelper |
getMappingHelper() |
Get mapping helper.
|
Schema |
getSchema() |
Get schema.
|
SchemaFactory |
getSchemaFactory() |
Get schema factory.
|
TypeMapper |
getTypeMapper() |
Get type mapper.
|
void |
setKeyGenRegistry(KeyGeneratorRegistry keyGenRegistry) |
Set key generator registry.
|
void |
setMapping(Mapping mapping) |
Set mapping document.
|
protected void |
setMappingHelper(MappingHelper mappingHelper) |
Set mapping helper.
|
protected void |
setSchemaFactory(SchemaFactory schemaFactory) |
Set schema factory.
|
void |
setTypeMapper(TypeMapper typeMapper) |
Set type mapper.
|
getEngineConfigName, getEngineConfigPath, getEngineName, initialize
protected AbstractGenerator(DDLGenConfiguration configuration)
configuration
- Configuration to use by the generator.public final DDLGenConfiguration getConfiguration()
public final void setKeyGenRegistry(KeyGeneratorRegistry keyGenRegistry)
setKeyGenRegistry
in interface Generator
keyGenRegistry
- Key generator registry.protected final void setMappingHelper(MappingHelper mappingHelper)
mappingHelper
- Mapping helper.public final MappingHelper getMappingHelper()
public final void setTypeMapper(TypeMapper typeMapper)
typeMapper
- Type mapper.public final TypeMapper getTypeMapper()
protected final void setSchemaFactory(SchemaFactory schemaFactory)
schemaFactory
- Schema factory.public final SchemaFactory getSchemaFactory()
public final void setMapping(Mapping mapping)
setMapping
in interface Generator
mapping
- Mapping document.public final Mapping getMapping()
public final Schema getSchema()
public final void generateDDL(java.io.OutputStream output) throws GeneratorException
generateDDL
in interface Generator
output
- Output stream for output.GeneratorException
- If failed to generate DDL.public final void generateDrop(DDLWriter writer) throws GeneratorException
writer
- DDLWriter to write schema objects to.GeneratorException
- If failed to generate DDL.public final void generateCreate(DDLWriter writer) throws GeneratorException
CREATE TABLE prod ( id INTEGER NOT NULL, name CHAR(16) ); CREATE TABLE prod_detail ( id INTEGER NOT NULL, prod_id CHAR(16) );
writer
- DDLWriter to write schema objects to.GeneratorException
- If failed to generate DDL.public final void generatePrimaryKey(DDLWriter writer) throws GeneratorException
writer
- DDLWriter to write schema objects to.GeneratorException
- If failed to generate DDL.public final void generateForeignKey(DDLWriter writer) throws GeneratorException
ALTER TABLE `prod_group` ADD CONSTRAINT `FK_prod_group_1` FOREIGN KEY `FK_prod_group_1` (`id`, `name`) REFERENCES `category` (`id`, `name`) ON DELETE SET NULL ON UPDATE CASCADE;
writer
- DDLWriter to write schema objects to.GeneratorException
- If failed to generate DDL.public final void generateIndex(DDLWriter writer) throws GeneratorException
writer
- DDLWriter to write schema objects to.GeneratorException
- If failed to generate DDL.public final void generateKeyGenerator(DDLWriter writer) throws GeneratorException
writer
- DDLWriter to write schema objects to.GeneratorException
- If failed to generate DDL.protected final void createForeignKeyDDL(Table table, DDLWriter writer) throws GeneratorException
table
- Table to generate DDL of foreign key for.writer
- DDLWriter to write schema objects to.GeneratorException
- If failed to generate DDL.public final void createIndex(Table table, DDLWriter writer) throws GeneratorException
table
- Table to generate DDL of indices for.writer
- DDLWriter to write schema objects to.GeneratorException
- If failed to generate DDL.public abstract void generateHeader(DDLWriter writer)
writer
- DDLWriter to write schema objects to.public final void createSchema() throws GeneratorException
GeneratorException
- If failed to create schema objects.Intalio Inc. (C) 1999-2008. All rights reserved http://www.intalio.com