Author: tfischer
Date: Wed Oct 22 00:16:46 2014
New Revision: 1633494
URL: http://svn.apache.org/r1633494
Log:
TORQUE-331 - generate check constraint for enums
Added:
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/EnumValue.java
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/derby/enumConstraint.groovy
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/enumValue.groovy
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/hsqldb/enumConstraint.groovy
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/mssql/enumConstraint.groovy
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/mysql/enumConstraint.groovy
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/oracle/enumConstraint.groovy
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/postgresql/enumConstraint.groovy
Modified:
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TemplateOptionName.java
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/Column.java
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/Inheritance.java
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMColumnTransformer.java
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLModelTransformer.java
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SqlAttributeName.java
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/conf/options.properties
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/outlets/ddl.xml
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/database.groovy
db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema.sql
Modified:
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TemplateOptionName.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TemplateOptionName.java?rev=1633494&r1=1633493&r2=1633494&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TemplateOptionName.java
(original)
+++
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TemplateOptionName.java
Wed Oct 22 00:16:46 2014
@@ -247,7 +247,13 @@ public enum TemplateOptionName implement
OM_ENUM_NAME_PREFIX("torque.om.enumNamePrefix"),
/** The suffix for the name of enum types. */
- OM_ENUM_NAME_SUFFIX("torque.om.enumNameSuffix");
+ OM_ENUM_NAME_SUFFIX("torque.om.enumNameSuffix"),
+
+ /** The prefix for the constraint name for enum types. */
+ SQL_ENUM_CONSTRAINT_NAME_PREFIX("torque.sql.enumConstraintNamePrefix"),
+
+ /** The suffix for the constraint name for enum types. */
+ SQL_ENUM_CONSTRAINT_NAME_SUFFIX("torque.sql.enumConstraintNameSuffix");
/**
* The fully qualified name of the option.
Modified:
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/Column.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/Column.java?rev=1633494&r1=1633493&r2=1633494&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/Column.java
(original)
+++
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/Column.java
Wed Oct 22 00:16:46 2014
@@ -40,6 +40,9 @@ public class Column
/** The list of inheritances for this column. */
public List<Inheritance> inheritanceList = new ArrayList<Inheritance>();
+ /** The list of enum values for this column. */
+ public List<EnumValue> enumValueList = new ArrayList<EnumValue>();
+
/** The column's name. */
public String name;
@@ -97,8 +100,21 @@ public class Column
/** The description of (== comment for) the column. */
public String description;
+ /** The name of the enum type for the column. It can be either fully
qualified or unqualified. */
+ public String enumType;
+
// SQL generation properties
/** Contains the SQL to define the column. */
public String ddlSql;
+
+ /** the constraint name for an enum column. */
+ public String enumConstraintName;
+
+ /**
+ * Whether to generate an enum constraint for the column
+ * (nb: predefined enums can be defined for which no constraint can be
defuned).
+ */
+ public Boolean generateEnum;
+
}
Added:
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/EnumValue.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/EnumValue.java?rev=1633494&view=auto
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/EnumValue.java
(added)
+++
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/EnumValue.java
Wed Oct 22 00:16:46 2014
@@ -0,0 +1,47 @@
+package org.apache.torque.templates.model;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * The model of the enum-value tag in a Torque schema file.
+ *
+ * @version $Id: $
+ */
+public class EnumValue
+{
+ /** The column to which this enum-value definition belongs to. */
+ public Column parent;
+
+ /** The value of the enum-value. */
+ public String value;
+
+ /** The java name of the enum-value. */
+ public String javaName;
+
+ /** The description of the enum-value. */
+ public String description;
+
+ // sql generation properties
+ /** The properly escaped sql value for the value. */
+ public String sqlValue;
+
+ /** Whether another enumValue exists in the list of enumValues where this
enumValue belongs to. */
+ public boolean hasNext;
+}
Modified:
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/Inheritance.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/Inheritance.java?rev=1633494&r1=1633493&r2=1633494&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/Inheritance.java
(original)
+++
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/Inheritance.java
Wed Oct 22 00:16:46 2014
@@ -20,7 +20,7 @@ package org.apache.torque.templates.mode
*/
/**
- * The model of the option tag in a Torque schema file.
+ * The model of the inheritance tag in a Torque schema file.
*
* @version $Id: $
*/
Modified:
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMColumnTransformer.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMColumnTransformer.java?rev=1633494&r1=1633493&r2=1633494&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMColumnTransformer.java
(original)
+++
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMColumnTransformer.java
Wed Oct 22 00:16:46 2014
@@ -1045,16 +1045,17 @@ public class OMColumnTransformer
*
* @return the class name of the enum, or null if the column is not an
enum column.
*/
- protected String setEnumAttributes(
+ public static String setEnumAttributes(
final SourceElement columnElement,
final ControllerState controllerState)
{
String enumClassName = (String)
columnElement.getAttribute(TorqueSchemaAttributeName.ENUM_NAME);
- String enumPackage;
- boolean columnIsEnum = false;
// whether to generate an enum class. This is not the same as
columnIsEnum because
// we have the case of pre-defined enums (no enum-value attributes
given).
- boolean generateEnum = true;
+ boolean generateEnum =
columnElement.getChild(TorqueSchemaElementName.ENUM_VALUE) != null;
+
+ String enumPackage;
+ boolean columnIsEnum = false;
if (enumClassName != null)
{
columnIsEnum = true;
@@ -1069,18 +1070,10 @@ public class OMColumnTransformer
enumPackage = (String) columnElement.getParent().getAttribute(
TableAttributeName.DB_OBJECT_PACKAGE);
}
- if (columnElement.getChild(TorqueSchemaElementName.ENUM_VALUE) ==
null)
- {
- generateEnum = false;
- }
}
else
{
- if (columnElement.getChild(TorqueSchemaElementName.ENUM_VALUE) ==
null)
- {
- generateEnum = false;
- }
- else
+ if (columnElement.getChild(TorqueSchemaElementName.ENUM_VALUE) !=
null)
{
columnIsEnum = true;
}
Modified:
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLModelTransformer.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLModelTransformer.java?rev=1633494&r1=1633493&r2=1633494&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLModelTransformer.java
(original)
+++
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLModelTransformer.java
Wed Oct 22 00:16:46 2014
@@ -21,6 +21,7 @@ package org.apache.torque.templates.tran
import java.util.ArrayList;
import java.util.Date;
+import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang.StringUtils;
@@ -31,6 +32,7 @@ import org.apache.torque.templates.Templ
import org.apache.torque.templates.TorqueSchemaIdMethod;
import org.apache.torque.templates.model.Column;
import org.apache.torque.templates.model.Database;
+import org.apache.torque.templates.model.EnumValue;
import org.apache.torque.templates.model.ForeignKey;
import org.apache.torque.templates.model.Index;
import org.apache.torque.templates.model.IndexColumn;
@@ -204,6 +206,20 @@ public class SQLModelTransformer impleme
column,
controllerState);
}
+ if (column.enumConstraintName == null)
+ {
+ column.enumConstraintName =
controllerState.getStringOption(TemplateOptionName.SQL_ENUM_CONSTRAINT_NAME_PREFIX)
+ + column.name
+ +
controllerState.getStringOption(TemplateOptionName.SQL_ENUM_CONSTRAINT_NAME_SUFFIX);
+ }
+ column.generateEnum = !column.enumValueList.isEmpty();
+ Iterator<EnumValue> enumValueIt = column.enumValueList.iterator();
+ while (enumValueIt.hasNext())
+ {
+ EnumValue enumValue = enumValueIt.next();
+ transformEnumValue(enumValue, controllerState);
+ enumValue.hasNext = enumValueIt.hasNext();
+ }
}
int fkIndex = 1;
@@ -400,4 +416,59 @@ public class SQLModelTransformer impleme
}
}
}
+
+ /**
+ * Enriches the enum-value elements with additional attributes
+ * needed for SQL generation.
+ *
+ * @param enumValueElement the element to enrich, not null.
+ * @param controllerState the current controller state, not null.
+ *
+ * @throws SourceTransformerException if the name or type attributes
+ * are not set or if the type is unknown.
+ */
+ private void transformEnumValue(
+ final EnumValue enumValue,
+ final ControllerState controllerState)
+ throws SourceTransformerException
+ {
+ if (enumValue.sqlValue != null)
+ {
+ return;
+ }
+ Column column = enumValue.parent;
+ SchemaType schemaType = SchemaTypeHelper.getSchemaType(
+ column,
+ controllerState);
+ Platform platform = getPlatform(controllerState);
+
+ if ((SchemaType.DATE == schemaType
+ || SchemaType.TIME == schemaType
+ || SchemaType.TIMESTAMP == schemaType))
+ {
+ Date defaultDate
+ =
OMColumnTransformer.getDefaultValueAsDate(enumValue.value);
+ if (SchemaType.DATE == schemaType)
+ {
+ enumValue.sqlValue = platform.getDateString(defaultDate);
+ }
+ else if (SchemaType.TIME == schemaType)
+ {
+ enumValue.sqlValue = platform.getTimeString(defaultDate);
+ }
+ else
+ {
+ enumValue.sqlValue = platform.getTimestampString(defaultDate);
+ }
+ }
+ else if (TypeMap.isTextType(schemaType))
+ {
+ enumValue.sqlValue = platform.quoteAndEscape(enumValue.value);
+ }
+ else
+ {
+ enumValue.sqlValue = enumValue.value;
+ }
+ }
+
}
Modified:
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SqlAttributeName.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SqlAttributeName.java?rev=1633494&r1=1633493&r2=1633494&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SqlAttributeName.java
(original)
+++
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SqlAttributeName.java
Wed Oct 22 00:16:46 2014
@@ -76,7 +76,17 @@ public enum SqlAttributeName implements
/**
* The attribute contains the SQL to define the column.
*/
- DDL_SQL("ddlSql");
+ DDL_SQL("ddlSql"),
+
+ /**
+ * The attribute contains the constraint name if the column contains an
enum.
+ */
+ ENUM_CONSTRAINT_NAME("enumConstraintName"),
+
+ /**
+ * The attribute contains the properly escaped and transformed sql value
for the element.
+ */
+ SQL_VALUE("sqlValue");
/** The name of the source element attribute, not null. */
private String name;
@@ -86,7 +96,7 @@ public enum SqlAttributeName implements
*
* @param name the name of the source element attribute, not null.
*/
- private SqlAttributeName(String name)
+ private SqlAttributeName(final String name)
{
this.name = name;
}
Modified:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/conf/options.properties
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/conf/options.properties?rev=1633494&r1=1633493&r2=1633494&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/conf/options.properties
(original)
+++
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/conf/options.properties
Wed Oct 22 00:16:46 2014
@@ -15,3 +15,8 @@
# specific language governing permissions and limitations
# under the License.
torque.sql.generate.drops = true
+
+#The prefix for the constraint name for enum types.
+torque.sql.enumConstraintNamePrefix =
+# The suffix for the constraint name for enum types.
+torque.sql.enumConstraintNameSuffix = _CHECK
Modified:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/outlets/ddl.xml
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/outlets/ddl.xml?rev=1633494&r1=1633493&r2=1633494&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/outlets/ddl.xml
(original)
+++
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/outlets/ddl.xml
Wed Oct 22 00:16:46 2014
@@ -47,6 +47,11 @@
element="tableList"
outlet="torque.sql.ddl.foreignKeySkipDecider"/>
</mergepoint>
+ <mergepoint name="enumConstraints">
+ <action xsi:type="traverseAllAction"
+ element="tableList/columnList"
+ outlet="torque.sql.ddl.enumConstraint"/>
+ </mergepoint>
<mergepoint name="views">
<action xsi:type="traverseAllAction"
element="viewList"
@@ -226,6 +231,21 @@
xsi:type="groovyOutlet"
path="ddl/${option:database}/foreignKey.groovy" />
+ <outlet name="torque.sql.ddl.enumConstraint"
+ xsi:type="groovyOutlet"
+ path="ddl/${option:database}/enumConstraint.groovy">
+ <mergepoint name="enumValue">
+ <action xsi:type="traverseAllAction"
+ element="enumValueList"
+ outlet="torque.sql.ddl.enumValue"/>
+ </mergepoint>
+ </outlet>
+
+ <outlet name="torque.sql.ddl.enumValue"
+ xsi:type="groovyOutlet"
+ path="ddl/enumValue.groovy">
+ </outlet>
+
<outlet name="torque.sql.ddl.view"
xsi:type="groovyOutlet"
path="ddl/${option:database}/view.groovy">
Modified:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/database.groovy
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/database.groovy?rev=1633494&r1=1633493&r2=1633494&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/database.groovy
(original)
+++
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/database.groovy
Wed Oct 22 00:16:46 2014
@@ -22,6 +22,7 @@ return torqueGenGroovy.mergepoint("datab
torqueGenGroovy.mergepoint("createSchema") +
torqueGenGroovy.mergepoint("tables") +
torqueGenGroovy.mergepoint("foreignKeys") +
+ torqueGenGroovy.mergepoint("enumConstraints") +
torqueGenGroovy.mergepoint("views") +
torqueGenGroovy.mergepoint("comments") +
torqueGenGroovy.mergepoint("databaseEnd") + "\n"
\ No newline at end of file
Added:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/derby/enumConstraint.groovy
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/derby/enumConstraint.groovy?rev=1633494&view=auto
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/derby/enumConstraint.groovy
(added)
+++
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/derby/enumConstraint.groovy
Wed Oct 22 00:16:46 2014
@@ -0,0 +1,35 @@
+package org.apache.torque.templates.sql.templates.ddl.derby
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+import org.apache.torque.generator.template.groovy.TorqueGenGroovy
+import org.apache.torque.templates.model.Column
+
+TorqueGenGroovy torqueGenGroovy = (TorqueGenGroovy) torqueGen
+Column column = torqueGenGroovy.model
+
+if (!column.generateEnum)
+{
+ return ""
+}
+def result = """\
+ALTER TABLE $column.parent.name
+ ADD CONSTRAINT $column.enumConstraintName
+ CHECK
+ ($column.name in (""" + torqueGenGroovy.mergepoint("enumValue") + """));
+
+"""
+return result
\ No newline at end of file
Added:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/enumValue.groovy
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/enumValue.groovy?rev=1633494&view=auto
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/enumValue.groovy
(added)
+++
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/enumValue.groovy
Wed Oct 22 00:16:46 2014
@@ -0,0 +1,29 @@
+package org.apache.torque.templates.sql.templates.ddl
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+import org.apache.torque.generator.template.groovy.TorqueGenGroovy
+import org.apache.torque.templates.model.EnumValue
+
+TorqueGenGroovy torqueGenGroovy = (TorqueGenGroovy) torqueGen
+EnumValue enumValue = torqueGenGroovy.model
+
+String result = enumValue.sqlValue
+if (enumValue.hasNext)
+{
+ result += ", "
+}
+return result
\ No newline at end of file
Added:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/hsqldb/enumConstraint.groovy
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/hsqldb/enumConstraint.groovy?rev=1633494&view=auto
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/hsqldb/enumConstraint.groovy
(added)
+++
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/hsqldb/enumConstraint.groovy
Wed Oct 22 00:16:46 2014
@@ -0,0 +1,35 @@
+package org.apache.torque.templates.sql.templates.ddl.hsqldb
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+import org.apache.torque.generator.template.groovy.TorqueGenGroovy
+import org.apache.torque.templates.model.Column
+
+TorqueGenGroovy torqueGenGroovy = (TorqueGenGroovy) torqueGen
+Column column = torqueGenGroovy.model
+
+if (!column.generateEnum)
+{
+ return ""
+}
+def result = """\
+ALTER TABLE $column.parent.name
+ ADD CONSTRAINT $column.enumConstraintName
+ CHECK
+ ($column.name in (""" + torqueGenGroovy.mergepoint("enumValue") + """));
+
+"""
+return result
\ No newline at end of file
Added:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/mssql/enumConstraint.groovy
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/mssql/enumConstraint.groovy?rev=1633494&view=auto
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/mssql/enumConstraint.groovy
(added)
+++
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/mssql/enumConstraint.groovy
Wed Oct 22 00:16:46 2014
@@ -0,0 +1,35 @@
+package org.apache.torque.templates.sql.templates.ddl.mssql
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+import org.apache.torque.generator.template.groovy.TorqueGenGroovy
+import org.apache.torque.templates.model.Column
+
+TorqueGenGroovy torqueGenGroovy = (TorqueGenGroovy) torqueGen
+Column column = torqueGenGroovy.model
+
+if (!column.generateEnum)
+{
+ return ""
+}
+def result = """\
+ALTER TABLE $column.parent.name
+ ADD CONSTRAINT $column.enumConstraintName
+ CHECK
+ ($column.name in (""" + torqueGenGroovy.mergepoint("enumValue") + """));
+
+"""
+return result
\ No newline at end of file
Added:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/mysql/enumConstraint.groovy
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/mysql/enumConstraint.groovy?rev=1633494&view=auto
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/mysql/enumConstraint.groovy
(added)
+++
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/mysql/enumConstraint.groovy
Wed Oct 22 00:16:46 2014
@@ -0,0 +1,35 @@
+package org.apache.torque.templates.sql.templates.ddl.mysql
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+import org.apache.torque.generator.template.groovy.TorqueGenGroovy
+import org.apache.torque.templates.model.Column
+
+TorqueGenGroovy torqueGenGroovy = (TorqueGenGroovy) torqueGen
+Column column = torqueGenGroovy.model
+
+if (!column.generateEnum)
+{
+ return ""
+}
+def result = """\
+ALTER TABLE $column.parent.name
+ ADD CONSTRAINT $column.enumConstraintName
+ CHECK
+ ($column.name in (""" + torqueGenGroovy.mergepoint("enumValue") + """));
+
+"""
+return result
\ No newline at end of file
Added:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/oracle/enumConstraint.groovy
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/oracle/enumConstraint.groovy?rev=1633494&view=auto
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/oracle/enumConstraint.groovy
(added)
+++
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/oracle/enumConstraint.groovy
Wed Oct 22 00:16:46 2014
@@ -0,0 +1,35 @@
+package org.apache.torque.templates.sql.templates.ddl.oracle
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+import org.apache.torque.generator.template.groovy.TorqueGenGroovy
+import org.apache.torque.templates.model.Column
+
+TorqueGenGroovy torqueGenGroovy = (TorqueGenGroovy) torqueGen
+Column column = torqueGenGroovy.model
+
+if (!column.generateEnum)
+{
+ return ""
+}
+def result = """\
+ALTER TABLE $column.parent.name
+ ADD CONSTRAINT $column.enumConstraintName
+ CHECK
+ ($column.name in (""" + torqueGenGroovy.mergepoint("enumValue") + """));
+
+"""
+return result
\ No newline at end of file
Added:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/postgresql/enumConstraint.groovy
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/postgresql/enumConstraint.groovy?rev=1633494&view=auto
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/postgresql/enumConstraint.groovy
(added)
+++
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/templates/ddl/postgresql/enumConstraint.groovy
Wed Oct 22 00:16:46 2014
@@ -0,0 +1,35 @@
+package org.apache.torque.templates.sql.templates.ddl.postgresql
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+import org.apache.torque.generator.template.groovy.TorqueGenGroovy
+import org.apache.torque.templates.model.Column
+
+TorqueGenGroovy torqueGenGroovy = (TorqueGenGroovy) torqueGen
+Column column = torqueGenGroovy.model
+
+if (!column.generateEnum)
+{
+ return ""
+}
+def result = """\
+ALTER TABLE $column.parent.name
+ ADD CONSTRAINT $column.enumConstraintName
+ CHECK
+ ($column.name in (""" + torqueGenGroovy.mergepoint("enumValue") + """));
+
+"""
+return result
\ No newline at end of file
Modified:
db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema.sql
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema.sql?rev=1633494&r1=1633493&r2=1633494&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema.sql
(original)
+++
db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema.sql
Wed Oct 22 00:16:46 2014
@@ -281,6 +281,11 @@ ALTER TABLE extext_schema
FOREIGN KEY (extext_id)
REFERENCES extext (extext_id);
+ALTER TABLE a
+ ADD CONSTRAINT enum_CHECK
+ CHECK
+ (enum in ('x', 'y', 'z'));
+
CREATE OR REPLACE VIEW a_b AS
SELECT
a.a_id AS a_id,
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]