ADD: different DB2 platforms

This commit is contained in:
Roland Praml committed 2022-01-27 10:09:31 +01:00
1 parent 404b167bcc
commit 48c8f5e2ca
7 files changed
+116 -9

No files matched your search

@@ -15,15 +15,11 @@ import java.sql.Types;
/** /**
* DB2 specific platform. * DB2 specific platform.
*/ */
public class DB2Platform extends DatabasePlatform { public abstract class BaseDB2Platform extends DatabasePlatform {
public DB2Platform() { public BaseDB2Platform() {
super(); super();
this.platform = Platform.DB2; this.platform = Platform.DB2;
// Note: DB2 (at least LUW supports length up to 128)
// TOOD: Check if we need to introduce a new platform (DB2_LUW_11 ?)
this.maxTableNameLength = 18;
this.maxConstraintNameLength = 18;
this.supportsNativeJavaTime = false; this.supportsNativeJavaTime = false;
this.truncateTable = "truncate table %s reuse storage ignore delete triggers immediate"; this.truncateTable = "truncate table %s reuse storage ignore delete triggers immediate";
this.sqlLimiter = new Db2SqlLimiter(); this.sqlLimiter = new Db2SqlLimiter();
@@ -0,0 +1,40 @@
package io.ebean.config.dbplatform.db2;
import io.ebean.annotation.PersistBatch;
import io.ebean.annotation.Platform;
import io.ebean.config.dbplatform.DbPlatformType;
import io.ebean.config.dbplatform.DbType;
import io.ebean.config.dbplatform.SqlErrorCodes;
import java.sql.Types;
/**
* DB2 specific platform for i Series.
* @author Cédric Sougné
*/
public class DB2ForIPlatform extends BaseDB2Platform {
public DB2ForIPlatform() {
super();
this.platform = Platform.DB2;
// Note: IBM i from 7.1 allow up to to 128
// TODO: Check if we need to introduce older platform (DB2ForI_6 ? but older documentation is not anymore published on ibm.com),
this.maxTableNameLength = 128;
this.maxConstraintNameLength = 128;
this.dbIdentity.setSupportsIdentity(true);
this.exceptionTranslator =
new SqlErrorCodes()
.addAcquireLock("57033") // key -913
.addDuplicateKey("23505") // -803
// .addDataIntegrity("-407","-530","-531","-532","-543","-544","-545","-603","-667")
// we need SQLState, not code: https://www.ibm.com/support/knowledgecenter/en/SSEPEK_10.0.0/codes/src/tpc/db2z_n.html
.addDataIntegrity("23502","23503","23504","23507","23511","23512","23513","42917","23515")
.build();
booleanDbType = Types.SMALLINT;
dbTypeMap.put(DbType.BOOLEAN, new DbPlatformType("smallint default 0"));
}
}
@@ -0,0 +1,20 @@
package io.ebean.config.dbplatform.db2;
import io.ebean.annotation.Platform;
/**
* DB2 specific platform for older DB2 versions. This platform is here for
* compatibility reasons. It uses a length limit of 18 chars for table and
* constraint names. Newer DB2 versions will support up to 128. It is strongly
* recommended to migrate to db2luw/DB2ForI or db2zos platform.
*/
public class DB2LegacyPlatform extends BaseDB2Platform {
public DB2LegacyPlatform() {
super();
this.platform = Platform.DB2;
// Note: DB2 (at least LUW supports length up to 128)
// TOOD: Check if we need to introduce a new platform (DB2_LUW_11 ?)
this.maxTableNameLength = 18;
this.maxConstraintNameLength = 18;
}
}
@@ -0,0 +1,17 @@
package io.ebean.config.dbplatform.db2;
import io.ebean.annotation.Platform;
/**
* DB2 platform for Linux/Unix/Windows.
* @author Roland Praml, FOCONIS AG
*
*/
public class DB2LuwPlatform extends BaseDB2Platform {
public DB2LuwPlatform() {
super();
this.platform = Platform.DB2; // TODO DB2LUW
this.maxTableNameLength = 128;
this.maxConstraintNameLength = 128;
}
}
@@ -0,0 +1,18 @@
package io.ebean.config.dbplatform.db2;
import io.ebean.annotation.Platform;
/**
* DB2 platform for z/OS.
* Note: This platform is currently not tested!
* @author Roland Praml, FOCONIS AG
*
*/
public class DB2ZosPlatform extends BaseDB2Platform {
public DB2ZosPlatform() {
super();
this.platform = Platform.DB2; // TODO DB2ZOS
this.maxTableNameLength = 128;
this.maxConstraintNameLength = 128;
}
}
@@ -4,7 +4,10 @@ import io.ebean.config.DatabaseConfig;
import io.ebean.config.dbplatform.DatabasePlatform; import io.ebean.config.dbplatform.DatabasePlatform;
import io.ebean.config.dbplatform.clickhouse.ClickHousePlatform; import io.ebean.config.dbplatform.clickhouse.ClickHousePlatform;
import io.ebean.config.dbplatform.cockroach.CockroachPlatform; import io.ebean.config.dbplatform.cockroach.CockroachPlatform;
import io.ebean.config.dbplatform.db2.DB2Platform; import io.ebean.config.dbplatform.db2.DB2ForIPlatform;
import io.ebean.config.dbplatform.db2.DB2LegacyPlatform;
import io.ebean.config.dbplatform.db2.DB2LuwPlatform;
import io.ebean.config.dbplatform.db2.DB2ZosPlatform;
import io.ebean.config.dbplatform.h2.H2Platform; import io.ebean.config.dbplatform.h2.H2Platform;
import io.ebean.config.dbplatform.hana.HanaPlatform; import io.ebean.config.dbplatform.hana.HanaPlatform;
import io.ebean.config.dbplatform.hsqldb.HsqldbPlatform; import io.ebean.config.dbplatform.hsqldb.HsqldbPlatform;
@@ -103,7 +106,19 @@ public class DatabasePlatformFactory {
return new SqlAnywherePlatform(); return new SqlAnywherePlatform();
} }
if (dbName.equals("db2")) { if (dbName.equals("db2")) {
return new DB2Platform(); throw new IllegalArgumentException("Please choose the more specific db2luw/db2zos/db2fori platform. Refer to issue #xxxx for details");
}
if (dbName.equals("db2legacy")) {
return new DB2LegacyPlatform();
}
if (dbName.equals("db2zos")) {
return new DB2ZosPlatform();
}
if (dbName.equals("db2fori")) {
return new DB2ForIPlatform();
}
if (dbName.equals("db2luw")) {
return new DB2LuwPlatform();
} }
if (dbName.equals("clickhouse")) { if (dbName.equals("clickhouse")) {
return new ClickHousePlatform(); return new ClickHousePlatform();
@@ -159,7 +174,7 @@ public class DatabasePlatformFactory {
} else if (dbProductName.contains("sqlite")) { } else if (dbProductName.contains("sqlite")) {
return new SQLitePlatform(); return new SQLitePlatform();
} else if (dbProductName.contains("db2")) { } else if (dbProductName.contains("db2")) {
return new DB2Platform(); throw new IllegalArgumentException("For DB2 please explicitly choose either db2legacy/db2luw/db2zos/db2fori platform. Refer to issue #xxxx for details");
} else if (dbProductName.contains("sql anywhere")) { } else if (dbProductName.contains("sql anywhere")) {
return new SqlAnywherePlatform(); return new SqlAnywherePlatform();
} else if (dbProductName.contains("hdb")) { } else if (dbProductName.contains("hdb")) {
@@ -2,3 +2,4 @@ ebean.test.platform=db2
ebean.test.dbName=unit ebean.test.dbName=unit
ebean.test.dbPassword=unit ebean.test.dbPassword=unit
datasource.default=db2-11 datasource.default=db2-11
ebean.db2-11.databasePlatformName=db2luw