From 4fe3f67ef490b6b12456b1ababae7f0b3c840a53 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Tue, 21 May 2024 11:45:10 +0200 Subject: [PATCH] Various fixes for MySQL, SQL Server, DB2 and Sybase --- jpa/bin/pom.xml | 4 +++- jpa/spec-tests/pom.xml | 17 +++++++++++++++++ .../mapkeyenumerated/Department2.java | 3 ++- .../core/annotations/version/Client4.java | 5 ++++- .../annotations/enumerated/Client.java | 6 ++++++ .../annotations/index/Client.java | 8 ++++++-- .../annotations/joinTable/Client.java | 10 ++++++++-- .../annotations/orderColumn/Client.java | 7 ++++++- .../annotations/secondaryTable/Client.java | 7 ++++++- .../annotations/uniqueConstraint/Client.java | 5 ++++- sql/db2/db2.ddl.persistence.sql | 2 +- sql/mssqlserver/mssqlserver.ddl.persistence.sql | 8 +++++++- sql/mysql/mysql.ddl.persistence.sql | 4 ++++ sql/sybase/sybase.ddl.persistence.sql | 13 ++++++++++++- 14 files changed, 86 insertions(+), 13 deletions(-) diff --git a/jpa/bin/pom.xml b/jpa/bin/pom.xml index 95f32f1d13..034b8fbaa7 100644 --- a/jpa/bin/pom.xml +++ b/jpa/bin/pom.xml @@ -771,6 +771,7 @@ mysql com.mysql.cj.jdbc.Driver ! + false @@ -816,8 +817,9 @@ 1.0.0 sybase - com.sybase.jdbc4.jdbc.SybDriver + com.sybase.jdbc42.jdbc.SybDriver ! + false + + + com.sybase + jdbc42 + ${sybase.jdbc.version} + + + diff --git a/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/core/annotations/mapkeyenumerated/Department2.java b/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/core/annotations/mapkeyenumerated/Department2.java index a603595f93..ead0b4d422 100644 --- a/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/core/annotations/mapkeyenumerated/Department2.java +++ b/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/core/annotations/mapkeyenumerated/Department2.java @@ -20,6 +20,7 @@ import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; import jakarta.persistence.Id; import jakarta.persistence.MapKeyColumn; import jakarta.persistence.MapKeyEnumerated; @@ -72,7 +73,7 @@ public void setName(String name) { @OneToMany(mappedBy = "department") @MapKeyColumn(name = "OFFICE_ID") - @MapKeyEnumerated() + @MapKeyEnumerated(EnumType.STRING) public Map getLastNameEmployees() { return lastNameEmployees; } diff --git a/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/core/annotations/version/Client4.java b/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/core/annotations/version/Client4.java index 177590f92f..3f00e73282 100644 --- a/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/core/annotations/version/Client4.java +++ b/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/core/annotations/version/Client4.java @@ -175,7 +175,10 @@ public void createTimestampTestData() { try { getEntityTransaction().begin(); - Timestamp currentTime = new Timestamp(new Date().getTime()); + long time = new Date().getTime(); + // Remove the milliseconds, since the table column type has no fractional seconds, + // otherwise an optimistic lock exception might be thrown + Timestamp currentTime = new Timestamp(time - (time % 1000)); getEntityManager().persist(new Timestamp_Field("1", currentTime)); getEntityManager().persist(new Timestamp_Property("2", currentTime)); getEntityTransaction().commit(); diff --git a/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/se/schemaGeneration/annotations/enumerated/Client.java b/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/se/schemaGeneration/annotations/enumerated/Client.java index 6a16e2b38e..81b3dada37 100644 --- a/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/se/schemaGeneration/annotations/enumerated/Client.java +++ b/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/se/schemaGeneration/annotations/enumerated/Client.java @@ -128,6 +128,12 @@ public void enumeratedTest() throws Exception { expected.add("ENUMDATA VARCHAR"); expected.add("PRIMARY KEY (ID)"); pass1 = findDataInFile(f1, expected); + + expected.clear(); + expected.add("CREATE TABLE SCHEMAGENSIMPLE"); + expected.add("ENUMDATA ENUM"); + expected.add("PRIMARY KEY (ID)"); + pass1 = pass1 || findDataInFile(f1, expected); // CREATE TABLE SCHEMAGENSIMPLE (ID INTEGER NOT NULL, ENUMDATA VARCHAR(255), // PRIMARY KEY (ID)) diff --git a/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/se/schemaGeneration/annotations/index/Client.java b/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/se/schemaGeneration/annotations/index/Client.java index caad87f07e..2d041961a6 100644 --- a/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/se/schemaGeneration/annotations/index/Client.java +++ b/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/se/schemaGeneration/annotations/index/Client.java @@ -174,14 +174,18 @@ public void indexTest() throws Exception { pass1c = findDataInFile(f1, "CREATE INDEX SCHEMAGENSIMPLE_SVALUE2_DESC ON SCHEMAGENSIMPLE (SVALUE2 DESC)"); pass1c = pass1c || findDataInFile(f1, expected); + expected.clear(); + expected.add("CREATE UNIQUE"); + expected.add("INDEX SCHEMAGENSIMPLE_SVALUE3 ON SCHEMAGENSIMPLE (SVALUE3)"); + + pass1d = findDataInFile(f1, expected); + expected.clear(); expected.add("ALTER TABLE"); expected.add("SCHEMAGENSIMPLE"); expected.add("ADD"); expected.add("UNIQUE"); expected.add("INDEX SCHEMAGENSIMPLE_SVALUE3"); - - pass1d = findDataInFile(f1, "CREATE UNIQUE INDEX SCHEMAGENSIMPLE_SVALUE3 ON SCHEMAGENSIMPLE (SVALUE3)"); pass1d = pass1d || findDataInFile(f1, expected); expected.clear(); diff --git a/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/se/schemaGeneration/annotations/joinTable/Client.java b/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/se/schemaGeneration/annotations/joinTable/Client.java index 23e9d9a92e..7c330e9232 100644 --- a/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/se/schemaGeneration/annotations/joinTable/Client.java +++ b/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/se/schemaGeneration/annotations/joinTable/Client.java @@ -40,6 +40,8 @@ public class Client extends PMClientBase { String schemaGenerationDir = null; + String dataBaseName = null; + String sTestCase = "jpa_se_schemaGeneration_annotations_joinTable"; public JavaArchive createDeployment() throws Exception { @@ -78,6 +80,7 @@ public void setup() throws Exception { throw new Exception(msg); } removeTestData(); + dataBaseName = System.getProperty("jdbc.db"); } catch (Exception e) { logger.log(Logger.Level.ERROR, "Exception: ", e); @@ -185,9 +188,12 @@ public void joinTableTest() throws Exception { * SCHEMAGENCOURSE (COURSEID) */ - pass2a = findDataInFile(f2, List.of("ALTER TABLE", "SCHEMAGEN_COURSE_STUDENT DROP", "STUDENTIDCONSTRAINT")); + // DB2 cascades constraints automatically on a drop table statement + pass2a = dataBaseName.equals("db2"); + pass2a = pass2a || findDataInFile(f2, List.of("ALTER TABLE", "SCHEMAGEN_COURSE_STUDENT DROP", "STUDENTIDCONSTRAINT")); pass2a = pass2a || findDataInFile(f2, List.of("DROP TABLE", "SCHEMAGEN_COURSE_STUDENT", "CASCADE CONSTRAINTS")); - pass2b = findDataInFile(f2, List.of("ALTER TABLE", "SCHEMAGEN_COURSE_STUDENT DROP", "COURSEIDCONSTRAINT")); + pass2b = dataBaseName.equals("db2"); + pass2b = pass2b || findDataInFile(f2, List.of("ALTER TABLE", "SCHEMAGEN_COURSE_STUDENT DROP", "COURSEIDCONSTRAINT")); pass2b = pass2b || findDataInFile(f2, List.of("DROP TABLE", "SCHEMAGEN_COURSE_STUDENT", "CASCADE CONSTRAINTS")); expected.clear(); expected.add("DROP TABLE"); diff --git a/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/se/schemaGeneration/annotations/orderColumn/Client.java b/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/se/schemaGeneration/annotations/orderColumn/Client.java index 259cd7d948..f2ce226e9e 100644 --- a/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/se/schemaGeneration/annotations/orderColumn/Client.java +++ b/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/se/schemaGeneration/annotations/orderColumn/Client.java @@ -41,6 +41,8 @@ public class Client extends PMClientBase { Employee expectedEmployee = null; + String dataBaseName = null; + String sTestCase = "jpa_se_schemaGeneration_annotations_orderColumn"; public JavaArchive createDeployment() throws Exception { @@ -79,6 +81,7 @@ public void setup() throws Exception { throw new Exception(msg); } removeTestData(); + dataBaseName = System.getProperty("jdbc.db"); } catch (Exception e) { logger.log(Logger.Level.ERROR, "Exception: ", e); @@ -170,7 +173,9 @@ public void orderColumnTest() throws Exception { expected.clear(); expected.add("ALTER TABLE"); expected.add("SCHEMAGENEMP DROP"); - pass2c = findDataInFile(f2, expected); + // DB2 cascades constraints automatically on a drop table statement + pass2c = dataBaseName.equals("db2"); + pass2c = pass2c || findDataInFile(f2, expected); pass2c = pass2c || findDataInFile(f2, List.of("DROP TABLE", "SCHEMAGENEMP", "CASCADE CONSTRAINTS")); logger.log(Logger.Level.TRACE, "Execute the create script"); diff --git a/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/se/schemaGeneration/annotations/secondaryTable/Client.java b/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/se/schemaGeneration/annotations/secondaryTable/Client.java index 7eafea44ee..fca18a53ff 100644 --- a/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/se/schemaGeneration/annotations/secondaryTable/Client.java +++ b/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/se/schemaGeneration/annotations/secondaryTable/Client.java @@ -39,6 +39,8 @@ public class Client extends PMClientBase { String schemaGenerationDir = null; + String dataBaseName = null; + String sTestCase = "jpa_se_schemaGeneration_annotations_secondaryTable"; public JavaArchive createDeployment() throws Exception { @@ -77,6 +79,7 @@ public void setup() throws Exception { throw new Exception(msg); } removeTestData(); + dataBaseName = System.getProperty("jdbc.db"); } catch (Exception e) { logger.log(Logger.Level.ERROR, "Exception: ", e); @@ -158,7 +161,9 @@ public void secondaryTableTest() throws Exception { expected.clear(); expected.add("ALTER TABLE"); expected.add("SCHEMAGENSIMPLE_SECOND DROP"); - pass2a = findDataInFile(f2, expected); + // DB2 cascades constraints automatically on a drop table statement + pass2a = dataBaseName.equals("db2"); + pass2a = pass2a || findDataInFile(f2, expected); pass2a = pass2a || findDataInFile(f2, List.of("DROP TABLE", "SCHEMAGENSIMPLE_SECOND", "CASCADE CONSTRAINTS")); expected.clear(); expected.add("DROP TABLE"); diff --git a/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/se/schemaGeneration/annotations/uniqueConstraint/Client.java b/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/se/schemaGeneration/annotations/uniqueConstraint/Client.java index 5082fd7b0d..211bae8271 100644 --- a/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/se/schemaGeneration/annotations/uniqueConstraint/Client.java +++ b/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/se/schemaGeneration/annotations/uniqueConstraint/Client.java @@ -136,7 +136,10 @@ public void uniqueConstraintTest() throws Exception { pass1b = findDataInFile(f1, "CONSTRAINT MYUNIQUECONSTRAINT UNIQUE (ID, NAME)"); - pass1b = pass1b || findDataInFile(f1, "CREATE UNIQUE INDEX MYUNIQUECONSTRAINT ON SCHEMAGENSIMPLE (ID, NAME)"); + expected.clear(); + expected.add("CREATE UNIQUE"); + expected.add("INDEX MYUNIQUECONSTRAINT ON SCHEMAGENSIMPLE (ID, NAME)"); + pass1b = pass1b || findDataInFile(f1, expected); /* * CREATE TABLE SCHEMAGENSIMPLE (ID INTEGER NOT NULL, NAME VARCHAR(255), PRIMARY * KEY (ID)) ALTER TABLE SCHEMAGENSIMPLE ADD CONSTRAINT MYUNIQUECONSTRAINT diff --git a/sql/db2/db2.ddl.persistence.sql b/sql/db2/db2.ddl.persistence.sql index 7c771b8a58..7be1ae613d 100644 --- a/sql/db2/db2.ddl.persistence.sql +++ b/sql/db2/db2.ddl.persistence.sql @@ -36,7 +36,7 @@ DROP table FKS_ANOOP_CNOOP ! CREATE TABLE FKS_ANOOP_CNOOP( FK8_FOR_CUSTOMER_TABLE VARCHAR(255) , FK2_FOR_ALIAS_TABLE VARCHAR(255))! DROP TABLE CREDITCARD_TABLE! -CREATE TABLE CREDITCARD_TABLE ( ID VARCHAR(255) PRIMARY KEY NOT NULL, TYPE VARCHAR(255) , EXPIRES VARCHAR(255) , APPROVED DECIMAL(18,0) , CREDITCARD_NUMBER VARCHAR(255) , BALANCE DOUBLE, FK3_FOR_CUSTOMER_TABLE VARCHAR(255) , FK_FOR_ORDER_TABLE VARCHAR(255) )! +CREATE TABLE CREDITCARD_TABLE ( ID VARCHAR(255) PRIMARY KEY NOT NULL, TYPE VARCHAR(255) , EXPIRES VARCHAR(255) , APPROVED BOOLEAN , CREDITCARD_NUMBER VARCHAR(255) , BALANCE DOUBLE, FK3_FOR_CUSTOMER_TABLE VARCHAR(255) , FK_FOR_ORDER_TABLE VARCHAR(255) )! DROP TABLE ORDER_TABLE! CREATE TABLE ORDER_TABLE ( ID VARCHAR(255) PRIMARY KEY NOT NULL, TOTALPRICE DOUBLE , FK4_FOR_CUSTOMER_TABLE VARCHAR(255) , FK0_FOR_LINEITEM_TABLE VARCHAR(255) )! diff --git a/sql/mssqlserver/mssqlserver.ddl.persistence.sql b/sql/mssqlserver/mssqlserver.ddl.persistence.sql index 4a626726b4..44dfdc6c7e 100644 --- a/sql/mssqlserver/mssqlserver.ddl.persistence.sql +++ b/sql/mssqlserver/mssqlserver.ddl.persistence.sql @@ -962,10 +962,16 @@ CREATE TABLE EMPLOYEE_EMBEDED_ADDRESS (ID INTEGER NOT NULL, FIRSTNAME VARCHAR(25 CREATE TABLE COLTAB_EMP_EMBEDED_ADDRESS (ADDRESS_LOCATION VARCHAR(255), STREET VARCHAR(255), STATE VARCHAR(255), ZIP VARCHAR(255), CITY VARCHAR(255), ID VARCHAR(255), EMPEMBADDRID INTEGER) ! ALTER TABLE COLTAB_EMP_EMBEDED_ADDRESS ADD CONSTRAINT FK_EMPEMBADDRID FOREIGN KEY (EMPEMBADDRID) REFERENCES EMPLOYEE_EMBEDED_ADDRESS (ID) ! +DROP SEQUENCE SEQGENERATOR ! +CREATE SEQUENCE SEQGENERATOR START WITH 10 ! + DROP TABLE UUIDTYPE ! CREATE TABLE UUIDTYPE (ID VARCHAR(96) NOT NULL, NAME VARCHAR(255), PRIMARY KEY (ID)) ! DROP TABLE CRITERIA_TEST_COLTABLE ! DROP TABLE CRITERIA_TEST_TABLE ! CREATE TABLE CRITERIA_TEST_TABLE (ID INTEGER PRIMARY KEY NOT NULL, DATE_VAL DATE, INT_VAL INTEGER, STR_VAL_1 VARCHAR(255), STR_VAL_2 VARCHAR(255), TIME_VAL TIME) ! -CREATE TABLE CRITERIA_TEST_COLTABLE(ENT_ID INTEGER NOT NULL, COLVAL VARCHAR(255), CONSTRAINT FK_CRITERIA_TEST_COLTABLE_ENT_ID FOREIGN KEY (ENT_ID) REFERENCES CRITERIA_TEST_TABLE (ID)) ! \ No newline at end of file +CREATE TABLE CRITERIA_TEST_COLTABLE(ENT_ID INTEGER NOT NULL, COLVAL VARCHAR(255), CONSTRAINT FK_CRITERIA_TEST_COLTABLE_ENT_ID FOREIGN KEY (ENT_ID) REFERENCES CRITERIA_TEST_TABLE (ID)) ! + +DROP SEQUENCE DATATYPES_SEQ ! +CREATE SEQUENCE DATATYPES_SEQ START WITH 1 INCREMENT BY 50 ! \ No newline at end of file diff --git a/sql/mysql/mysql.ddl.persistence.sql b/sql/mysql/mysql.ddl.persistence.sql index 01838a435e..d7feed78c9 100644 --- a/sql/mysql/mysql.ddl.persistence.sql +++ b/sql/mysql/mysql.ddl.persistence.sql @@ -1153,3 +1153,7 @@ DROP TABLE IF EXISTS CRITERIA_TEST_COLTABLE ! DROP TABLE IF EXISTS CRITERIA_TEST_TABLE ! CREATE TABLE CRITERIA_TEST_TABLE (ID INTEGER PRIMARY KEY NOT NULL, DATE_VAL DATE, INT_VAL INTEGER, STR_VAL_1 VARCHAR(255), STR_VAL_2 VARCHAR(255), TIME_VAL TIME(6)) ! CREATE TABLE CRITERIA_TEST_COLTABLE(ENT_ID INTEGER NOT NULL, COLVAL VARCHAR(255), CONSTRAINT FK_CRITERIA_TEST_COLTABLE_ENT_ID FOREIGN KEY (ENT_ID) REFERENCES CRITERIA_TEST_TABLE (ID))! + +DROP TABLE DATATYPES_SEQ ! +CREATE TABLE DATATYPES_SEQ (NEXT_VAL INTEGER) ENGINE=innoDB DEFAULT CHARSET=latin1 ! +INSERT into DATATYPES_SEQ(NEXT_VAL) values (0) ! \ No newline at end of file diff --git a/sql/sybase/sybase.ddl.persistence.sql b/sql/sybase/sybase.ddl.persistence.sql index df79b34b9e..f17265474f 100644 --- a/sql/sybase/sybase.ddl.persistence.sql +++ b/sql/sybase/sybase.ddl.persistence.sql @@ -359,6 +359,9 @@ CREATE TABLE EMPLOYEE (ID INTEGER PRIMARY KEY NOT NULL, FIRSTNAME VARCHAR(255) N DROP TABLE DEPARTMENT ! CREATE TABLE DEPARTMENT (NAME VARCHAR(200) NULL, ID INTEGER PRIMARY KEY NOT NULL, COMPANY_COMPANYID INTEGER) ! +DROP TABLE DEPARTMENT2 ! +CREATE TABLE DEPARTMENT2 (ID INTEGER PRIMARY KEY NOT NULL, NAME VARCHAR(255) NULL) ! + DROP TABLE COFFEE ! CREATE TABLE COFFEE (ID INTEGER PRIMARY KEY NOT NULL, BRANDNAME VARCHAR(25), PRICE REAL) ! @@ -1120,6 +1123,10 @@ ALTER TABLE EMP_MAPKEYCOL ADD CONSTRAINT FK_DEPT1 FOREIGN KEY (FK_DEPT) REFERENC ALTER TABLE EMP_MAPKEYCOL ADD CONSTRAINT FK_DEPT3 FOREIGN KEY (FK_DEPT3) REFERENCES DEPARTMENT (ID) ! ALTER TABLE EMP_MAPKEYCOL ADD CONSTRAINT FK_DEPT4 FOREIGN KEY (FK_DEPT4) REFERENCES DEPARTMENT (ID) ! +DROP TABLE EMP_MAPKEYCOL2 ! +CREATE TABLE EMP_MAPKEYCOL2(ID INTEGER PRIMARY KEY NOT NULL, LASTNAME VARCHAR(255) NULL, THEDATE DATE NULL ,FK_DEPT5 INTEGER NULL )! +ALTER TABLE EMP_MAPKEYCOL2 ADD CONSTRAINT FK_DEPT5 FOREIGN KEY (FK_DEPT5) REFERENCES DEPARTMENT2 (ID) ! + ALTER TABLE COLTAB_EMP_EMBEDED_ADDRESS DROP CONSTRAINT FK_EMPEMBADDRID ! DROP TABLE COLTAB_EMP_EMBEDED_ADDRESS ! DROP TABLE EMPLOYEE_EMBEDED_ADDRESS ! @@ -1133,4 +1140,8 @@ CREATE TABLE UUIDTYPE (ID VARCHAR(96) NOT NULL, NAME VARCHAR(255), PRIMARY KEY ( DROP TABLE CRITERIA_TEST_COLTABLE ! DROP TABLE CRITERIA_TEST_TABLE ! CREATE TABLE CRITERIA_TEST_TABLE (ID INTEGER PRIMARY KEY NOT NULL, DATE_VAL DATE, INT_VAL INTEGER, STR_VAL_1 VARCHAR(255), STR_VAL_2 VARCHAR(255), TIME_VAL TIME) ! -CREATE TABLE CRITERIA_TEST_COLTABLE(ENT_ID INTEGER NOT NULL, COLVAL VARCHAR(255), CONSTRAINT FK_CRITERIA_TEST_COLTABLE_ENT_ID FOREIGN KEY (ENT_ID) REFERENCES CRITERIA_TEST_TABLE (ID)) ! \ No newline at end of file +CREATE TABLE CRITERIA_TEST_COLTABLE(ENT_ID INTEGER NOT NULL, COLVAL VARCHAR(255), CONSTRAINT FK_CRITERIA_TEST_COLTABLE_ENT_ID FOREIGN KEY (ENT_ID) REFERENCES CRITERIA_TEST_TABLE (ID)) ! + +DROP TABLE DATATYPES_SEQ ! +CREATE TABLE DATATYPES_SEQ (NEXT_VAL INTEGER) ! +INSERT into DATATYPES_SEQ(NEXT_VAL) values (0) ! \ No newline at end of file