diff --git a/src/main/java/com/avaje/ebean/config/dbplatform/DB2Platform.java b/src/main/java/com/avaje/ebean/config/dbplatform/DB2Platform.java index 832ceb6a3..9c0261481 100644 --- a/src/main/java/com/avaje/ebean/config/dbplatform/DB2Platform.java +++ b/src/main/java/com/avaje/ebean/config/dbplatform/DB2Platform.java @@ -24,9 +24,9 @@ public class DB2Platform extends DatabasePlatform { this.dbIdentity.setSupportsSequence(true); booleanDbType = Types.BOOLEAN; - dbTypeMap.put(Types.REAL, new DbType("real")); - dbTypeMap.put(Types.TINYINT, new DbType("smallint")); - dbTypeMap.put(Types.DECIMAL, new DbType("decimal", 15)); + dbTypeMap.put(DbType.REAL, new DbPlatformType("real")); + dbTypeMap.put(DbType.TINYINT, new DbPlatformType("smallint")); + dbTypeMap.put(DbType.DECIMAL, new DbPlatformType("decimal", 15)); } /** diff --git a/src/main/java/com/avaje/ebean/config/dbplatform/DatabasePlatform.java b/src/main/java/com/avaje/ebean/config/dbplatform/DatabasePlatform.java index cd243e4e4..9416cc7ba 100644 --- a/src/main/java/com/avaje/ebean/config/dbplatform/DatabasePlatform.java +++ b/src/main/java/com/avaje/ebean/config/dbplatform/DatabasePlatform.java @@ -73,7 +73,7 @@ public class DatabasePlatform { /** * Mapping of JDBC to Database types. */ - protected DbTypeMap dbTypeMap = new DbTypeMap(); + protected DbPlatformTypeMapping dbTypeMap = new DbPlatformTypeMapping(); /** * Default values for DB columns. @@ -309,7 +309,7 @@ public class DatabasePlatform { * * @return the db type map */ - public DbTypeMap getDbTypeMap() { + public DbPlatformTypeMapping getDbTypeMap() { return dbTypeMap; } diff --git a/src/main/java/com/avaje/ebean/config/dbplatform/DbPlatformType.java b/src/main/java/com/avaje/ebean/config/dbplatform/DbPlatformType.java new file mode 100644 index 000000000..5ff8c2c6e --- /dev/null +++ b/src/main/java/com/avaje/ebean/config/dbplatform/DbPlatformType.java @@ -0,0 +1,126 @@ +package com.avaje.ebean.config.dbplatform; + +/** + * Represents a DB type with name, length, precision, and scale. + *
+ * The length is for VARCHAR types and precision/scale for DECIMAL types. + *
+ */ +public class DbPlatformType implements ExtraDbTypes { + + /** + * The data type name (VARCHAR, INTEGER ...) + */ + private final String name; + + /** + * The default length or precision. + */ + private final int defaultLength; + + /** + * The default scale (decimal). + */ + private final int defaultScale; + + /** + * Set to true if the type should never have a length or scale. + */ + private final boolean canHaveLength; + + /** + * Construct with no length or scale. + */ + public DbPlatformType(String name) { + this(name, 0, 0); + } + + /** + * Construct with a given length. + */ + public DbPlatformType(String name, int defaultLength) { + this(name, defaultLength, 0); + } + + /** + * Construct for Decimal with precision and scale. + */ + public DbPlatformType(String name, int defaultPrecision, int defaultScale) { + this.name = name; + this.defaultLength = defaultPrecision; + this.defaultScale = defaultScale; + this.canHaveLength = true; + } + + /** + * Use with canHaveLength=false for types that should never have a length. + * + * @param name + * the type name + * @param canHaveLength + * set this to false for type that should never have a length + */ + public DbPlatformType(String name, boolean canHaveLength) { + this.name = name; + this.defaultLength = 0; + this.defaultScale = 0; + this.canHaveLength = canHaveLength; + } + + /** + * Return the type for a specific property that incorporates the name, length, + * precision and scale. + *+ * The deployLength and deployScale are for the property we are rendering the + * DB type for. + *
+ * + * @param deployLength + * the length or precision defined by deployment on a specific + * property. + * @param deployScale + * the scale defined by deployment on a specific property. + */ + public String renderType(int deployLength, int deployScale) { + return renderType(deployLength, deployScale, true); + } + + /** + * Render the type defining strict mode. + *+ * If strict mode if OFF then this will render with a scale value even if + * that is not strictly supported. The reason for supporting this is to enable + * use to use types like jsonb(200) as a "logical" type that maps to JSONB for + * Postgres and VARCHAR(200) for other databases. + *
+ */ + public String renderType(int deployLength, int deployScale, boolean strict) { + + StringBuilder sb = new StringBuilder(); + sb.append(name); + + if (canHaveLength || !strict) { + // see if there is a precision/scale to add (or not) + int len = deployLength != 0 ? deployLength : defaultLength; + if (len > 0) { + sb.append("("); + sb.append(len); + int scale = deployScale != 0 ? deployScale : defaultScale; + if (scale > 0) { + sb.append(","); + sb.append(scale); + } + sb.append(")"); + } + } + + return sb.toString(); + } + + /** + * Create a copy of the type with a new default length. + */ + public DbPlatformType withLength(int defaultLength) { + return new DbPlatformType(name, defaultLength); + } +} diff --git a/src/main/java/com/avaje/ebean/config/dbplatform/DbPlatformTypeLookup.java b/src/main/java/com/avaje/ebean/config/dbplatform/DbPlatformTypeLookup.java new file mode 100644 index 000000000..4ec001821 --- /dev/null +++ b/src/main/java/com/avaje/ebean/config/dbplatform/DbPlatformTypeLookup.java @@ -0,0 +1,53 @@ +package com.avaje.ebean.config.dbplatform; + +import java.util.HashMap; +import java.util.Map; + +/** + * Helper to reverse lookup a DbType given the name or JDBC int value. + */ +class DbPlatformTypeLookup { + + /** + * A map to lookup the type by name. + */ + private Map+ * This has some extended JSON types (JSON, JSONB, JSONVarchar, JSONClob, JSONBlob). + * These types get translated to specific database platform types during DDL generation. + */ + public static DbPlatformTypeMapping logicalTypes() { + return new DbPlatformTypeMapping(true); + } + + public DbPlatformTypeMapping() { + loadDefaults(false); + } + + private DbPlatformTypeMapping(boolean logicalTypes) { + loadDefaults(logicalTypes); + } + + /** + * Load the standard types. These can be overridden by DB specific platform. + */ + private void loadDefaults(boolean logicalTypes) { + + put(DbType.BOOLEAN); + put(DbType.BIT); + put(DbType.INTEGER); + put(DbType.BIGINT); + put(DbType.REAL, new DbPlatformType("float")); + + put(DbType.DOUBLE); + put(DbType.SMALLINT); + put(DbType.TINYINT); + put(DbType.DECIMAL, new DbPlatformType("decimal", 38)); + + put(DbType.VARCHAR, new DbPlatformType("varchar", 255)); + put(DbType.CHAR, new DbPlatformType("char", 1)); + + put(DbType.BLOB); + put(DbType.CLOB); + put(DbType.ARRAY); + + if (logicalTypes) { + // keep it logical for 2 layer DDL generation + put(DbType.HSTORE, new DbPlatformType("hstore", false)); + put(DbType.JSON, new DbPlatformType("json", false)); + put(DbType.JSONB, new DbPlatformType("jsonb", false)); + put(DbType.JSONCLOB, new DbPlatformType("jsonclob")); + put(DbType.JSONBLOB, new DbPlatformType("jsonblob")); + put(DbType.JSONVARCHAR, new DbPlatformType("jsonvarchar", 1000)); + put(DbType.UUID, UUID_NATIVE); + + } else { + put(DbType.JSON, JSON_CLOB_PLACEHOLDER); // Postgres maps this to JSON + put(DbType.JSONB, JSON_CLOB_PLACEHOLDER); // Postgres maps this to JSONB + put(DbType.JSONCLOB, JSON_CLOB_PLACEHOLDER); + put(DbType.JSONBLOB, JSON_BLOB_PLACEHOLDER); + put(DbType.JSONVARCHAR, JSON_VARCHAR_PLACEHOLDER); + put(DbType.UUID, UUID_PLACEHOLDER); + } + + put(DbType.LONGVARBINARY); + put(DbType.LONGVARCHAR); + put(DbType.VARBINARY, new DbPlatformType("varbinary", 255)); + put(DbType.BINARY, new DbPlatformType("binary", 255)); + + put(DbType.DATE); + put(DbType.TIME); + put(DbType.TIMESTAMP); + } + + /** + * Lookup the platform specific DbType given the standard sql type name. + */ + public DbPlatformType lookup(String name, boolean withScale) { + name = name.trim().toUpperCase(); + DbType type = lookup.byName(name); + if (type == null) { + throw new IllegalArgumentException("Unknown type [" + name + "] - not standard sql type"); + } + // handle JSON types mapped to clob, blob and varchar + switch (type) { + case JSONBLOB: + return get(DbType.BLOB); + case JSONCLOB: + return get(DbType.CLOB); + case JSONVARCHAR: + return get(DbType.VARCHAR); + case JSON: + return getJsonType(DbType.JSON, withScale); + case JSONB: + return getJsonType(DbType.JSONB, withScale); + default: + return get(type); + } + } + + private DbPlatformType getJsonType(DbType type, boolean withScale) { + DbPlatformType dbType = get(type); + if (dbType == JSON_CLOB_PLACEHOLDER) { + // if we have scale that implies this maps to varchar + return withScale ? get(Types.VARCHAR) : get(Types.CLOB); + } + if (dbType == JSON_BLOB_PLACEHOLDER) { + return get(Types.BLOB); + } + if (dbType == JSON_VARCHAR_PLACEHOLDER) { + return get(Types.VARCHAR); + } + // Postgres has specific type + return get(type); + } + + /** + * Override the type for a given JDBC type. + */ + private void put(DbType type) { + typeMap.put(type, type.createPlatformType()); + } + + /** + * Override the type for a given JDBC type. + */ + public void put(DbType type, DbPlatformType platformType) { + typeMap.put(type, platformType); + } + + /** + * Return the type for a given jdbc type. + */ + public DbPlatformType get(int jdbcType) { + DbType type = lookup.byId(jdbcType); + return get(type); + } + + /** + * Return the type for a given jdbc type. + */ + public DbPlatformType get(DbType dbType) { + return typeMap.get(dbType); + } + + /** + * Map the UUID appropriately based on native DB support and ServerConfig.DbUuid. + */ + public void config(boolean nativeUuidType, ServerConfig.DbUuid dbUuid) { + if (nativeUuidType && dbUuid.useNativeType()) { + put(DbType.UUID, UUID_NATIVE); + } else if (dbUuid.useBinary()) { + put(DbType.UUID, get(DbType.BINARY).withLength(16)); + } else { + put(DbType.UUID, get(DbType.VARCHAR).withLength(40)); + } + } +} diff --git a/src/main/java/com/avaje/ebean/config/dbplatform/DbType.java b/src/main/java/com/avaje/ebean/config/dbplatform/DbType.java index 1242cfa5d..616f7f0bf 100644 --- a/src/main/java/com/avaje/ebean/config/dbplatform/DbType.java +++ b/src/main/java/com/avaje/ebean/config/dbplatform/DbType.java @@ -1,161 +1,65 @@ package com.avaje.ebean.config.dbplatform; +import java.sql.Types; + /** - * Represents a DB type with name, length, precision, and scale. + * The known DB types that are mapped. *
- * The length is for VARCHAR types and precision/scale for DECIMAL types. + * This includes extra types such as UUID, JSON, JSONB and HSTORE. *
*/ -public class DbType { +public enum DbType { - /** - * DB native UUID type (H2 and Postgres). - */ - public static final int UUID = 5010; + BOOLEAN(Types.BOOLEAN), + BIT(Types.BIT), + INTEGER(Types.INTEGER), + BIGINT(Types.BIGINT), + SMALLINT(Types.SMALLINT), + TINYINT(Types.TINYINT), + REAL(Types.REAL), + //FLOAT(Types.FLOAT), + DOUBLE(Types.DOUBLE), + DECIMAL(Types.DECIMAL), + VARCHAR(Types.VARCHAR), + CHAR(Types.CHAR), + BLOB(Types.BLOB), + CLOB(Types.CLOB), + LONGVARBINARY(Types.LONGVARBINARY), + LONGVARCHAR(Types.LONGVARCHAR), + VARBINARY(Types.VARBINARY), + BINARY(Types.BINARY), + DATE(Types.DATE), + TIME(Types.TIME), + TIMESTAMP(Types.TIMESTAMP), - /** - * Type to map Map content to Postgres HSTORE. - */ - public static final int HSTORE = 5000; + ARRAY(Types.ARRAY), - /** - * Type to map JSON content to Clob or Postgres JSON type. - */ - public static final int JSON = 5001; + UUID(ExtraDbTypes.UUID), - /** - * Type to map JSON content to Clob or Postgres JSONB type. - */ - public static final int JSONB = 5002; + HSTORE(ExtraDbTypes.HSTORE), + JSON(ExtraDbTypes.JSON), + JSONB(ExtraDbTypes.JSONB), + JSONCLOB(ExtraDbTypes.JSONClob), + JSONBLOB(ExtraDbTypes.JSONBlob), + JSONVARCHAR(ExtraDbTypes.JSONVarchar); - /** - * Type to map JSON content to VARCHAR. - */ - public static final int JSONVarchar = 5003; + private final int id; - /** - * Type to map JSON content to Clob. - */ - public static final int JSONClob = 5004; - - /** - * Type to map JSON content to Blob. - */ - public static final int JSONBlob = 5005; - - /** - * The data type name (VARCHAR, INTEGER ...) - */ - private final String name; - - /** - * The default length or precision. - */ - private final int defaultLength; - - /** - * The default scale (decimal). - */ - private final int defaultScale; - - /** - * Set to true if the type should never have a length or scale. - */ - private final boolean canHaveLength; - - /** - * Construct with no length or scale. - */ - public DbType(String name) { - this(name, 0, 0); + DbType(int id) { + this.id = id; } /** - * Construct with a given length. + * Return the JDBC java.sql.Types value. */ - public DbType(String name, int defaultLength) { - this(name, defaultLength, 0); + public int id() { + return id; } /** - * Construct for Decimal with precision and scale. + * Create a platform type without scale or precision. */ - public DbType(String name, int defaultPrecision, int defaultScale) { - this.name = name; - this.defaultLength = defaultPrecision; - this.defaultScale = defaultScale; - this.canHaveLength = true; - } - - /** - * Use with canHaveLength=false for types that should never have a length. - * - * @param name - * the type name - * @param canHaveLength - * set this to false for type that should never have a length - */ - public DbType(String name, boolean canHaveLength) { - this.name = name; - this.defaultLength = 0; - this.defaultScale = 0; - this.canHaveLength = canHaveLength; - } - - /** - * Return the type for a specific property that incorporates the name, length, - * precision and scale. - *- * The deployLength and deployScale are for the property we are rendering the - * DB type for. - *
- * - * @param deployLength - * the length or precision defined by deployment on a specific - * property. - * @param deployScale - * the scale defined by deployment on a specific property. - */ - public String renderType(int deployLength, int deployScale) { - return renderType(deployLength, deployScale, true); - } - - /** - * Render the type defining strict mode. - *- * If strict mode if OFF then this will render with a scale value even if - * that is not strictly supported. The reason for supporting this is to enable - * use to use types like jsonb(200) as a "logical" type that maps to JSONB for - * Postgres and VARCHAR(200) for other databases. - *
- */ - public String renderType(int deployLength, int deployScale, boolean strict) { - - StringBuilder sb = new StringBuilder(); - sb.append(name); - - if (canHaveLength || !strict) { - // see if there is a precision/scale to add (or not) - int len = deployLength != 0 ? deployLength : defaultLength; - if (len > 0) { - sb.append("("); - sb.append(len); - int scale = deployScale != 0 ? deployScale : defaultScale; - if (scale > 0) { - sb.append(","); - sb.append(scale); - } - sb.append(")"); - } - } - - return sb.toString(); - } - - /** - * Create a copy of the type with a new default length. - */ - public DbType withLength(int defaultLength) { - return new DbType(name, defaultLength); + public DbPlatformType createPlatformType() { + return new DbPlatformType(name().toLowerCase()); } } diff --git a/src/main/java/com/avaje/ebean/config/dbplatform/DbTypeMap.java b/src/main/java/com/avaje/ebean/config/dbplatform/DbTypeMap.java deleted file mode 100644 index 56ec250f6..000000000 --- a/src/main/java/com/avaje/ebean/config/dbplatform/DbTypeMap.java +++ /dev/null @@ -1,210 +0,0 @@ -package com.avaje.ebean.config.dbplatform; - -import com.avaje.ebean.config.ServerConfig; - -import java.sql.Types; -import java.util.HashMap; -import java.util.Map; - -/** - * Used to map bean property types to DB specific types for DDL generation. - */ -public class DbTypeMap { - - private static final DbType UUID_NATIVE = new DbType("uuid", false); - private static final DbType UUID_PLACEHOLDER = new DbType("uuidPlaceholder"); - private static final DbType JSON_CLOB_PLACEHOLDER = new DbType("jsonClobPlaceholder"); - private static final DbType JSON_BLOB_PLACEHOLDER = new DbType("jsonBlobPlaceholder"); - private static final DbType JSON_VARCHAR_PLACEHOLDER = new DbType("jsonVarcharPlaceholder"); - - /** - * A map to reverse lookup the type by name. - *
- * Used when converting from logical types to platform types which we
- * want to do with 2 phase DDL generation.
- */
- static Map
- * This has some extended JSON types (JSON, JSONB, JSONVarchar, JSONClob, JSONBlob).
- * These types get translated to specific database platform types during DDL generation.
- */
- public static DbTypeMap logicalTypes() {
- return new DbTypeMap(true);
- }
-
- public DbTypeMap() {
- loadDefaults(false);
- }
-
- private DbTypeMap(boolean logicalTypes) {
- loadDefaults(logicalTypes);
- }
-
- /**
- * Load the standard types. These can be overridden by DB specific platform.
- */
- private void loadDefaults(boolean logicalTypes) {
-
- put(Types.BOOLEAN, new DbType("boolean"));
- put(Types.BIT, new DbType("bit"));
-
- put(Types.INTEGER, new DbType("integer"));
- put(Types.BIGINT, new DbType("bigint"));
- put(Types.REAL, new DbType("float"));
- put(Types.DOUBLE, new DbType("double"));
- put(Types.SMALLINT, new DbType("smallint"));
- put(Types.TINYINT, new DbType("tinyint"));
- put(Types.DECIMAL, new DbType("decimal", 38));
-
- put(Types.VARCHAR, new DbType("varchar", 255));
- put(Types.CHAR, new DbType("char", 1));
-
- put(Types.BLOB, new DbType("blob"));
- put(Types.CLOB, new DbType("clob"));
-
- put(Types.ARRAY, new DbType("array"));
-
- if (logicalTypes) {
- // keep it logical for 2 layer DDL generation
- put(DbType.HSTORE, new DbType("hstore", false));
- put(DbType.JSON, new DbType("json", false));
- put(DbType.JSONB, new DbType("jsonb", false));
- put(DbType.JSONClob, new DbType("jsonclob"));
- put(DbType.JSONBlob, new DbType("jsonblob"));
- put(DbType.JSONVarchar, new DbType("jsonvarchar", 1000));
- put(DbType.UUID, UUID_NATIVE);
-
- } else {
- put(DbType.JSON, JSON_CLOB_PLACEHOLDER); // Postgres maps this to JSON
- put(DbType.JSONB, JSON_CLOB_PLACEHOLDER); // Postgres maps this to JSONB
- put(DbType.JSONClob, JSON_CLOB_PLACEHOLDER);
- put(DbType.JSONBlob, JSON_BLOB_PLACEHOLDER);
- put(DbType.JSONVarchar, JSON_VARCHAR_PLACEHOLDER);
- put(DbType.UUID, UUID_PLACEHOLDER);
- }
-
- put(Types.LONGVARBINARY, new DbType("longvarbinary"));
- put(Types.LONGVARCHAR, new DbType("lonvarchar"));
- put(Types.VARBINARY, new DbType("varbinary", 255));
- put(Types.BINARY, new DbType("binary", 255));
-
- put(Types.DATE, new DbType("date"));
- put(Types.TIME, new DbType("time"));
- put(Types.TIMESTAMP, new DbType("timestamp"));
- }
-
- /**
- * Lookup the platform specific DbType given the standard sql type name.
- */
- public DbType lookup(String name, boolean withScale) {
- name = name.trim().toUpperCase();
- Integer typeKey = lookup.get(name);
- if (typeKey == null) {
- throw new IllegalArgumentException("Unknown type [" + name + "] - not standard sql type");
- }
- // handle JSON types mapped to clob, blob and varchar
- switch (typeKey) {
- case DbType.JSONBlob:
- return get(Types.BLOB);
- case DbType.JSONClob:
- return get(Types.CLOB);
- case DbType.JSONVarchar:
- return get(Types.VARCHAR);
- case DbType.JSON:
- return getJsonType(DbType.JSON, withScale);
- case DbType.JSONB:
- return getJsonType(DbType.JSONB, withScale);
- default:
- return get(typeKey);
- }
- }
-
- private DbType getJsonType(int type, boolean withScale) {
- DbType dbType = get(type);
- if (dbType == JSON_CLOB_PLACEHOLDER) {
- // if we have scale that implies this maps to varchar
- return withScale ? get(Types.VARCHAR) : get(Types.CLOB);
- }
- if (dbType == JSON_BLOB_PLACEHOLDER) {
- return get(Types.BLOB);
- }
- if (dbType == JSON_VARCHAR_PLACEHOLDER) {
- return get(Types.VARCHAR);
- }
- // Postgres has specific type
- return get(type);
- }
-
- /**
- * Override the type for a given JDBC type.
- */
- public void put(int jdbcType, DbType dbType) {
- typeMap.put(jdbcType, dbType);
- }
-
- /**
- * Return the type for a given jdbc type.
- */
- public DbType get(int jdbcType) {
- return typeMap.get(jdbcType);
- }
-
- /**
- * Map the UUID appropriately based on native DB support and ServerConfig.DbUuid.
- */
- public void config(boolean nativeUuidType, ServerConfig.DbUuid dbUuid) {
- if (nativeUuidType && dbUuid.useNativeType()) {
- put(DbType.UUID, UUID_NATIVE);
- } else if (dbUuid.useBinary()) {
- put(DbType.UUID, get(Types.BINARY).withLength(16));
- } else {
- put(DbType.UUID, get(Types.VARCHAR).withLength(40));
- }
- }
-}
diff --git a/src/main/java/com/avaje/ebean/config/dbplatform/ExtraDbTypes.java b/src/main/java/com/avaje/ebean/config/dbplatform/ExtraDbTypes.java
new file mode 100644
index 000000000..f8eac425a
--- /dev/null
+++ b/src/main/java/com/avaje/ebean/config/dbplatform/ExtraDbTypes.java
@@ -0,0 +1,43 @@
+package com.avaje.ebean.config.dbplatform;
+
+/**
+ * Integer codes for the extra types beyond java.sql.Types.
+ */
+public interface ExtraDbTypes {
+
+ /**
+ * DB native UUID type (H2 and Postgres).
+ */
+ int UUID = 5010;
+
+ /**
+ * Type to map Map content to Postgres HSTORE.
+ */
+ int HSTORE = 5000;
+
+ /**
+ * Type to map JSON content to Clob or Postgres JSON type.
+ */
+ int JSON = 5001;
+
+ /**
+ * Type to map JSON content to Clob or Postgres JSONB type.
+ */
+ int JSONB = 5002;
+
+ /**
+ * Type to map JSON content to VARCHAR.
+ */
+ int JSONVarchar = 5003;
+
+ /**
+ * Type to map JSON content to Clob.
+ */
+ int JSONClob = 5004;
+
+ /**
+ * Type to map JSON content to Blob.
+ */
+ int JSONBlob = 5005;
+
+}
diff --git a/src/main/java/com/avaje/ebean/config/dbplatform/HsqldbPlatform.java b/src/main/java/com/avaje/ebean/config/dbplatform/HsqldbPlatform.java
index e34605142..8ae8ad499 100644
--- a/src/main/java/com/avaje/ebean/config/dbplatform/HsqldbPlatform.java
+++ b/src/main/java/com/avaje/ebean/config/dbplatform/HsqldbPlatform.java
@@ -4,7 +4,6 @@ import com.avaje.ebean.BackgroundExecutor;
import com.avaje.ebean.dbmigration.ddlgeneration.platform.HsqldbDdl;
import javax.sql.DataSource;
-import java.sql.Types;
/**
* H2 specific platform.
@@ -22,7 +21,7 @@ public class HsqldbPlatform extends DatabasePlatform {
this.dbIdentity.setSupportsSequence(true);
this.dbIdentity.setSupportsIdentity(true);
- dbTypeMap.put(Types.INTEGER, new DbType("integer", false));
+ dbTypeMap.put(DbType.INTEGER, new DbPlatformType("integer", false));
}
@Override
diff --git a/src/main/java/com/avaje/ebean/config/dbplatform/MsSqlServer2000Platform.java b/src/main/java/com/avaje/ebean/config/dbplatform/MsSqlServer2000Platform.java
index 5fd072352..1a8da0353 100644
--- a/src/main/java/com/avaje/ebean/config/dbplatform/MsSqlServer2000Platform.java
+++ b/src/main/java/com/avaje/ebean/config/dbplatform/MsSqlServer2000Platform.java
@@ -2,8 +2,6 @@ package com.avaje.ebean.config.dbplatform;
import com.avaje.ebean.config.PersistBatch;
-import java.sql.Types;
-
/**
* Microsoft SQL Server 2000 specific platform.
*
@@ -29,22 +27,22 @@ public class MsSqlServer2000Platform extends DatabasePlatform {
this.openQuote = "[";
this.closeQuote = "]";
- dbTypeMap.put(Types.BOOLEAN, new DbType("bit default 0"));
+ dbTypeMap.put(DbType.BOOLEAN, new DbPlatformType("bit default 0"));
- dbTypeMap.put(Types.BIGINT, new DbType("numeric", 19));
- dbTypeMap.put(Types.REAL, new DbType("float(16)"));
- dbTypeMap.put(Types.DOUBLE, new DbType("float(32)"));
- dbTypeMap.put(Types.TINYINT, new DbType("smallint"));
- dbTypeMap.put(Types.DECIMAL, new DbType("numeric", 28));
+ dbTypeMap.put(DbType.BIGINT, new DbPlatformType("numeric", 19));
+ dbTypeMap.put(DbType.REAL, new DbPlatformType("float(16)"));
+ dbTypeMap.put(DbType.DOUBLE, new DbPlatformType("float(32)"));
+ dbTypeMap.put(DbType.TINYINT, new DbPlatformType("smallint"));
+ dbTypeMap.put(DbType.DECIMAL, new DbPlatformType("numeric", 28));
- dbTypeMap.put(Types.BLOB, new DbType("image"));
- dbTypeMap.put(Types.CLOB, new DbType("text"));
- dbTypeMap.put(Types.LONGVARBINARY, new DbType("image"));
- dbTypeMap.put(Types.LONGVARCHAR, new DbType("text"));
+ dbTypeMap.put(DbType.BLOB, new DbPlatformType("image"));
+ dbTypeMap.put(DbType.CLOB, new DbPlatformType("text"));
+ dbTypeMap.put(DbType.LONGVARBINARY, new DbPlatformType("image"));
+ dbTypeMap.put(DbType.LONGVARCHAR, new DbPlatformType("text"));
- dbTypeMap.put(Types.DATE, new DbType("datetime"));
- dbTypeMap.put(Types.TIME, new DbType("datetime"));
- dbTypeMap.put(Types.TIMESTAMP, new DbType("datetime"));
+ dbTypeMap.put(DbType.DATE, new DbPlatformType("datetime"));
+ dbTypeMap.put(DbType.TIME, new DbPlatformType("datetime"));
+ dbTypeMap.put(DbType.TIMESTAMP, new DbPlatformType("datetime"));
}
diff --git a/src/main/java/com/avaje/ebean/config/dbplatform/MsSqlServer2005Platform.java b/src/main/java/com/avaje/ebean/config/dbplatform/MsSqlServer2005Platform.java
index 8a0882bb6..2a9c76cc5 100644
--- a/src/main/java/com/avaje/ebean/config/dbplatform/MsSqlServer2005Platform.java
+++ b/src/main/java/com/avaje/ebean/config/dbplatform/MsSqlServer2005Platform.java
@@ -3,8 +3,6 @@ package com.avaje.ebean.config.dbplatform;
import com.avaje.ebean.config.PersistBatch;
import com.avaje.ebean.dbmigration.ddlgeneration.platform.MsSqlServerDdl;
-import java.sql.Types;
-
/**
* Microsoft SQL Server 2005 specific platform.
*
@@ -34,23 +32,23 @@ public class MsSqlServer2005Platform extends DatabasePlatform {
this.openQuote = "[";
this.closeQuote = "]";
- dbTypeMap.put(Types.BOOLEAN, new DbType("bit default 0"));
+ dbTypeMap.put(DbType.BOOLEAN, new DbPlatformType("bit default 0"));
- dbTypeMap.put(Types.INTEGER, new DbType("integer", false));
- dbTypeMap.put(Types.BIGINT, new DbType("numeric", 19));
- dbTypeMap.put(Types.REAL, new DbType("float(16)"));
- dbTypeMap.put(Types.DOUBLE, new DbType("float(32)"));
- dbTypeMap.put(Types.TINYINT, new DbType("smallint"));
- dbTypeMap.put(Types.DECIMAL, new DbType("numeric", 28));
+ dbTypeMap.put(DbType.INTEGER, new DbPlatformType("integer", false));
+ dbTypeMap.put(DbType.BIGINT, new DbPlatformType("numeric", 19));
+ dbTypeMap.put(DbType.REAL, new DbPlatformType("float(16)"));
+ dbTypeMap.put(DbType.DOUBLE, new DbPlatformType("float(32)"));
+ dbTypeMap.put(DbType.TINYINT, new DbPlatformType("smallint"));
+ dbTypeMap.put(DbType.DECIMAL, new DbPlatformType("numeric", 28));
- dbTypeMap.put(Types.BLOB, new DbType("image"));
- dbTypeMap.put(Types.CLOB, new DbType("text"));
- dbTypeMap.put(Types.LONGVARBINARY, new DbType("image"));
- dbTypeMap.put(Types.LONGVARCHAR, new DbType("text"));
+ dbTypeMap.put(DbType.BLOB, new DbPlatformType("image"));
+ dbTypeMap.put(DbType.CLOB, new DbPlatformType("text"));
+ dbTypeMap.put(DbType.LONGVARBINARY, new DbPlatformType("image"));
+ dbTypeMap.put(DbType.LONGVARCHAR, new DbPlatformType("text"));
- dbTypeMap.put(Types.DATE, new DbType("date"));
- dbTypeMap.put(Types.TIME, new DbType("time"));
- dbTypeMap.put(Types.TIMESTAMP, new DbType("datetime2"));
+ dbTypeMap.put(DbType.DATE, new DbPlatformType("date"));
+ dbTypeMap.put(DbType.TIME, new DbPlatformType("time"));
+ dbTypeMap.put(DbType.TIMESTAMP, new DbPlatformType("datetime2"));
}
diff --git a/src/main/java/com/avaje/ebean/config/dbplatform/MySqlBlob.java b/src/main/java/com/avaje/ebean/config/dbplatform/MySqlBlob.java
index 7e171fc10..b3482b30b 100644
--- a/src/main/java/com/avaje/ebean/config/dbplatform/MySqlBlob.java
+++ b/src/main/java/com/avaje/ebean/config/dbplatform/MySqlBlob.java
@@ -7,7 +7,7 @@ package com.avaje.ebean.config.dbplatform;
* If no deployment length is defined longblob is used.
*
@@ -23,17 +21,17 @@ public class SqlAnywherePlatform extends DatabasePlatform { this.dbIdentity.setSelectLastInsertedIdTemplate("select @@IDENTITY as X"); this.dbIdentity.setSupportsIdentity(true); - dbTypeMap.put(Types.BOOLEAN, new DbType("bit default 0")); - dbTypeMap.put(Types.BIGINT, new DbType("numeric", 19)); - dbTypeMap.put(Types.REAL, new DbType("float(16)")); - dbTypeMap.put(Types.DOUBLE, new DbType("float(32)")); - dbTypeMap.put(Types.TINYINT, new DbType("smallint")); - dbTypeMap.put(Types.DECIMAL, new DbType("numeric", 28)); + dbTypeMap.put(DbType.BOOLEAN, new DbPlatformType("bit default 0")); + dbTypeMap.put(DbType.BIGINT, new DbPlatformType("numeric", 19)); + dbTypeMap.put(DbType.REAL, new DbPlatformType("float(16)")); + dbTypeMap.put(DbType.DOUBLE, new DbPlatformType("float(32)")); + dbTypeMap.put(DbType.TINYINT, new DbPlatformType("smallint")); + dbTypeMap.put(DbType.DECIMAL, new DbPlatformType("numeric", 28)); - dbTypeMap.put(Types.BLOB, new DbType("binary(4500)")); - dbTypeMap.put(Types.CLOB, new DbType("long varchar")); - dbTypeMap.put(Types.LONGVARBINARY, new DbType("long binary")); - dbTypeMap.put(Types.LONGVARCHAR, new DbType("long varchar")); + dbTypeMap.put(DbType.BLOB, new DbPlatformType("binary(4500)")); + dbTypeMap.put(DbType.CLOB, new DbPlatformType("long varchar")); + dbTypeMap.put(DbType.LONGVARBINARY, new DbPlatformType("long binary")); + dbTypeMap.put(DbType.LONGVARCHAR, new DbPlatformType("long varchar")); } diff --git a/src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/platform/util/PlatformTypeConverter.java b/src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/platform/util/PlatformTypeConverter.java index 53fe5f23b..104167bda 100644 --- a/src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/platform/util/PlatformTypeConverter.java +++ b/src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/platform/util/PlatformTypeConverter.java @@ -1,7 +1,7 @@ package com.avaje.ebean.dbmigration.ddlgeneration.platform.util; -import com.avaje.ebean.config.dbplatform.DbType; -import com.avaje.ebean.config.dbplatform.DbTypeMap; +import com.avaje.ebean.config.dbplatform.DbPlatformType; +import com.avaje.ebean.config.dbplatform.DbPlatformTypeMapping; /** * Converts a logical column definition into platform specific one. @@ -10,12 +10,12 @@ import com.avaje.ebean.config.dbplatform.DbTypeMap; */ public class PlatformTypeConverter { - protected final DbTypeMap platformTypes; + protected final DbPlatformTypeMapping platformTypes; /** * Construct with the platform specific types. */ - public PlatformTypeConverter(DbTypeMap platformTypes) { + public PlatformTypeConverter(DbPlatformTypeMapping platformTypes) { this.platformTypes = platformTypes; } @@ -47,7 +47,7 @@ public class PlatformTypeConverter { String suffix = close + 1 < columnDefinition.length() ? columnDefinition.substring(close + 1) : ""; String type = columnDefinition.substring(0, open); try { - DbType dbType = platformTypes.lookup(type, true); + DbPlatformType dbType = platformTypes.lookup(type, true); int comma = columnDefinition.indexOf(',', open); if (comma > -1) { // scale and precision - decimal(10,4) @@ -73,7 +73,7 @@ public class PlatformTypeConverter { protected String convertNoScale(String columnDefinition) { try { - DbType dbType = platformTypes.lookup(columnDefinition, false); + DbPlatformType dbType = platformTypes.lookup(columnDefinition, false); return dbType.renderType(0, 0); } catch (IllegalArgumentException e) { diff --git a/src/main/java/com/avaje/ebean/dbmigration/model/build/ModelBuildBeanVisitor.java b/src/main/java/com/avaje/ebean/dbmigration/model/build/ModelBuildBeanVisitor.java index 3db639e35..d451af807 100644 --- a/src/main/java/com/avaje/ebean/dbmigration/model/build/ModelBuildBeanVisitor.java +++ b/src/main/java/com/avaje/ebean/dbmigration/model/build/ModelBuildBeanVisitor.java @@ -1,6 +1,6 @@ package com.avaje.ebean.dbmigration.model.build; -import com.avaje.ebean.config.dbplatform.DbType; +import com.avaje.ebean.config.dbplatform.DbPlatformType; import com.avaje.ebean.config.dbplatform.IdType; import com.avaje.ebean.dbmigration.migration.IdentityType; import com.avaje.ebean.dbmigration.model.MColumn; @@ -52,7 +52,7 @@ public class ModelBuildBeanVisitor implements BeanVisitor { if (inheritInfo != null && inheritInfo.isRoot()) { // add the discriminator column String discColumn = inheritInfo.getDiscriminatorColumn(); - DbType dbType = ctx.getDbTypeMap().get(inheritInfo.getDiscriminatorType()); + DbPlatformType dbType = ctx.getDbTypeMap().get(inheritInfo.getDiscriminatorType()); String discDbType = dbType.renderType(inheritInfo.getDiscriminatorLength(), 0); table.addColumn(new MColumn(discColumn, discDbType, true)); diff --git a/src/main/java/com/avaje/ebean/dbmigration/model/build/ModelBuildContext.java b/src/main/java/com/avaje/ebean/dbmigration/model/build/ModelBuildContext.java index 949e6b154..e18c53356 100644 --- a/src/main/java/com/avaje/ebean/dbmigration/model/build/ModelBuildContext.java +++ b/src/main/java/com/avaje/ebean/dbmigration/model/build/ModelBuildContext.java @@ -1,8 +1,8 @@ package com.avaje.ebean.dbmigration.model.build; import com.avaje.ebean.config.DbConstraintNaming; -import com.avaje.ebean.config.dbplatform.DbType; -import com.avaje.ebean.config.dbplatform.DbTypeMap; +import com.avaje.ebean.config.dbplatform.DbPlatformType; +import com.avaje.ebean.config.dbplatform.DbPlatformTypeMapping; import com.avaje.ebean.dbmigration.model.MColumn; import com.avaje.ebean.dbmigration.model.MTable; import com.avaje.ebean.dbmigration.model.ModelContainer; @@ -21,7 +21,7 @@ public class ModelBuildContext { * Use platform agnostic logical types. These types are converted to * platform specific types in the DDL generation. */ - private final DbTypeMap dbTypeMap = DbTypeMap.logicalTypes(); + private final DbPlatformTypeMapping dbTypeMap = DbPlatformTypeMapping.logicalTypes(); private final ModelContainer model; @@ -106,7 +106,7 @@ public class ModelBuildContext { * Return the map used to determine the DB specific type * for a given bean property. */ - public DbTypeMap getDbTypeMap() { + public DbPlatformTypeMapping getDbTypeMap() { return dbTypeMap; } @@ -115,14 +115,14 @@ public class ModelBuildContext { * Render the DB type for this property given the strict mode. */ public String getColumnDefn(BeanProperty p, boolean strict) { - DbType dbType = getDbType(p); + DbPlatformType dbType = getDbType(p); if (dbType == null) { throw new IllegalStateException("Unknown DbType mapping for " + p.getFullBeanName()); } return p.renderDbType(dbType, strict); } - private DbType getDbType(BeanProperty p) { + private DbPlatformType getDbType(BeanProperty p) { if (p.isDbEncrypted()) { return dbTypeMap.get(p.getDbEncryptedType()); diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanProperty.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanProperty.java index 965b7b775..98458338e 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanProperty.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanProperty.java @@ -5,7 +5,7 @@ import com.avaje.ebean.bean.EntityBean; import com.avaje.ebean.bean.PersistenceContext; import com.avaje.ebean.config.EncryptKey; import com.avaje.ebean.config.dbplatform.DbEncryptFunction; -import com.avaje.ebean.config.dbplatform.DbType; +import com.avaje.ebean.config.dbplatform.DbPlatformType; import com.avaje.ebean.plugin.Property; import com.avaje.ebean.text.StringParser; import com.avaje.ebeaninternal.api.SpiExpressionRequest; @@ -972,7 +972,7 @@ public class BeanProperty implements ElPropertyValue, Property { /** * Return the DB column type definition. */ - public String renderDbType(DbType dbType, boolean strict) { + public String renderDbType(DbPlatformType dbType, boolean strict) { if (dbColumnDefn != null) { return dbColumnDefn; } diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/DeployUtil.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/DeployUtil.java index 4515a44d2..6ac806c88 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/DeployUtil.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/DeployUtil.java @@ -18,7 +18,7 @@ import com.avaje.ebean.config.NamingConvention; import com.avaje.ebean.config.ServerConfig; import com.avaje.ebean.config.TableName; import com.avaje.ebean.config.dbplatform.DatabasePlatform; -import com.avaje.ebean.config.dbplatform.DbType; +import com.avaje.ebean.config.dbplatform.DbPlatformType; import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanProperty; import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanPropertyCompound; import com.avaje.ebeaninternal.server.type.DataEncryptSupport; @@ -254,7 +254,7 @@ public class DeployUtil { } public void setDbJsonBType(DeployBeanProperty prop, DbJsonB dbJsonB) { - setDbJsonType(prop, DbType.JSONB, dbJsonB.length()); + setDbJsonType(prop, DbPlatformType.JSONB, dbJsonB.length()); } private void setDbJsonType(DeployBeanProperty prop, int dbType, int dbLength) { @@ -280,9 +280,9 @@ public class DeployUtil { switch (dbJsonType) { case JSON: - return DbType.JSON; + return DbPlatformType.JSON; case JSONB: - return DbType.JSONB; + return DbPlatformType.JSONB; case VARCHAR: return Types.VARCHAR; case CLOB: @@ -290,7 +290,7 @@ public class DeployUtil { case BLOB: return Types.BLOB; default: - return DbType.JSON; + return DbPlatformType.JSON; } } diff --git a/src/main/java/com/avaje/ebeaninternal/server/persist/Binder.java b/src/main/java/com/avaje/ebeaninternal/server/persist/Binder.java index fec91ab45..5c51fae18 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/persist/Binder.java +++ b/src/main/java/com/avaje/ebeaninternal/server/persist/Binder.java @@ -11,7 +11,7 @@ import java.util.List; import javax.persistence.PersistenceException; -import com.avaje.ebean.config.dbplatform.DbType; +import com.avaje.ebean.config.dbplatform.DbPlatformType; import com.avaje.ebeaninternal.api.BindParams; import com.avaje.ebeaninternal.server.core.DbExpressionHandler; import com.avaje.ebeaninternal.server.core.Message; @@ -321,7 +321,7 @@ public class Binder { b.setBytes((byte[]) data); break; - case DbType.UUID: + case DbPlatformType.UUID: // native UUID support in H2 and Postgres b.setObject(data); break; diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/DefaultTypeManager.java b/src/main/java/com/avaje/ebeaninternal/server/type/DefaultTypeManager.java index 9b4ad0f40..1bdf25101 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/type/DefaultTypeManager.java +++ b/src/main/java/com/avaje/ebeaninternal/server/type/DefaultTypeManager.java @@ -10,7 +10,7 @@ import com.avaje.ebean.config.JsonConfig; import com.avaje.ebean.config.ScalarTypeConverter; import com.avaje.ebean.config.ServerConfig; import com.avaje.ebean.config.dbplatform.DatabasePlatform; -import com.avaje.ebean.config.dbplatform.DbType; +import com.avaje.ebean.config.dbplatform.DbPlatformType; import com.avaje.ebean.dbmigration.DbOffline; import com.avaje.ebeaninternal.server.core.bootup.BootupClasses; import com.avaje.ebeaninternal.server.type.reflect.CheckImmutable; @@ -421,9 +421,9 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable { return jsonNodeBlob; case Types.CLOB: return jsonNodeClob; - case DbType.JSONB: + case DbPlatformType.JSONB: return jsonNodeJsonb; - case DbType.JSON: + case DbPlatformType.JSON: return jsonNodeJson; default: return jsonNodeJson; @@ -939,7 +939,7 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable { int platformClobType = databasePlatform.getClobDbType(); int platformBlobType = databasePlatform.getBlobDbType(); - nativeMap.put(DbType.HSTORE, hstoreType); + nativeMap.put(DbPlatformType.HSTORE, hstoreType); ScalarType> utilDateType = extraTypeFactory.createUtilDate(mode); typeMap.put(java.util.Date.class, utilDateType); diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJsonList.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJsonList.java index 5e5e5589e..b157a1c64 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJsonList.java +++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJsonList.java @@ -1,6 +1,6 @@ package com.avaje.ebeaninternal.server.type; -import com.avaje.ebean.config.dbplatform.DbType; +import com.avaje.ebean.config.dbplatform.DbPlatformType; import com.avaje.ebean.text.json.EJson; import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyType; import com.fasterxml.jackson.core.JsonGenerator; @@ -22,9 +22,9 @@ public class ScalarTypeJsonList { public static ScalarType> typeFor(boolean postgres, int dbType, DocPropertyType docType) { if (postgres) { switch (dbType) { - case DbType.JSONB: + case DbPlatformType.JSONB: return new ScalarTypeJsonList.JsonB(docType); - case DbType.JSON: + case DbPlatformType.JSON: return new ScalarTypeJsonList.Json(docType); } } @@ -45,7 +45,7 @@ public class ScalarTypeJsonList { */ private static class Json extends ScalarTypeJsonList.PgBase { public Json(DocPropertyType docType) { - super(DbType.JSON, PostgresHelper.JSON_TYPE, docType); + super(DbPlatformType.JSON, PostgresHelper.JSON_TYPE, docType); } } @@ -54,7 +54,7 @@ public class ScalarTypeJsonList { */ private static class JsonB extends ScalarTypeJsonList.PgBase { public JsonB(DocPropertyType docType) { - super(DbType.JSONB, PostgresHelper.JSONB_TYPE, docType); + super(DbPlatformType.JSONB, PostgresHelper.JSONB_TYPE, docType); } } diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJsonMap.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJsonMap.java index c946b6f29..29134f32b 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJsonMap.java +++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJsonMap.java @@ -1,6 +1,6 @@ package com.avaje.ebeaninternal.server.type; -import com.avaje.ebean.config.dbplatform.DbType; +import com.avaje.ebean.config.dbplatform.DbPlatformType; import com.avaje.ebean.text.TextException; import com.avaje.ebean.text.json.EJson; import com.avaje.ebeaninternal.util.EncodeUtil; @@ -41,9 +41,9 @@ public abstract class ScalarTypeJsonMap extends ScalarTypeBase