Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes for MySQL, SQL Server, DB2 and Sybase #1308

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion jpa/bin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@
<jdbc.db>mysql</jdbc.db>
<jakarta.persistence.jdbc.driver>com.mysql.cj.jdbc.Driver</jakarta.persistence.jdbc.driver>
<db.delimiter>!</db.delimiter>
<db.supports.sequence>false</db.supports.sequence>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -816,8 +817,9 @@
<properties>
<sybase.jdbc.version>1.0.0</sybase.jdbc.version>
<jdbc.db>sybase</jdbc.db>
<jakarta.persistence.jdbc.driver>com.sybase.jdbc4.jdbc.SybDriver</jakarta.persistence.jdbc.driver>
<jakarta.persistence.jdbc.driver>com.sybase.jdbc42.jdbc.SybDriver</jakarta.persistence.jdbc.driver>
<db.delimiter>!</db.delimiter>
<db.supports.sequence>false</db.supports.sequence>
</properties>
<!--
Install with:
Expand Down
17 changes: 17 additions & 0 deletions jpa/spec-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,22 @@
</dependency>
</dependencies>
</profile>
<profile>
<id>sybase</id>
<properties>
<sybase.jdbc.version>1.0.0</sybase.jdbc.version>
</properties>
<!--
Install with:
mvn org.apache.maven.plugins:maven-install-plugin:3.1.1:install-file -Dfile=jconn42.jar -DgroupId=com.sybase -DartifactId=jdbc42 -Dversion=1.0.0 -Dpackaging=jar
-->
<dependencies>
<dependency>
<groupId>com.sybase</groupId>
<artifactId>jdbc42</artifactId>
<version>${sybase.jdbc.version}</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,7 +73,7 @@ public void setName(String name) {

@OneToMany(mappedBy = "department")
@MapKeyColumn(name = "OFFICE_ID")
@MapKeyEnumerated()
@MapKeyEnumerated(EnumType.STRING)
public Map<Offices, Employee2> getLastNameEmployees() {
return lastNameEmployees;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sql/db2/db2.ddl.persistence.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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) )!
Expand Down
8 changes: 7 additions & 1 deletion sql/mssqlserver/mssqlserver.ddl.persistence.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)) !
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 !
4 changes: 4 additions & 0 deletions sql/mysql/mysql.ddl.persistence.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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) !
13 changes: 12 additions & 1 deletion sql/sybase/sybase.ddl.persistence.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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) !

Expand Down Expand Up @@ -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 !
Expand All @@ -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)) !
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) !