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 nameLookup = new HashMap(); + + /** + * A map to lookup the type by JDBC int value. + */ + private Map idLookup = new HashMap(); + + DbPlatformTypeLookup() { + addAll(); + } + + /** + * Return the DbType for the given name. + */ + DbType byName(String name) { + return nameLookup.get(name.toUpperCase()); + } + + /** + * Return the DbType for the given name. + */ + DbType byId(int jdbcId) { + return idLookup.get(jdbcId); + } + + private void addAll() { + // Extra mapping for Float and Varchar2 + add("FLOAT", DbType.REAL); + add("VARCHAR2", DbType.VARCHAR); + for (DbType type : DbType.values()) { + add(type.name(), type); + } + } + + private void add(String name, DbType dbType) { + nameLookup.put(name, dbType); + idLookup.put(dbType.id(), dbType); + } + +} diff --git a/src/main/java/com/avaje/ebean/config/dbplatform/DbPlatformTypeMapping.java b/src/main/java/com/avaje/ebean/config/dbplatform/DbPlatformTypeMapping.java new file mode 100644 index 000000000..389f4b3c5 --- /dev/null +++ b/src/main/java/com/avaje/ebean/config/dbplatform/DbPlatformTypeMapping.java @@ -0,0 +1,177 @@ +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 DbPlatformTypeMapping { + + private static DbPlatformTypeLookup lookup = new DbPlatformTypeLookup(); + + private static final DbPlatformType UUID_NATIVE = new DbPlatformType("uuid", false); + private static final DbPlatformType UUID_PLACEHOLDER = new DbPlatformType("uuidPlaceholder"); + private static final DbPlatformType JSON_CLOB_PLACEHOLDER = new DbPlatformType("jsonClobPlaceholder"); + private static final DbPlatformType JSON_BLOB_PLACEHOLDER = new DbPlatformType("jsonBlobPlaceholder"); + private static final DbPlatformType JSON_VARCHAR_PLACEHOLDER = new DbPlatformType("jsonVarcharPlaceholder"); + + private final Map typeMap = new HashMap(); + + /** + * Return the DbTypeMap with standard (not platform specific) types. + *

+ * 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 lookup = new HashMap(); - - static { - lookup.put("BOOLEAN", Types.BOOLEAN); - lookup.put("BIT", Types.BIT); - lookup.put("INTEGER", Types.INTEGER); - lookup.put("BIGINT", Types.BIGINT); - lookup.put("REAL", Types.REAL); - // Float is most common REAL mapping to have that as well - lookup.put("FLOAT", Types.REAL); - - lookup.put("DOUBLE", Types.DOUBLE); - lookup.put("SMALLINT", Types.SMALLINT); - lookup.put("TINYINT", Types.TINYINT); - lookup.put("DECIMAL", Types.DECIMAL); - lookup.put("VARCHAR", Types.VARCHAR); - // VARCHAR2 - extra for Oracle specific column definition - lookup.put("VARCHAR2", Types.VARCHAR); - lookup.put("CHAR", Types.CHAR); - lookup.put("BLOB", Types.BLOB); - lookup.put("CLOB", Types.CLOB); - - lookup.put("LONGVARBINARY", Types.LONGVARBINARY); - lookup.put("LONGVARCHAR", Types.LONGVARCHAR); - lookup.put("VARBINARY", Types.VARBINARY); - lookup.put("BINARY", Types.BINARY); - lookup.put("DATE", Types.DATE); - lookup.put("TIME", Types.TIME); - lookup.put("TIMESTAMP", Types.TIMESTAMP); - - lookup.put("ARRAY", Types.ARRAY); - lookup.put("UUID", DbType.UUID); - - // Not standard java.sql.Types - // logical JSON storage types - lookup.put("JSON", DbType.JSON); - lookup.put("JSONB", DbType.JSONB); - lookup.put("JSONCLOB", DbType.JSONClob); - lookup.put("JSONBLOB", DbType.JSONBlob); - lookup.put("JSONVARCHAR", DbType.JSONVarchar); - } - - - private final Map typeMap = new HashMap(); - - /** - * Return the DbTypeMap with standard (not platform specific) types. - *

- * 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. *

*/ -public class MySqlBlob extends DbType { +public class MySqlBlob extends DbPlatformType { private static final int POWER_2_16 = 65536; private static final int POWER_2_24 = 16777216; diff --git a/src/main/java/com/avaje/ebean/config/dbplatform/MySqlClob.java b/src/main/java/com/avaje/ebean/config/dbplatform/MySqlClob.java index 9f8c5b098..9fbb61cdd 100644 --- a/src/main/java/com/avaje/ebean/config/dbplatform/MySqlClob.java +++ b/src/main/java/com/avaje/ebean/config/dbplatform/MySqlClob.java @@ -7,7 +7,7 @@ package com.avaje.ebean.config.dbplatform; * If no deployment length is defined longtext is used. *

*/ -public class MySqlClob extends DbType { +public class MySqlClob extends DbPlatformType { private static final int POWER_2_16 = 65536; private static final int POWER_2_24 = 16777216; diff --git a/src/main/java/com/avaje/ebean/config/dbplatform/MySqlPlatform.java b/src/main/java/com/avaje/ebean/config/dbplatform/MySqlPlatform.java index d8812266a..718da4e19 100644 --- a/src/main/java/com/avaje/ebean/config/dbplatform/MySqlPlatform.java +++ b/src/main/java/com/avaje/ebean/config/dbplatform/MySqlPlatform.java @@ -39,13 +39,13 @@ public class MySqlPlatform extends DatabasePlatform { this.forwardOnlyHintOnFindIterate = true; this.booleanDbType = Types.BIT; - dbTypeMap.put(Types.BIT, new DbType("tinyint(1) default 0")); - dbTypeMap.put(Types.BOOLEAN, new DbType("tinyint(1) default 0")); - dbTypeMap.put(Types.TIMESTAMP, new DbType("datetime(6)")); - dbTypeMap.put(Types.CLOB, new MySqlClob()); - dbTypeMap.put(Types.BLOB, new MySqlBlob()); - dbTypeMap.put(Types.BINARY, new DbType("binary", 255)); - dbTypeMap.put(Types.VARBINARY, new DbType("varbinary", 255)); + dbTypeMap.put(DbType.BIT, new DbPlatformType("tinyint(1) default 0")); + dbTypeMap.put(DbType.BOOLEAN, new DbPlatformType("tinyint(1) default 0")); + dbTypeMap.put(DbType.TIMESTAMP, new DbPlatformType("datetime(6)")); + dbTypeMap.put(DbType.CLOB, new MySqlClob()); + dbTypeMap.put(DbType.BLOB, new MySqlBlob()); + dbTypeMap.put(DbType.BINARY, new DbPlatformType("binary", 255)); + dbTypeMap.put(DbType.VARBINARY, new DbPlatformType("varbinary", 255)); } /** diff --git a/src/main/java/com/avaje/ebean/config/dbplatform/OraclePlatform.java b/src/main/java/com/avaje/ebean/config/dbplatform/OraclePlatform.java index 66c30aab9..5f60dc8ac 100644 --- a/src/main/java/com/avaje/ebean/config/dbplatform/OraclePlatform.java +++ b/src/main/java/com/avaje/ebean/config/dbplatform/OraclePlatform.java @@ -34,24 +34,24 @@ public class OraclePlatform extends DatabasePlatform { this.closeQuote = "\""; booleanDbType = Types.INTEGER; - dbTypeMap.put(Types.BOOLEAN, new DbType("number(1) default 0")); + dbTypeMap.put(DbType.BOOLEAN, new DbPlatformType("number(1) default 0")); - dbTypeMap.put(Types.INTEGER, new DbType("number", 10)); - dbTypeMap.put(Types.BIGINT, new DbType("number", 19)); - dbTypeMap.put(Types.REAL, new DbType("number", 19, 4)); - dbTypeMap.put(Types.DOUBLE, new DbType("number", 19, 4)); - dbTypeMap.put(Types.SMALLINT, new DbType("number", 5)); - dbTypeMap.put(Types.TINYINT, new DbType("number", 3)); - dbTypeMap.put(Types.DECIMAL, new DbType("number", 38)); + dbTypeMap.put(DbType.INTEGER, new DbPlatformType("number", 10)); + dbTypeMap.put(DbType.BIGINT, new DbPlatformType("number", 19)); + dbTypeMap.put(DbType.REAL, new DbPlatformType("number", 19, 4)); + dbTypeMap.put(DbType.DOUBLE, new DbPlatformType("number", 19, 4)); + dbTypeMap.put(DbType.SMALLINT, new DbPlatformType("number", 5)); + dbTypeMap.put(DbType.TINYINT, new DbPlatformType("number", 3)); + dbTypeMap.put(DbType.DECIMAL, new DbPlatformType("number", 38)); - dbTypeMap.put(Types.VARCHAR, new DbType("varchar2", 255)); + dbTypeMap.put(DbType.VARCHAR, new DbPlatformType("varchar2", 255)); - dbTypeMap.put(Types.LONGVARBINARY, new DbType("blob")); - dbTypeMap.put(Types.LONGVARCHAR, new DbType("clob")); - dbTypeMap.put(Types.VARBINARY, new DbType("raw", 255)); - dbTypeMap.put(Types.BINARY, new DbType("raw", 255)); + dbTypeMap.put(DbType.LONGVARBINARY, new DbPlatformType("blob")); + dbTypeMap.put(DbType.LONGVARCHAR, new DbPlatformType("clob")); + dbTypeMap.put(DbType.VARBINARY, new DbPlatformType("raw", 255)); + dbTypeMap.put(DbType.BINARY, new DbPlatformType("raw", 255)); - dbTypeMap.put(Types.TIME, new DbType("timestamp")); + dbTypeMap.put(DbType.TIME, new DbPlatformType("timestamp")); } @Override diff --git a/src/main/java/com/avaje/ebean/config/dbplatform/PostgresPlatform.java b/src/main/java/com/avaje/ebean/config/dbplatform/PostgresPlatform.java index 70dbb8009..700b0499e 100644 --- a/src/main/java/com/avaje/ebean/config/dbplatform/PostgresPlatform.java +++ b/src/main/java/com/avaje/ebean/config/dbplatform/PostgresPlatform.java @@ -41,26 +41,26 @@ public class PostgresPlatform extends DatabasePlatform { this.openQuote = "\""; this.closeQuote = "\""; - DbType dbTypeText = new DbType("text"); - DbType dbBytea = new DbType("bytea", false); + DbPlatformType dbTypeText = new DbPlatformType("text"); + DbPlatformType dbBytea = new DbPlatformType("bytea", false); - dbTypeMap.put(DbType.HSTORE, new DbType("hstore", false)); - dbTypeMap.put(DbType.JSON, new DbType("json", false)); - dbTypeMap.put(DbType.JSONB, new DbType("jsonb", false)); + dbTypeMap.put(DbType.HSTORE, new DbPlatformType("hstore", false)); + dbTypeMap.put(DbType.JSON, new DbPlatformType("json", false)); + dbTypeMap.put(DbType.JSONB, new DbPlatformType("jsonb", false)); - dbTypeMap.put(Types.INTEGER, new DbType("integer", false)); - dbTypeMap.put(Types.DOUBLE, new DbType("float")); - dbTypeMap.put(Types.TINYINT, new DbType("smallint")); - dbTypeMap.put(Types.DECIMAL, new DbType("decimal", 38)); - dbTypeMap.put(Types.TIMESTAMP, new DbType("timestamptz")); + dbTypeMap.put(DbType.INTEGER, new DbPlatformType("integer", false)); + dbTypeMap.put(DbType.DOUBLE, new DbPlatformType("float")); + dbTypeMap.put(DbType.TINYINT, new DbPlatformType("smallint")); + dbTypeMap.put(DbType.DECIMAL, new DbPlatformType("decimal", 38)); + dbTypeMap.put(DbType.TIMESTAMP, new DbPlatformType("timestamptz")); - dbTypeMap.put(Types.BINARY, dbBytea); - dbTypeMap.put(Types.VARBINARY, dbBytea); + dbTypeMap.put(DbType.BINARY, dbBytea); + dbTypeMap.put(DbType.VARBINARY, dbBytea); - dbTypeMap.put(Types.BLOB, dbBytea); - dbTypeMap.put(Types.CLOB, dbTypeText); - dbTypeMap.put(Types.LONGVARBINARY, dbBytea); - dbTypeMap.put(Types.LONGVARCHAR, dbTypeText); + dbTypeMap.put(DbType.BLOB, dbBytea); + dbTypeMap.put(DbType.CLOB, dbTypeText); + dbTypeMap.put(DbType.LONGVARBINARY, dbBytea); + dbTypeMap.put(DbType.LONGVARCHAR, dbTypeText); } @Override @@ -71,7 +71,7 @@ public class PostgresPlatform extends DatabasePlatform { String tsType = properties.getProperty("ebean.postgres.timestamp"); if (tsType != null) { // set timestamp type to "timestamp" without time zone - dbTypeMap.put(Types.TIMESTAMP, new DbType(tsType)); + dbTypeMap.put(DbType.TIMESTAMP, new DbPlatformType(tsType)); } } } diff --git a/src/main/java/com/avaje/ebean/config/dbplatform/SQLitePlatform.java b/src/main/java/com/avaje/ebean/config/dbplatform/SQLitePlatform.java index f988e62e5..415d50109 100644 --- a/src/main/java/com/avaje/ebean/config/dbplatform/SQLitePlatform.java +++ b/src/main/java/com/avaje/ebean/config/dbplatform/SQLitePlatform.java @@ -18,10 +18,10 @@ public class SQLitePlatform extends DatabasePlatform { this.booleanDbType = Types.INTEGER; - dbTypeMap.put(Types.BIT, new DbType("int default 0")); - dbTypeMap.put(Types.BOOLEAN, new DbType("int default 0")); - dbTypeMap.put(Types.BIGINT, new DbType("integer")); - dbTypeMap.put(Types.SMALLINT, new DbType("integer")); + dbTypeMap.put(DbType.BIT, new DbPlatformType("int default 0")); + dbTypeMap.put(DbType.BOOLEAN, new DbPlatformType("int default 0")); + dbTypeMap.put(DbType.BIGINT, new DbPlatformType("integer")); + dbTypeMap.put(DbType.SMALLINT, new DbPlatformType("integer")); } diff --git a/src/main/java/com/avaje/ebean/config/dbplatform/SqlAnywherePlatform.java b/src/main/java/com/avaje/ebean/config/dbplatform/SqlAnywherePlatform.java index 86d02290a..8a89e3c49 100644 --- a/src/main/java/com/avaje/ebean/config/dbplatform/SqlAnywherePlatform.java +++ b/src/main/java/com/avaje/ebean/config/dbplatform/SqlAnywherePlatform.java @@ -1,7 +1,5 @@ package com.avaje.ebean.config.dbplatform; -import java.sql.Types; - /** * Sybase SQL Anywhere specific platform. *

@@ -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 { return BLOB; case Types.CLOB: return CLOB; - case DbType.JSONB: + case DbPlatformType.JSONB: return postgres ? JSONB : CLOB; - case DbType.JSON: + case DbPlatformType.JSON: return postgres ? JSON : CLOB; default: throw new IllegalStateException("Unknown dbType " + dbType); diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJsonMapPostgres.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJsonMapPostgres.java index cd51a3fff..c5e4405ba 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJsonMapPostgres.java +++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJsonMapPostgres.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 java.sql.SQLException; import java.util.Map; @@ -30,7 +30,7 @@ public abstract class ScalarTypeJsonMapPostgres extends ScalarTypeJsonMap { public static class JSON extends ScalarTypeJsonMapPostgres { public JSON() { - super(DbType.JSON, PostgresHelper.JSON_TYPE); + super(DbPlatformType.JSON, PostgresHelper.JSON_TYPE); } } @@ -40,7 +40,7 @@ public abstract class ScalarTypeJsonMapPostgres extends ScalarTypeJsonMap { public static class JSONB extends ScalarTypeJsonMapPostgres { public JSONB() { - super(DbType.JSONB, PostgresHelper.JSONB_TYPE); + super(DbPlatformType.JSONB, PostgresHelper.JSONB_TYPE); } } } diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJsonNodePostgres.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJsonNodePostgres.java index ae01ee6b8..90ae1c8f4 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJsonNodePostgres.java +++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJsonNodePostgres.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.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -33,7 +33,7 @@ public abstract class ScalarTypeJsonNodePostgres extends ScalarTypeJsonNode { public static class JSON extends ScalarTypeJsonNodePostgres { public JSON(ObjectMapper objectMapper) { - super(objectMapper, DbType.JSON, PostgresHelper.JSON_TYPE); + super(objectMapper, DbPlatformType.JSON, PostgresHelper.JSON_TYPE); } } @@ -43,7 +43,7 @@ public abstract class ScalarTypeJsonNodePostgres extends ScalarTypeJsonNode { public static class JSONB extends ScalarTypeJsonNodePostgres { public JSONB(ObjectMapper objectMapper) { - super(objectMapper, DbType.JSONB, PostgresHelper.JSONB_TYPE); + super(objectMapper, DbPlatformType.JSONB, PostgresHelper.JSONB_TYPE); } } } diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJsonObjectMapper.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJsonObjectMapper.java index ad9e512d3..f4d229dff 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJsonObjectMapper.java +++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJsonObjectMapper.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.ebeanservice.docstore.api.mapping.DocPropertyType; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; @@ -45,9 +45,9 @@ public class ScalarTypeJsonObjectMapper { private static String getPostgresType(boolean postgres, int dbType) { if (postgres) { switch (dbType) { - case DbType.JSON: + case DbPlatformType.JSON: return PostgresHelper.JSON_TYPE; - case DbType.JSONB: + case DbPlatformType.JSONB: return PostgresHelper.JSONB_TYPE; } } diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJsonSet.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJsonSet.java index 798acdac6..b6f11fac2 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJsonSet.java +++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJsonSet.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; @@ -25,9 +25,9 @@ public class ScalarTypeJsonSet { public static ScalarType typeFor(boolean postgres, int dbType, DocPropertyType docPropertyType) { if (postgres) { switch (dbType) { - case DbType.JSONB: + case DbPlatformType.JSONB: return new ScalarTypeJsonSet.JsonB(docPropertyType); - case DbType.JSON: + case DbPlatformType.JSON: return new ScalarTypeJsonSet.Json(docPropertyType); } } @@ -48,7 +48,7 @@ public class ScalarTypeJsonSet { */ private static class Json extends ScalarTypeJsonSet.PgBase { public Json(DocPropertyType docPropertyType) { - super(DbType.JSON, PostgresHelper.JSON_TYPE, docPropertyType); + super(DbPlatformType.JSON, PostgresHelper.JSON_TYPE, docPropertyType); } } @@ -57,7 +57,7 @@ public class ScalarTypeJsonSet { */ private static class JsonB extends ScalarTypeJsonSet.PgBase { public JsonB(DocPropertyType docPropertyType) { - super(DbType.JSONB, PostgresHelper.JSONB_TYPE, docPropertyType); + super(DbPlatformType.JSONB, PostgresHelper.JSONB_TYPE, docPropertyType); } } diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypePostgresHstore.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypePostgresHstore.java index a519579dd..bd5f37f09 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypePostgresHstore.java +++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypePostgresHstore.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.ebeanservice.docstore.api.mapping.DocPropertyType; @@ -20,7 +20,7 @@ import java.util.Map; public class ScalarTypePostgresHstore extends ScalarTypeBase { public ScalarTypePostgresHstore() { - super(Map.class, false, DbType.HSTORE); + super(Map.class, false, DbPlatformType.HSTORE); } @Override diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeUUIDBase.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeUUIDBase.java index 3fc5c6dbc..09722e001 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeUUIDBase.java +++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeUUIDBase.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.ebeaninternal.server.core.BasicTypeConverter; import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyType; import com.fasterxml.jackson.core.JsonGenerator; @@ -22,7 +22,7 @@ public abstract class ScalarTypeUUIDBase extends ScalarTypeBase implements @Override public int getLogicalType() { - return DbType.UUID; + return DbPlatformType.UUID; } @Override diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeUUIDNative.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeUUIDNative.java index c69ae0fa8..44fa8dd96 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeUUIDNative.java +++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeUUIDNative.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 java.sql.SQLException; import java.util.UUID; @@ -11,7 +11,7 @@ import java.util.UUID; public class ScalarTypeUUIDNative extends ScalarTypeUUIDBase { public ScalarTypeUUIDNative() { - super(false, DbType.UUID); + super(false, DbPlatformType.UUID); } @Override diff --git a/src/test/java/com/avaje/ebean/config/dbplatform/DbPlatformTypeLookupTest.java b/src/test/java/com/avaje/ebean/config/dbplatform/DbPlatformTypeLookupTest.java new file mode 100644 index 000000000..fd306c2be --- /dev/null +++ b/src/test/java/com/avaje/ebean/config/dbplatform/DbPlatformTypeLookupTest.java @@ -0,0 +1,53 @@ +package com.avaje.ebean.config.dbplatform; + +import org.junit.Test; + +import java.sql.Types; + +import static org.junit.Assert.*; + +public class DbPlatformTypeLookupTest { + + DbPlatformTypeLookup lookup = new DbPlatformTypeLookup(); + + @Test + public void byName() throws Exception { + + assertEquals(lookup.byName("DECIMAL"), DbType.DECIMAL); + assertEquals(lookup.byName("Decimal"), DbType.DECIMAL); + assertEquals(lookup.byName("decimal"), DbType.DECIMAL); + + assertEquals(lookup.byName("varchar"), DbType.VARCHAR); + assertEquals(lookup.byName("varchar2"), DbType.VARCHAR); + + assertEquals(lookup.byName("float"), DbType.REAL); + assertEquals(lookup.byName("real"), DbType.REAL); + + assertEquals(lookup.byName("uuid"), DbType.UUID); + assertEquals(lookup.byName("hstore"), DbType.HSTORE); + + assertEquals(lookup.byName("json"), DbType.JSON); + assertEquals(lookup.byName("jsonb"), DbType.JSONB); + assertEquals(lookup.byName("jsonclob"), DbType.JSONCLOB); + assertEquals(lookup.byName("jsonblob"), DbType.JSONBLOB); + assertEquals(lookup.byName("jsonVarchar"), DbType.JSONVARCHAR); + + } + + @Test + public void byId() throws Exception { + + assertEquals(lookup.byId(Types.ARRAY), DbType.ARRAY); + assertEquals(lookup.byId(Types.BIGINT), DbType.BIGINT); + + assertEquals(lookup.byId(ExtraDbTypes.UUID), DbType.UUID); + assertEquals(lookup.byId(ExtraDbTypes.HSTORE), DbType.HSTORE); + + assertEquals(lookup.byId(ExtraDbTypes.JSON), DbType.JSON); + assertEquals(lookup.byId(ExtraDbTypes.JSONB), DbType.JSONB); + assertEquals(lookup.byId(ExtraDbTypes.JSONClob), DbType.JSONCLOB); + assertEquals(lookup.byId(ExtraDbTypes.JSONBlob), DbType.JSONBLOB); + assertEquals(lookup.byId(ExtraDbTypes.JSONVarchar), DbType.JSONVARCHAR); + } + +} \ No newline at end of file diff --git a/src/test/java/com/avaje/ebean/config/dbplatform/DbTypeMapTest.java b/src/test/java/com/avaje/ebean/config/dbplatform/DbTypeMapTest.java index abf0d6d6e..cb5e6598f 100644 --- a/src/test/java/com/avaje/ebean/config/dbplatform/DbTypeMapTest.java +++ b/src/test/java/com/avaje/ebean/config/dbplatform/DbTypeMapTest.java @@ -11,7 +11,7 @@ public class DbTypeMapTest { public void testLookupRender_given_postgresPlatformType() throws Exception { PostgresPlatform pg = new PostgresPlatform(); - DbTypeMap dbTypeMap = pg.getDbTypeMap(); + DbPlatformTypeMapping dbTypeMap = pg.getDbTypeMap(); assertThat(dbTypeMap.lookup("clob", false).renderType(0,0)).isEqualTo("text"); assertThat(dbTypeMap.lookup("CLOB", false).renderType(0, 0)).isEqualTo("text"); @@ -29,9 +29,9 @@ public class DbTypeMapTest { @Test public void testPlatformTypes() { - DbTypeMap dbTypeMap = DbTypeMap.logicalTypes(); - DbType dbType = dbTypeMap.get(DbType.JSON); - DbType json = dbTypeMap.lookup("json", false); + DbPlatformTypeMapping dbTypeMap = DbPlatformTypeMapping.logicalTypes(); + DbPlatformType dbType = dbTypeMap.get(DbPlatformType.JSON); + DbPlatformType json = dbTypeMap.lookup("json", false); assertThat(dbType).isSameAs(json); } diff --git a/src/test/java/com/avaje/ebean/config/dbplatform/MySqlPlatformTest.java b/src/test/java/com/avaje/ebean/config/dbplatform/MySqlPlatformTest.java index 2aaa510bd..bbf77fa0c 100644 --- a/src/test/java/com/avaje/ebean/config/dbplatform/MySqlPlatformTest.java +++ b/src/test/java/com/avaje/ebean/config/dbplatform/MySqlPlatformTest.java @@ -27,7 +27,7 @@ public class MySqlPlatformTest { MySqlPlatform platform = new MySqlPlatform(); platform.configure(new ServerConfig()); - DbType dbType = platform.getDbTypeMap().get(DbType.UUID); + DbPlatformType dbType = platform.getDbTypeMap().get(DbPlatformType.UUID); assertThat(dbType.renderType(0, 0)).isEqualTo("varchar(40)"); } @@ -40,7 +40,7 @@ public class MySqlPlatformTest { serverConfig.setDbUuid(ServerConfig.DbUuid.AUTO_BINARY); platform.configure(serverConfig); - DbType dbType = platform.getDbTypeMap().get(DbType.UUID); + DbPlatformType dbType = platform.getDbTypeMap().get(DbPlatformType.UUID); assertThat(dbType.renderType(0, 0)).isEqualTo("binary(16)"); } diff --git a/src/test/java/com/avaje/ebean/config/dbplatform/OraclePlatformTest.java b/src/test/java/com/avaje/ebean/config/dbplatform/OraclePlatformTest.java index f9dd28422..5fd5c9fe7 100644 --- a/src/test/java/com/avaje/ebean/config/dbplatform/OraclePlatformTest.java +++ b/src/test/java/com/avaje/ebean/config/dbplatform/OraclePlatformTest.java @@ -35,7 +35,7 @@ public class OraclePlatformTest { OraclePlatform platform = new OraclePlatform(); platform.configure(new ServerConfig()); - DbType dbType = platform.getDbTypeMap().get(DbType.UUID); + DbPlatformType dbType = platform.getDbTypeMap().get(DbPlatformType.UUID); assertThat(dbType.renderType(0, 0)).isEqualTo("varchar2(40)"); } @@ -50,7 +50,7 @@ public class OraclePlatformTest { platform.configure(serverConfig); - DbType dbType = platform.getDbTypeMap().get(DbType.UUID); + DbPlatformType dbType = platform.getDbTypeMap().get(DbPlatformType.UUID); assertThat(dbType.renderType(0, 0)).isEqualTo("raw(16)"); } } \ No newline at end of file diff --git a/src/test/java/com/avaje/ebean/config/dbplatform/PostgresPlatformTest.java b/src/test/java/com/avaje/ebean/config/dbplatform/PostgresPlatformTest.java index 1f5516199..41577423f 100644 --- a/src/test/java/com/avaje/ebean/config/dbplatform/PostgresPlatformTest.java +++ b/src/test/java/com/avaje/ebean/config/dbplatform/PostgresPlatformTest.java @@ -38,7 +38,7 @@ public class PostgresPlatformTest { PostgresPlatform platform = new PostgresPlatform(); platform.configure(new ServerConfig()); - DbType dbType = platform.getDbTypeMap().get(DbType.UUID); + DbPlatformType dbType = platform.getDbTypeMap().get(DbPlatformType.UUID); String columnDefn = dbType.renderType(0, 0); assertThat(columnDefn).isEqualTo("uuid"); diff --git a/src/test/java/com/avaje/ebean/dbmigration/ddlgeneration/platform/PlatformTypeConverterTest.java b/src/test/java/com/avaje/ebean/dbmigration/ddlgeneration/platform/PlatformTypeConverterTest.java index 423a281b7..bdf7cb6cd 100644 --- a/src/test/java/com/avaje/ebean/dbmigration/ddlgeneration/platform/PlatformTypeConverterTest.java +++ b/src/test/java/com/avaje/ebean/dbmigration/ddlgeneration/platform/PlatformTypeConverterTest.java @@ -1,6 +1,6 @@ package com.avaje.ebean.dbmigration.ddlgeneration.platform; -import com.avaje.ebean.config.dbplatform.DbTypeMap; +import com.avaje.ebean.config.dbplatform.DbPlatformTypeMapping; import com.avaje.ebean.config.dbplatform.H2Platform; import com.avaje.ebean.config.dbplatform.PostgresPlatform; import com.avaje.ebean.dbmigration.ddlgeneration.platform.util.PlatformTypeConverter; @@ -14,7 +14,7 @@ public class PlatformTypeConverterTest { public void convert_withSuffix_expect_suffix() { PostgresPlatform pg = new PostgresPlatform(); - DbTypeMap dbTypeMap = pg.getDbTypeMap(); + DbPlatformTypeMapping dbTypeMap = pg.getDbTypeMap(); PlatformTypeConverter converter = new PlatformTypeConverter(dbTypeMap); @@ -30,7 +30,7 @@ public class PlatformTypeConverterTest { public void testConvert_given_postgres() throws Exception { PostgresPlatform pg = new PostgresPlatform(); - DbTypeMap dbTypeMap = pg.getDbTypeMap(); + DbPlatformTypeMapping dbTypeMap = pg.getDbTypeMap(); PlatformTypeConverter converter = new PlatformTypeConverter(dbTypeMap); @@ -52,7 +52,7 @@ public class PlatformTypeConverterTest { H2Platform platform = new H2Platform(); - DbTypeMap dbTypeMap = platform.getDbTypeMap(); + DbPlatformTypeMapping dbTypeMap = platform.getDbTypeMap(); PlatformTypeConverter converter = new PlatformTypeConverter(dbTypeMap); @@ -69,7 +69,7 @@ public class PlatformTypeConverterTest { public void testConvertJsonTypes_given_postgres() { PostgresPlatform platform = new PostgresPlatform(); - DbTypeMap dbTypeMap = platform.getDbTypeMap(); + DbPlatformTypeMapping dbTypeMap = platform.getDbTypeMap(); PlatformTypeConverter converter = new PlatformTypeConverter(dbTypeMap); @@ -84,7 +84,7 @@ public class PlatformTypeConverterTest { public void testConvertJsonTypes_given_h2() { H2Platform platform = new H2Platform(); - DbTypeMap dbTypeMap = platform.getDbTypeMap(); + DbPlatformTypeMapping dbTypeMap = platform.getDbTypeMap(); PlatformTypeConverter converter = new PlatformTypeConverter(dbTypeMap);