You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by gk...@apache.org on 2019/10/25 15:13:36 UTC
svn commit: r1868940 - in /db/torque/torque4/trunk/torque-templates/src:
main/java/org/apache/torque/templates/model/
main/java/org/apache/torque/templates/platform/
main/java/org/apache/torque/templates/transformer/sql/
main/resources/org/apache/torqu...
Author: gk
Date: Fri Oct 25 15:13:36 2019
New Revision: 1868940
URL: http://svn.apache.org/viewvc?rev=1868940&view=rev
Log:
torque templates:
- add hasUniqueConstraintSize (column size in unique constraint) into Platform (allow sizing in mysql and probably postgresql)
- add test table for this case (and test for multiple unique columns as well)
Modified:
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/Unique.java
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/UniqueColumn.java
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/Platform.java
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformDefaultImpl.java
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformMysqlImpl.java
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformPostgresqlImpl.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/SQLTransformer.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/createdb/templates/mysql/createdb.vm
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/xsd/database-4-1.xsd
db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-derby.sql
db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-hsqldb.sql
db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-idtable-init.sql
db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-mssql.sql
db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-mysql.sql
db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-oracle.sql
db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-postgresql.sql
db/torque/torque4/trunk/torque-templates/src/test/schema/schema.xml
Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/Unique.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/Unique.java?rev=1868940&r1=1868939&r2=1868940&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/Unique.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/Unique.java Fri Oct 25 15:13:36 2019
@@ -45,7 +45,7 @@ public class Unique
// SQL generation properties
- /** Contains all unique column names in a comma-separated String. */
+ /** Contains all unique column names in a comma-separated String with optional character size of each column. */
public String uniqueColumnNames;
}
Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/UniqueColumn.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/UniqueColumn.java?rev=1868940&r1=1868939&r2=1868940&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/UniqueColumn.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/UniqueColumn.java Fri Oct 25 15:13:36 2019
@@ -34,4 +34,11 @@ public class UniqueColumn
* unique constraint.
*/
public String name;
+
+ /**
+ * The optional size of the column to be included in the
+ * unique constraint.
+ */
+
+ public String size;
}
Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/Platform.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/Platform.java?rev=1868940&r1=1868939&r2=1868940&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/Platform.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/Platform.java Fri Oct 25 15:13:36 2019
@@ -138,4 +138,12 @@ public interface Platform
* @return true if separate schema creation is possible, false if not.
*/
boolean usesStandaloneSchema();
+
+ /**
+ * Returns whether the database has schema support unique constraint
+ * for columns with size
+ *
+ * @return true if unique column constraint has size
+ */
+ boolean hasUniqueConstraintSize();
}
Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformDefaultImpl.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformDefaultImpl.java?rev=1868940&r1=1868939&r2=1868940&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformDefaultImpl.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformDefaultImpl.java Fri Oct 25 15:13:36 2019
@@ -235,4 +235,9 @@ public class PlatformDefaultImpl impleme
{
return false;
}
+
+ @Override
+ public boolean hasUniqueConstraintSize() {
+ return false;
+ }
}
Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformMysqlImpl.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformMysqlImpl.java?rev=1868940&r1=1868939&r2=1868940&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformMysqlImpl.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformMysqlImpl.java Fri Oct 25 15:13:36 2019
@@ -143,4 +143,12 @@ public class PlatformMysqlImpl extends P
.format(date.toInstant()
.atZone(ZoneId.of("GMT")));
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean hasUniqueConstraintSize() {
+ return true;
+ }
}
Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformPostgresqlImpl.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformPostgresqlImpl.java?rev=1868940&r1=1868939&r2=1868940&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformPostgresqlImpl.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformPostgresqlImpl.java Fri Oct 25 15:13:36 2019
@@ -145,4 +145,9 @@ public class PlatformPostgresqlImpl exte
{
return true;
}
+
+ @Override
+ public boolean hasUniqueConstraintSize() {
+ return 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=1868940&r1=1868939&r2=1868940&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 Fri Oct 25 15:13:36 2019
@@ -157,6 +157,9 @@ public class SQLModelTransformer impleme
}
table.primaryKeyColumnNames = primaryKeyColumnNames.toString();
+ Platform platform = getPlatform(controllerState);
+ boolean hasUniqueSize = platform.hasUniqueConstraintSize();
+
// unique
int uniqueIndex = 1;
for (final Unique unique : table.uniqueList)
@@ -166,6 +169,9 @@ public class SQLModelTransformer impleme
unique.name = table.name + "_UQ_" + uniqueIndex;
}
final StringBuilder uniqueColumnNames = new StringBuilder();
+
+ final StringBuilder uniqueColumnSizes = new StringBuilder();
+
for (final UniqueColumn uniqueColumn : unique.uniqueColumnList)
{
if (uniqueColumnNames.length() != 0)
@@ -173,8 +179,19 @@ public class SQLModelTransformer impleme
uniqueColumnNames.append(", ");
}
uniqueColumnNames.append(uniqueColumn.name);
+
+ if (hasUniqueSize) {
+ if (uniqueColumnSizes.length() != 0)
+ {
+ uniqueColumnSizes.append(", ");
+ }
+ if (uniqueColumn.size != null) {
+ uniqueColumnNames.append("(" + uniqueColumn.size + ")");
+ }
+ }
}
unique.uniqueColumnNames = uniqueColumnNames.toString();
+
++uniqueIndex;
}
Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLTransformer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLTransformer.java?rev=1868940&r1=1868939&r2=1868940&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLTransformer.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLTransformer.java Fri Oct 25 15:13:36 2019
@@ -212,6 +212,13 @@ public class SQLTransformer implements S
uniqueElement.setAttribute(
SqlAttributeName.UNIQUE_COLUMN_NAMES,
uniqueColumnNames);
+ String uniqueColumnSizes = collectAttributes(
+ uniqueElement,
+ TorqueSchemaElementName.UNIQUE_COLUMN.getName(),
+ TorqueSchemaAttributeName.SIZE.getName());
+ uniqueElement.setAttribute(
+ SqlAttributeName.UNIQUE_COLUMN_SIZES,
+ uniqueColumnSizes);
++uniqueIndex;
}
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=1868940&r1=1868939&r2=1868940&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 Fri Oct 25 15:13:36 2019
@@ -42,6 +42,13 @@ public enum SqlAttributeName implements
* in a comma-separated String.
*/
UNIQUE_COLUMN_NAMES("uniqueColumnNames"),
+
+ /**
+ * The attribute contains all unique column sizes
+ * in a comma-separated String.
+ */
+
+ UNIQUE_COLUMN_SIZES("uniqueColumnSizes"),
/**
* The attribute contains all index column names
Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/createdb/templates/mysql/createdb.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/createdb/templates/mysql/createdb.vm?rev=1868940&r1=1868939&r2=1868940&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/createdb/templates/mysql/createdb.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/sql/createdb/templates/mysql/createdb.vm Fri Oct 25 15:13:36 2019
@@ -15,4 +15,6 @@
## specific language governing permissions and limitations
## under the License.
drop database if exists $name;
+## utf8mb4 has up to 4 bytes per char.
+## database limits in mysql <5.7 for innodb 767bytes,m yisam 1000 and mysql > 5.7 3072bytes
create database $name character set utf8mb4 collate utf8mb4_unicode_ci;
Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/xsd/database-4-1.xsd
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/xsd/database-4-1.xsd?rev=1868940&r1=1868939&r2=1868940&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/xsd/database-4-1.xsd (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/xsd/database-4-1.xsd Fri Oct 25 15:13:36 2019
@@ -810,6 +810,13 @@ The name to use in defining this constra
</xs:documentation>
</xs:annotation>
</xs:attribute>
+ <xs:attribute name="size" type="xs:decimal" use="optional" >
+ <xs:annotation>
+ <xs:documentation xml:lang="en">
+The size of the field. E.g. columnname(size). Mainly to customize restrictions in bytes/character restrictions without global changes.
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
</xs:complexType>
<!-- =====================================
Modified: db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-derby.sql
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-derby.sql?rev=1868940&r1=1868939&r2=1868940&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-derby.sql (original)
+++ db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-derby.sql Fri Oct 25 15:13:36 2019
@@ -64,6 +64,7 @@ ALTER TABLE extext_schema
drop table a;
drop table b;
+drop table b2;
drop table r_ab;
drop table c;
drop table d;
@@ -105,6 +106,20 @@ CREATE TABLE b
-- -----------------------------------------------------------------------
+-- b2
+-- -----------------------------------------------------------------------
+CREATE TABLE b2
+(
+ b2_id INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY,
+ b2_name_1 VARCHAR(50) NOT NULL,
+ b2_name_2 VARCHAR(20) NOT NULL,
+ b2_name_3 VARCHAR(10) NOT NULL,
+ b2_name_4 VARCHAR(10) NOT NULL,
+ PRIMARY KEY(b2_id),
+ CONSTRAINT NAME_UNQ UNIQUE(b2_name_1, b2_name_2, b2_name_3, b2_name_4)
+);
+
+-- -----------------------------------------------------------------------
-- r_ab
-- -----------------------------------------------------------------------
CREATE TABLE r_ab
Modified: db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-hsqldb.sql
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-hsqldb.sql?rev=1868940&r1=1868939&r2=1868940&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-hsqldb.sql (original)
+++ db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-hsqldb.sql Fri Oct 25 15:13:36 2019
@@ -64,6 +64,7 @@ ALTER TABLE extext_schema
drop table a if exists;
drop table b if exists;
+drop table b2 if exists;
drop table r_ab if exists;
drop table c if exists;
drop table d if exists;
@@ -109,6 +110,20 @@ CREATE TABLE b
-- -----------------------------------------------------------------------
+-- b2
+-- -----------------------------------------------------------------------
+CREATE TABLE b2
+(
+ b2_id INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1) NOT NULL,
+ b2_name_1 VARCHAR(50) NOT NULL,
+ b2_name_2 VARCHAR(20) NOT NULL,
+ b2_name_3 VARCHAR(10) NOT NULL,
+ b2_name_4 VARCHAR(10) NOT NULL,
+ PRIMARY KEY(b2_id),
+ CONSTRAINT NAME_UNQ UNIQUE(b2_name_1, b2_name_2, b2_name_3, b2_name_4)
+);
+
+-- -----------------------------------------------------------------------
-- r_ab
-- -----------------------------------------------------------------------
CREATE TABLE r_ab
Modified: db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-idtable-init.sql
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-idtable-init.sql?rev=1868940&r1=1868939&r2=1868940&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-idtable-init.sql (original)
+++ db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-idtable-init.sql Fri Oct 25 15:13:36 2019
@@ -17,15 +17,16 @@
##
insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (103, 'a', 1000, 10);
insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (104, 'b', 1000, 10);
-insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (105, 'r_ab', 1000, 10);
-insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (106, 'c', 1000, 10);
-insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (107, 'd', 1000, 10);
-insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (108, 'nopk', 1000, 10);
-insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (109, 'MULTIPK_SELF_REFTABLE', 1000, 10);
-insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (110, 'ifc_table', 1000, 10);
-insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (111, 'ifc_table2', 1000, 10);
-insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (112, 'INHERITANCE_TEST', 1000, 10);
-insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (113, 'ext_schema', 1000, 10);
-insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (114, 'extext_schema', 1000, 10);
-insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (115, 'qualified_name', 1000, 10);
+insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (105, 'b2', 1000, 10);
+insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (106, 'r_ab', 1000, 10);
+insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (107, 'c', 1000, 10);
+insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (108, 'd', 1000, 10);
+insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (109, 'nopk', 1000, 10);
+insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (110, 'MULTIPK_SELF_REFTABLE', 1000, 10);
+insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (111, 'ifc_table', 1000, 10);
+insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (112, 'ifc_table2', 1000, 10);
+insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (113, 'INHERITANCE_TEST', 1000, 10);
+insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (114, 'ext_schema', 1000, 10);
+insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (115, 'extext_schema', 1000, 10);
+insert into ID_TABLE (id_table_id, table_name, next_id, quantity) VALUES (116, 'qualified_name', 1000, 10);
Modified: db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-mssql.sql
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-mssql.sql?rev=1868940&r1=1868939&r2=1868940&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-mssql.sql (original)
+++ db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-mssql.sql Fri Oct 25 15:13:36 2019
@@ -112,6 +112,31 @@ BEGIN
DROP TABLE b
END
;
+IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = 'b2')
+BEGIN
+ DECLARE @reftable_5 nvarchar(60), @constraintname_5 nvarchar(60)
+ DECLARE refcursor CURSOR FOR
+ select reftables.name tablename, cons.name constraintname
+ from sysobjects tables,
+ sysobjects reftables,
+ sysobjects cons,
+ sysreferences ref
+ where tables.id = ref.rkeyid
+ and cons.id = ref.constid
+ and reftables.id = ref.fkeyid
+ and tables.name = 'b2'
+ OPEN refcursor
+ FETCH NEXT from refcursor into @reftable_5, @constraintname_5
+ while @@FETCH_STATUS = 0
+ BEGIN
+ exec ('alter table '+@reftable_5+' drop constraint '+@constraintname_5)
+ FETCH NEXT from refcursor into @reftable_5, @constraintname_5
+ END
+ CLOSE refcursor
+ DEALLOCATE refcursor
+ DROP TABLE b2
+END
+;
IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = 'r_ab')
BEGIN
DECLARE @reftable_5 nvarchar(60), @constraintname_5 nvarchar(60)
@@ -387,6 +412,31 @@ BEGIN
DROP TABLE torque.qualified_name
END
;
+IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = 'qualified_name')
+BEGIN
+ DECLARE @reftable_16 nvarchar(60), @constraintname_16 nvarchar(60)
+ DECLARE refcursor CURSOR FOR
+ select reftables.name tablename, cons.name constraintname
+ from sysobjects tables,
+ sysobjects reftables,
+ sysobjects cons,
+ sysreferences ref
+ where tables.id = ref.rkeyid
+ and cons.id = ref.constid
+ and reftables.id = ref.fkeyid
+ and tables.name = 'torque.qualified_name'
+ OPEN refcursor
+ FETCH NEXT from refcursor into @reftable_16, @constraintname_16
+ while @@FETCH_STATUS = 0
+ BEGIN
+ exec ('alter table '+@reftable_16+' drop constraint '+@constraintname_16)
+ FETCH NEXT from refcursor into @reftable_16, @constraintname_16
+ END
+ CLOSE refcursor
+ DEALLOCATE refcursor
+ DROP TABLE torque.qualified_name
+END
+;
DROP SCHEMA torque;
@@ -422,6 +472,21 @@ CREATE TABLE b
)
;
+/* ----------------------------------------------------------------------- */
+/* b2 */
+/* ----------------------------------------------------------------------- */
+CREATE TABLE b2
+(
+ b2_id INT NOT NULL IDENTITY,
+ b2_name_1 VARCHAR(50) NOT NULL,
+ b2_name_2 VARCHAR(20) NOT NULL,
+ b2_name_3 VARCHAR(10) NOT NULL,
+ b2_name_4 VARCHAR(10) NOT NULL,
+ CONSTRAINT b2_PK PRIMARY KEY(b2_id),
+ CONSTRAINT NAME_UNQ UNIQUE (b2_name_1, b2_name_2, b2_name_3, b2_name_4)
+)
+
+;
/* ----------------------------------------------------------------------- */
Modified: db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-mysql.sql
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-mysql.sql?rev=1868940&r1=1868939&r2=1868940&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-mysql.sql (original)
+++ db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-mysql.sql Fri Oct 25 15:13:36 2019
@@ -62,6 +62,7 @@ ALTER TABLE extext_schema
drop table if exists a;
drop table if exists b;
+drop table if exists b2;
drop table if exists r_ab;
drop table if exists c;
drop table if exists d;
@@ -98,7 +99,22 @@ CREATE TABLE b
b_id INTEGER NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
PRIMARY KEY(b_id),
- UNIQUE NAME_UNQ (name)
+ UNIQUE NAME_UNQ (name(20))
+);
+
+
+# -----------------------------------------------------------------------
+# b2
+# -----------------------------------------------------------------------
+CREATE TABLE b2
+(
+ b2_id INTEGER NOT NULL AUTO_INCREMENT,
+ b2_name_1 VARCHAR(50) NOT NULL,
+ b2_name_2 VARCHAR(20) NOT NULL,
+ b2_name_3 VARCHAR(10) NOT NULL,
+ b2_name_4 VARCHAR(10) NOT NULL,
+ PRIMARY KEY(b2_id),
+ UNIQUE NAME_UNQ (b2_name_1(20), b2_name_2, b2_name_3(5), b2_name_4)
);
Modified: db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-oracle.sql
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-oracle.sql?rev=1868940&r1=1868939&r2=1868940&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-oracle.sql (original)
+++ db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-oracle.sql Fri Oct 25 15:13:36 2019
@@ -64,6 +64,8 @@ DROP TABLE a CASCADE CONSTRAINTS;
DROP SEQUENCE a_SEQ;
DROP TABLE b CASCADE CONSTRAINTS;
DROP SEQUENCE b_SEQ;
+DROP TABLE b2 CASCADE CONSTRAINTS;
+DROP SEQUENCE b2_SEQ;
DROP TABLE r_ab CASCADE CONSTRAINTS;
DROP TABLE c CASCADE CONSTRAINTS;
DROP SEQUENCE c_SEQ;
@@ -122,6 +124,27 @@ CREATE SEQUENCE b_SEQ INCREMENT BY 1 STA
-- -----------------------------------------------------------------------
+-- b2
+-- -----------------------------------------------------------------------
+CREATE TABLE b2
+(
+ b2_id NUMBER(10,0)(0) NOT NULL,
+ b2_name_1 VARCHAR2(50 CHAR) NOT NULL,
+ b2_name_2 VARCHAR2(20 CHAR) NOT NULL,
+ b2_name_3 VARCHAR2(10 CHAR) NOT NULL,
+ b2_name_4 VARCHAR2(10 CHAR) NOT NULL,
+ CONSTRAINT NAME_UNQ UNIQUE (b2_name_1, b2_name_2, b2_name_3, b2_name_4)
+);
+
+ALTER TABLE b2
+ ADD CONSTRAINT b2_PK
+ PRIMARY KEY(b2_id);
+
+
+CREATE SEQUENCE b2_SEQ INCREMENT BY 1 START WITH 1 NOMAXVALUE NOCYCLE NOCACHE ORDER;
+
+
+-- -----------------------------------------------------------------------
-- r_ab
-- -----------------------------------------------------------------------
CREATE TABLE r_ab
@@ -379,6 +402,9 @@ COMMENT ON TABLE a IS 'A table';
COMMENT ON TABLE b IS 'B table';
+COMMENT ON TABLE b2 IS 'B table';
+
+
COMMENT ON TABLE r_ab IS 'r_ab table';
Modified: db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-postgresql.sql
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-postgresql.sql?rev=1868940&r1=1868939&r2=1868940&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-postgresql.sql (original)
+++ db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/expected-schema-postgresql.sql Fri Oct 25 15:13:36 2019
@@ -64,6 +64,8 @@ DROP TABLE a CASCADE;
DROP SEQUENCE a_SEQ;
DROP TABLE b CASCADE;
DROP SEQUENCE b_SEQ;
+DROP TABLE b2 CASCADE;
+DROP SEQUENCE b2_SEQ;
DROP TABLE r_ab CASCADE;
DROP TABLE c CASCADE;
DROP SEQUENCE c_SEQ;
@@ -111,13 +113,29 @@ CREATE TABLE b
b_id INTEGER NOT NULL,
name VARCHAR(50) NOT NULL,
PRIMARY KEY(b_id),
- CONSTRAINT NAME_UNQ UNIQUE (name)
+ CONSTRAINT NAME_UNQ UNIQUE (name(20))
);
CREATE SEQUENCE b_SEQ INCREMENT BY 1 START WITH 1 NO MAXVALUE NO CYCLE;
-- -----------------------------------------------------------------------
+-- b2
+-- -----------------------------------------------------------------------
+CREATE TABLE b2
+(
+ b2_id INTEGER NOT NULL,
+ b2_name_1 VARCHAR(50) NOT NULL,
+ b2_name_2 VARCHAR(20) NOT NULL,
+ b2_name_3 VARCHAR(10) NOT NULL,
+ b2_name_4 VARCHAR(10) NOT NULL,
+ PRIMARY KEY(b2_id),
+ CONSTRAINT NAME_UNQ UNIQUE (b2_name_1(20), b2_name_2, b2_name_3(5), b2_name_4)
+);
+
+CREATE SEQUENCE b2_SEQ INCREMENT BY 1 START WITH 1 NO MAXVALUE NO CYCLE;
+
+-- -----------------------------------------------------------------------
-- r_ab
-- -----------------------------------------------------------------------
CREATE TABLE r_ab
@@ -335,6 +353,9 @@ COMMENT ON TABLE a IS 'A table';
COMMENT ON TABLE b IS 'B table';
+COMMENT ON TABLE b2 IS 'B table';
+
+
COMMENT ON TABLE r_ab IS 'r_ab table';
Modified: db/torque/torque4/trunk/torque-templates/src/test/schema/schema.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/test/schema/schema.xml?rev=1868940&r1=1868939&r2=1868940&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/test/schema/schema.xml (original)
+++ db/torque/torque4/trunk/torque-templates/src/test/schema/schema.xml Fri Oct 25 15:13:36 2019
@@ -18,10 +18,10 @@
under the License.
-->
<database
- xmlns="http://db.apache.org/torque/4.0/templates/database"
+ xmlns="http://db.apache.org/torque/4.1/templates/database"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://db.apache.org/torque/4.1/templates/database
- http://db.apache.org/torque/torque-4.1/documentation/orm-reference/database-4-1-strict.xsd"
+ http://db.apache.org/torque/torque-4.1/documentation/orm-reference/database-4-1.xsd"
name="bookstore"
defaultIdMethod="native">
<external-schema filename="ext-schema.xml" />
@@ -98,7 +98,50 @@
size="50"
/>
<unique name="NAME_UNQ">
- <unique-column name="name"/>
+ <unique-column name="name" size="20"/>
+ </unique>
+ </table>
+
+ <!-- =================================================== -->
+ <!-- B2 T A B L E -->
+ <!-- =================================================== -->
+
+ <table name="b2" description="B table">
+ <column
+ name="b2_id"
+ required="true"
+ primaryKey="true"
+ type="INTEGER"
+ />
+ <column
+ name="b2_name_1"
+ required="true"
+ type="VARCHAR"
+ size="50"
+ />
+ <column
+ name="b2_name_2"
+ required="true"
+ type="VARCHAR"
+ size="20"
+ />
+ <column
+ name="b2_name_3"
+ required="true"
+ type="VARCHAR"
+ size="10"
+ />
+ <column
+ name="b2_name_4"
+ required="true"
+ type="VARCHAR"
+ size="10"
+ />
+ <unique name="NAME_UNQ">
+ <unique-column name="b2_name_1" size="20"/>
+ <unique-column name="b2_name_2"/>
+ <unique-column name="b2_name_3" size="5"/>
+ <unique-column name="b2_name_4"/>
</unique>
</table>
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org