# Castor DDL Generator - Properties

Describes the properties available on the Castor DDL Generator.

## Overview

At startup, the DDL Generator first evaluates the command line options. Next it loads the global properties on the command line if specified, otherwise the default properties included with the DDL Generator. There are two important properties loaded at startup:

org.castor.ddlgen.Generators

  tells the DDL Generator about the supported database engines.

org.castor.ddlgen.DefaultEngine

  The database engine for which to generate a SQL script. Can be overridden on the command line

The last step at startup is to read the specific configuration of the database engine being used. A custom configuration can be provided on the command line to override the default.

## Global properties

Please find below a list of global properties to control various advanced options of the DDL Generator.

Command line options

Option | Description | Values | Default | Since
--- | --- | --- | --- | ---
org.castor.ddlgen.Generators | Generator classes of supported database engines. |  |  | 1.1
org.castor.ddlgen.DefaultEngine | Name of default database engine. Will be overwritten by engine specified on commandline. | db2, derby, hsql, mssql, mysql, oracle, pointbase, postgresql, sapdb or sybase | mysql | 1.1
org.castor.ddlgen.SchemaName | Name of the database schema. |  | test | 1.1
org.castor.ddlgen.GroupStatements | How to group generated DDL statements? | TABLE or DDLTYPE | TABLE | 1.1
org.castor.ddlgen.CharFormat | How to format characters of generated DDL statements? | SENSITIVE, UPPER or LOWER | SENSITIVE | 1.1
org.castor.ddlgen.Newline | Character sequence to write for newline. |  | \n | 1.1
org.castor.ddlgen.Indention | Character sequence to write for indented lines. |  | \t | 1.1
org.castor.ddlgen.GenerateSchema | Generate SCHEMA statements. | true or false | true | 1.1
org.castor.ddlgen.GenerateDrop | Generate DROP statements. | true or false | true | 1.1
org.castor.ddlgen.GenerateCreate | Generate CREATE statements. | true or false | true | 1.1
org.castor.ddlgen.GeneratePrimaryKey | Generate PRIMARYKEY statement. | true or false | true | 1.1
org.castor.ddlgen.GenerateForeignKey | Generate FOREIGNKEY statement. | true or false | true | 1.1
org.castor.ddlgen.GenerateIndex | Generate INDEX statements (Not supported yet). | true or false | false | 1.1
org.castor.ddlgen.GenerateKeyGenerator | Generate KEYGENERATOR statements. | true or false | true | 1.1
default_tinyint_precision | Default precision of tinyint values. |  |  | 1.1
default_smallint_precision | Default precision of smallint values. |  |  | 1.1
default_integer_precision | Default precision of integer values. |  |  | 1.1
default_bigint_precision | Default precision of bigint values. |  | 19 | 1.1
default_bigint_decimals | Default decimals of bigint values. |  | 0 | 1.1
default_float_precision | Default precision of float values. |  | 38 | 1.1
| Default precision of tinyint values. |  |  | 1.1
default_float_decimals | Default decimals of float values. |  | 7 | 1.1
default_double_precision | Default precision of double values. |  | 53 | 1.1
default_double_decimals | Default decimals of double values. |  | 15 | 1.1
default_real_precision | Default precision of real values. |  | 38 | 1.1
default_real_decimals | Default decimals of real values. |  | 7 | 1.1
default_numeric_precision | Default precision of numeric values. |  | 65 | 1.1
default_numeric_decimals | Default decimals of numeric values. |  | 30 | 1.1
default_decimal_precision | Default precision of decimal values. |  | 65 | 1.1
default_decimal_decimals | Default decimals of decimal values. |  | 30 | 1.1
default_char_length | Default length of char values. |  | 256 | 1.1
default_varchar_length | Default length of varchar values. |  | 256 | 1.1
default_longvarchar_length | Default length of longvarchar values. |  | 1024 | 1.1
default_date_precision | Default precision of date values. |  |  | 1.1
default_time_precision | Default precision of time values. |  |  | 1.1
default_timestamp_precision | Default precision of timestamp values. |  | 19 | 1.1
default_binary_length | Default length of binary values. |  | 256 | 1.1
default_varbinary_length | Default length of varbinary values. |  | 256 | 1.1
default_longvarbinary_length | Default length of longvarbinary values. |  | 1024 | 1.1
default_other_length | Default length of other values. |  | 1024 | 1.1
default_javaobject_length | Default length of javaobject values. |  | 1024 | 1.1
default_blob_length | Default length of blob values. |  | 1024 | 1.1
default_clob_length | Default length of clob values. |  | 1024 | 1.1

### Supported database engines

The supported database engines are defined as follows:

    #
    # generator classes of supported database engines
    #
    org.castor.ddlgen.Generators=\
      org.castor.ddlgen.engine.db2.Db2Generator,\
      org.castor.ddlgen.engine.derby.DerbyGenerator,\
      org.castor.ddlgen.engine.hsql.HsqlGenerator,\
      org.castor.ddlgen.engine.mssql.MssqlGenerator,\
      org.castor.ddlgen.engine.mysql.MysqlGenerator,\
      org.castor.ddlgen.engine.oracle.OracleGenerator,\
      org.castor.ddlgen.engine.pointbase.PointBaseGenerator,\
      org.castor.ddlgen.engine.postgresql.PostgresqlGenerator,\
      org.castor.ddlgen.engine.sapdb.SapdbGenerator,\
      org.castor.ddlgen.engine.sybase.SybaseGenerator

### Grouping of DDL statements

There are 2 supported modes to group DDL statements. For a simple example, the output of both modes is:

org.castor.ddlgen.GroupStatements=TABLE

    drop A if exist
    create A(IDA int);
    alter table A add primary key (IDA)

    drop B if exist
    create B(IDB int);
    alter table B add primary key (IDB)

org.castor.ddlgen.GroupStatements=DDLTYPE

    drop A if exist
    drop B if exist

    create A(IDA int);
    create B(IDB int);

    alter table A add primary key (IDA)
    alter table B add primary key (IDB)

## Specific properties

Below you can find a list of specific properties to control various advanced options of the DDL Generator.

### Properties common for all database engines

Common properties for all databases

Option | Description | Values | Default | Since
--- | --- | --- | --- | ---
org.castor.ddlgen.KeyGeneratorFactories | Key generator factory classes supported by DB/2. |  |  | 1.1
org.castor.ddlgen.HeaderComment | Comment to add to head of generated script. |  |  | 1.1

#### Key generators

The key generators supported by a database engine are defined as follows (example taken from Oracle):

    #
    # key generator factory classes of supported database engines
    #
    org.castor.ddlgen.KeyGeneratorFactories=\
      org.castor.ddlgen.keygenerator.HighLowKeyGeneratorFactory,\
      org.castor.ddlgen.keygenerator.MaxKeyGeneratorFactory,\
      org.castor.ddlgen.keygenerator.UUIDKeyGeneratorFactory,\
      org.castor.ddlgen.engine.oracle.OracleSequenceKeyGeneratorFactory

### Properties for db2, hsql, Oracle, Postgresql and sapdb

Common properties for all databases

Option | Description | Values | Default | Since
--- | --- | --- | --- | ---
org.castor.ddlgen.TriggerTemplate | Template to create TRIGGER statements. |  |  | 1.1

#### Trigger template

Below you can take a look at the default trigger template defined for Oracle. The DDL Generator will replace the parameters in brackets with appropriate values (e.g. <table_name>).

Default trigegr template for Oracle

    #
    # trigger template
    #
    org.castor.ddlgen.TriggerTemplate=\
    CREATE TRIGGER <trigger_name>
      BEFORE INSERT OR UPDATE ON <table_name>
      FOR EACH ROW
      DECLARE
        iCounter <table_name>.<pk_name>%TYPE;
        cannot_change_counter EXCEPTION;
      BEGIN
        IF INSERTING THEN
          Select <sequence_name>.NEXTVAL INTO iCounter FROM Dual;
          :new.<pk_name> := iCounter;
        END IF;

        IF UPDATING THEN
          IF NOT (:new.<pk_name> = :old.<pk_name>) THEN
            RAISE cannot_change_counter;
          END IF;
        END IF;

    EXCEPTION
      WHEN cannot_change_counter THEN
        raise_application_error(-20000, 'Cannot Change Counter Value');
    END;

### Properties for MySQL only

Common properties for all databases

Option | Description | Values | Default | Since
--- | --- | --- | --- | ---
org.castor.ddlgen.engine.mysql.StorageEngine | Storage engine to be used. If left empty the default configured at the database server will be used. | MYISAM, InnoDB, MERGE, MEMORY, BDB or ISAM |  | 1.1
org.castor.ddlgen.engine.mysql.ForeignKeyOnDeleteStrategy | Delete strategy for foreign keys. If not specified NO ACTION will be used by default. | CASCADE, RESTRICT, SET NULL, NO ACTION |  | 1.1
org.castor.ddlgen.engine.mysql.ForeignKeyOnUpdateStrategy | Update strategy for foreign keys. If not specified NO ACTION will be used by default. | CASCADE, RESTRICT, SET NULL, NO ACTION |  | 1.1