de.interactive_instruments.ShapeChange.Target.SQL
Class SqlDdl

java.lang.Object
  extended by de.interactive_instruments.ShapeChange.Target.SQL.SqlDdl
All Implemented Interfaces:
MessageSource, Target

public class SqlDdl
extends Object
implements Target, MessageSource

Creates SQL DDL for an application schema.

Author:
Johannes Echterhoff (echterhoff interactive-instruments de)

Field Summary
static String CRLF
           
static String DEFAULT_FOREIGN_KEY_COLUMN_SUFFIX
           
static String DEFAULT_ID_COLUMN_NAME
           
static int DEFAULT_SIZE
           
static int DEFAULT_SRID
           
static String IDT
           
static String MAP_PARAM_GEOMETRY
           
static String MAP_TARGETTYPE_COND_PART
           
static String MAP_TARGETTYPE_COND_TEXTORCHARACTERVARYING
           
static String PARAM_CREATE_DOCUMENTATION
          Flag to indicate that model documentation shall be added to the DDL via comments; default is true.
static String PARAM_CREATE_REFERENCES
          Flag to indicate that foreign key creation is desired (true); default is false.
static String PARAM_DATABASE_SYSTEM
          Identifier of the database system for which SQL DDL shall be created.
static String PARAM_FOREIGN_KEY_COLUMN_DATA_TYPE
           
static String PARAM_FOREIGN_KEY_COLUMN_SUFFIX
          Suffix to append to the name of columns that contain foreign keys.
static String PARAM_ID_COLUMN_NAME
          Name for the identifier column when generating table creation statements.
static String PARAM_SIZE
          Size for fields representing textual properties with limited length, to be used in case that the property represented by the field does not have a 'size' tagged value; default is 1024
static String PARAM_SRID
          EPSG code of the spatial reference system to use for geometries; default is 4326
static String PLATFORM
           
static String RULE_TGT_SQL_CLS_FEATURE_TYPES
          Ensures that table creation statements are generated for feature types.
static String RULE_TGT_SQL_CLS_OBJECT_TYPES
          Ensures that table creation statements are generated for object types.
static String RULE_TGT_SQL_CLS_REFERENCES_TO_EXTERNAL_TYPES
          If this rule is enabled, then a property whose type is a type with identity but that type is not contained in the currently processed schema ... is still encoded as a field with a foreign key - if other rules allow table creation for this type.
static int TARGET_SQLDDL
           
 
Constructor Summary
SqlDdl()
           
 
Method Summary
 void createAlterTableStatementForReverseProperty(PropertyInfo pi)
           
 void createForeignKeyDefinition(String className, PropertyInfo pi)
           
 void generateTableCreationStatement(ClassInfo ci, List<PropertyInfo> propertyInfosForColumns)
           
 int getTargetID()
           
 void initialise(PackageInfo pi, Model m, Options o, ShapeChangeResult r, boolean diagOnly)
          Allows a target to perform the necessary initialization routines before processing.
 String message(int mnr)
          Return a message for a message number.
 void process(ClassInfo ci)
          The converter will call this method for each class belonging to the package given during initialization (see Target.initialise(de.interactive_instruments.ShapeChange.Model.PackageInfo, de.interactive_instruments.ShapeChange.Model.Model, de.interactive_instruments.ShapeChange.Options, de.interactive_instruments.ShapeChange.ShapeChangeResult, boolean)).
 boolean refersToOtherFeatureOrObjectRepresentedByTable(PropertyInfo pi)
           
 void write()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TARGET_SQLDDL

public static final int TARGET_SQLDDL
See Also:
Constant Field Values

PLATFORM

public static final String PLATFORM
See Also:
Constant Field Values

PARAM_ID_COLUMN_NAME

public static final String PARAM_ID_COLUMN_NAME
Name for the identifier column when generating table creation statements. This parameter is optional. The default is "_id".

See Also:
Constant Field Values

PARAM_FOREIGN_KEY_COLUMN_SUFFIX

public static final String PARAM_FOREIGN_KEY_COLUMN_SUFFIX
Suffix to append to the name of columns that contain foreign keys. This parameter is optional. The default is the empty string.

See Also:
Constant Field Values

PARAM_FOREIGN_KEY_COLUMN_DATA_TYPE

public static final String PARAM_FOREIGN_KEY_COLUMN_DATA_TYPE
See Also:
Constant Field Values

PARAM_SIZE

public static final String PARAM_SIZE
Size for fields representing textual properties with limited length, to be used in case that the property represented by the field does not have a 'size' tagged value; default is 1024

See Also:
Constant Field Values

PARAM_SRID

public static final String PARAM_SRID
EPSG code of the spatial reference system to use for geometries; default is 4326

See Also:
Constant Field Values

PARAM_CREATE_REFERENCES

public static final String PARAM_CREATE_REFERENCES
Flag to indicate that foreign key creation is desired (true); default is false.

See Also:
Constant Field Values

PARAM_CREATE_DOCUMENTATION

public static final String PARAM_CREATE_DOCUMENTATION
Flag to indicate that model documentation shall be added to the DDL via comments; default is true.

See Also:
Constant Field Values

PARAM_DATABASE_SYSTEM

public static final String PARAM_DATABASE_SYSTEM
Identifier of the database system for which SQL DDL shall be created. Supported systems - and also relevant identifiers - are: The default is PostgreSQL.

See Also:
Constant Field Values

RULE_TGT_SQL_CLS_FEATURE_TYPES

public static final String RULE_TGT_SQL_CLS_FEATURE_TYPES
Ensures that table creation statements are generated for feature types.

See Also:
Constant Field Values

RULE_TGT_SQL_CLS_OBJECT_TYPES

public static final String RULE_TGT_SQL_CLS_OBJECT_TYPES
Ensures that table creation statements are generated for object types.

See Also:
Constant Field Values

RULE_TGT_SQL_CLS_REFERENCES_TO_EXTERNAL_TYPES

public static final String RULE_TGT_SQL_CLS_REFERENCES_TO_EXTERNAL_TYPES
If this rule is enabled, then a property whose type is a type with identity but that type is not contained in the currently processed schema ... is still encoded as a field with a foreign key - if other rules allow table creation for this type. Otherwise the field is encoded using a textual data type.

See Also:
Constant Field Values

DEFAULT_ID_COLUMN_NAME

public static final String DEFAULT_ID_COLUMN_NAME
See Also:
Constant Field Values

DEFAULT_FOREIGN_KEY_COLUMN_SUFFIX

public static final String DEFAULT_FOREIGN_KEY_COLUMN_SUFFIX
See Also:
Constant Field Values

DEFAULT_SIZE

public static final int DEFAULT_SIZE
See Also:
Constant Field Values

DEFAULT_SRID

public static final int DEFAULT_SRID
See Also:
Constant Field Values

MAP_PARAM_GEOMETRY

public static final String MAP_PARAM_GEOMETRY
See Also:
Constant Field Values

MAP_TARGETTYPE_COND_PART

public static final String MAP_TARGETTYPE_COND_PART
See Also:
Constant Field Values

MAP_TARGETTYPE_COND_TEXTORCHARACTERVARYING

public static final String MAP_TARGETTYPE_COND_TEXTORCHARACTERVARYING
See Also:
Constant Field Values

CRLF

public static final String CRLF
See Also:
Constant Field Values

IDT

public static final String IDT
See Also:
Constant Field Values
Constructor Detail

SqlDdl

public SqlDdl()
Method Detail

initialise

public void initialise(PackageInfo pi,
                       Model m,
                       Options o,
                       ShapeChangeResult r,
                       boolean diagOnly)
                throws ShapeChangeAbortException
Description copied from interface: Target
Allows a target to perform the necessary initialization routines before processing.

Will be called by the Converter for each selected schema (see Model.selectedSchemas() and PackageInfo.isSchema()).

Specified by:
initialise in interface Target
Parameters:
pi - a schema from the model selected via the configuration (see Model.selectedSchemas()) - not necessarily always an application schema
Throws:
ShapeChangeAbortException
See Also:
Target.initialise(de.interactive_instruments.ShapeChange.Model.PackageInfo, de.interactive_instruments.ShapeChange.Model.Model, de.interactive_instruments.ShapeChange.Options, de.interactive_instruments.ShapeChange.ShapeChangeResult, boolean)

process

public void process(ClassInfo ci)
Description copied from interface: Target
The converter will call this method for each class belonging to the package given during initialization (see Target.initialise(de.interactive_instruments.ShapeChange.Model.PackageInfo, de.interactive_instruments.ShapeChange.Model.Model, de.interactive_instruments.ShapeChange.Options, de.interactive_instruments.ShapeChange.ShapeChangeResult, boolean)).

NOTE: will be called not only for the classes directly contained in the package, but also all sub-packages belonging to the same targetNamespace!

Specified by:
process in interface Target

createForeignKeyDefinition

public void createForeignKeyDefinition(String className,
                                       PropertyInfo pi)

generateTableCreationStatement

public void generateTableCreationStatement(ClassInfo ci,
                                           List<PropertyInfo> propertyInfosForColumns)

createAlterTableStatementForReverseProperty

public void createAlterTableStatementForReverseProperty(PropertyInfo pi)

refersToOtherFeatureOrObjectRepresentedByTable

public boolean refersToOtherFeatureOrObjectRepresentedByTable(PropertyInfo pi)
Parameters:
pi -
Returns:
true if the value type of the property is a feature or object type, can be found in the model, is an object type and table creation for object types is allowed, is in the currently processed schema or references to external types with identity are allowed via the rule "rule-sql-cls-references-to-external-types"; otherwise false is returned.

write

public void write()
Specified by:
write in interface Target
See Also:
Target.write()

getTargetID

public int getTargetID()
Specified by:
getTargetID in interface Target

message

public String message(int mnr)
Description copied from interface: MessageSource
Return a message for a message number.

Specified by:
message in interface MessageSource
See Also:
MessageSource.message(int)


Copyright © 2015. All rights reserved.