templates.Ddl.xpt Maven / Gradle / Ivy
?IMPORT ddlDsl?
?EXTENSION extensions::Strings?
?EXTENSION extensions::Ddl?
?DEFINE main FOR Ddl?
?FILE ((String) GLOBALVAR ddlFileName)-?
?EXPAND statement FOREACH statements?
?ENDFILE?
?ENDDEFINE?
?DEFINE statement FOR DdlStatement??ENDDEFINE?
?DEFINE statement FOR TableComment?
COMMENT ON TABLE ?table.name.toUpperCase()? is '?comment?';
?ENDDEFINE?
?DEFINE statement FOR ColumnComment?
COMMENT ON COLUMN ?((CreateTable)column.eContainer).name.toUpperCase()?.?column.name? is '?comment?';
?ENDDEFINE?
?DEFINE statement FOR CreateTable?
?PROTECT CSTART "/*" CEND "*/" ID "preCreateTable_"+name? ?ENDPROTECT?
CREATE TABLE ?name.toUpperCase()? (
?FOREACH properties.typeSelect(Column) AS column ITERATOR iterator-?
?EXPAND property FOR column??IF !iterator.lastIteration?,?ENDIF?
?ENDFOREACH-?
);
?PROTECT CSTART "/*" CEND "*/" ID "postCreateTable_"+name? ?ENDPROTECT?
?IF !properties.typeSelect(PrimaryKeyConstraint).isEmpty-?
?PROTECT CSTART "/*" CEND "*/" ID "preCreateUniqueIndex_"+name? ?ENDPROTECT?
CREATE UNIQUE INDEX ?name?X1 ON ?name.toUpperCase()? (?FOREACH properties.typeSelect(PrimaryKeyConstraint).first().columns AS column SEPARATOR ","??column.name? ASC?ENDFOREACH?);
?PROTECT CSTART "/*" CEND "*/" ID "postCreateUniqueIndex_"+name? ?ENDPROTECT?
?PROTECT CSTART "/*" CEND "*/" ID "preAlterTableAddConstraintPrimaryKey_"+name? ?ENDPROTECT?
ALTER TABLE ?name.toUpperCase()?
ADD CONSTRAINT ?name.toUpperCase()?X1
PRIMARY KEY (?FOREACH properties.typeSelect(PrimaryKeyConstraint).first().columns AS column SEPARATOR ","??column.name??ENDFOREACH?)
;
?PROTECT CSTART "/*" CEND "*/" ID "postAlterTableAddConstraintPrimaryKey_"+name? ?ENDPROTECT?
?ENDIF-?
?ENDDEFINE?
?DEFINE property FOR TableProperty??ENDDEFINE?
?DEFINE property FOR Column-?
?name? ?EXPAND columnType FOR type??IF NullableConstraint.isInstance(constraint) && ((NullableConstraint)constraint).not? NOT NULL?ENDIF-?
?ENDDEFINE?
?DEFINE statement FOR Alter?
?EXPAND alterTableAction(table) FOR action-?
?ENDDEFINE?
?DEFINE alterTableAction(CreateTable table) FOR AlterTableAction??ENDDEFINE?
?DEFINE alterTableAction(CreateTable table) FOR AddTableConstraint-?
?PROTECT CSTART "/*" CEND "*/" ID "preAlterTableAddForeignKey_"+constraintName(table,constraint)? ?ENDPROTECT?
ALTER TABLE ?table.name.toUpperCase()?
ADD CONSTRAINT ?constraintName(table,constraint)?
?EXPAND constraint FOR constraint?
;
?PROTECT CSTART "/*" CEND "*/" ID "postAlterTableAddForeignKey_"+constraintName(table,constraint)? ?ENDPROTECT?
?ENDDEFINE?
?DEFINE constraintName(CreateTable table) FOR Constraint??ENDDEFINE?
?DEFINE constraintName(CreateTable table) FOR ForeignKeyConstraint?FK_?table.name?_?reference.table.name??ENDDEFINE?
?DEFINE constraint FOR Constraint??ENDDEFINE?
?DEFINE constraint FOR ForeignKeyConstraint-?
FOREIGN KEY (?FOREACH columns AS column SEPARATOR ","??column.name??ENDFOREACH?)
REFERENCES ?reference.table.name.toUpperCase()??IF !reference.columns.isEmpty?(?FOREACH reference.columns AS column SEPARATOR ","??column.name??ENDFOREACH?)?ENDIF-?
?ENDDEFINE?
?DEFINE columnType FOR SqlDataType??name.toUpperCase()??ENDDEFINE?
?DEFINE columnType FOR SqlCharacter??name.toUpperCase()??IF size!=null?(?size?)?ENDIF??ENDDEFINE?
?DEFINE columnType FOR SqlNumber??name.toUpperCase()??IF hasPrecision? PRECISION?ENDIF??IF precision>0?(?precision??IF scale>0?,?scale??ENDIF?)?ENDIF??ENDDEFINE?
?DEFINE columnType FOR Long??name.toUpperCase()??IF raw? RAW?ENDIF??ENDDEFINE?
?DEFINE columnType FOR Raw??name.toUpperCase()??IF size>0?(?size?)?ENDIF??ENDDEFINE?
?DEFINE columnType FOR SqlDate??name.toUpperCase()??ENDDEFINE?
?DEFINE columnType FOR SqlTimeStamp??name.toUpperCase()??IF precision>0?(?precision?)?ENDIF??ENDDEFINE?
?DEFINE columnType FOR SqlInterval??name.toUpperCase()??IF year? YEAR?ENDIF??IF day? DAY?ENDIF??IF precision>0?(?precision?)?ENDIF??ENDDEFINE?
?DEFINE columnType FOR LargeObjectType??name.toUpperCase()??IF size>0?(?size?)?ENDIF??ENDDEFINE?
?DEFINE columnType FOR RowIdType??name.toUpperCase()??IF size!=null?(?size?)?ENDIF??ENDDEFINE?
?DEFINE columnType FOR SqlBoolean??name.toUpperCase()??ENDDEFINE?