diff --git a/src/main/java/com/avaje/ebean/config/ServerConfig.java b/src/main/java/com/avaje/ebean/config/ServerConfig.java index 3c1ce319c..217f70034 100644 --- a/src/main/java/com/avaje/ebean/config/ServerConfig.java +++ b/src/main/java/com/avaje/ebean/config/ServerConfig.java @@ -320,7 +320,7 @@ public class ServerConfig { /** * Setting to indicate if UUID should be stored as binary(16) or varchar(40) or native DB type (for H2 and Postgres). */ - private DbUuid dbUuid = DbUuid.AUTO; + private DbUuid dbUuid = DbUuid.AUTO_VARCHAR; private List idGenerators = new ArrayList(); @@ -2615,18 +2615,45 @@ public class ServerConfig { public enum DbUuid { /** - * Store using native UUID in H2 and Postgres. + * Store using native UUID in H2 and Postgres and otherwise fallback to VARCHAR(40). */ - AUTO, + AUTO_VARCHAR(true, false), /** - * Store using DB VARCHAR. + * Store using native UUID in H2 and Postgres and otherwise fallback to BINARY(16). */ - VARCHAR, + AUTO_BINARY(true, true), /** - * Store using DB BINARY. + * Store using DB VARCHAR(40). */ - BINARY + VARCHAR(false, false), + + /** + * Store using DB BINARY(16). + */ + BINARY(false, true); + + boolean nativeType; + boolean binary; + + DbUuid(boolean nativeType, boolean binary) { + this.nativeType = nativeType; + this.binary = binary; + } + + /** + * Return true if native UUID type is preferred. + */ + public boolean useNativeType() { + return nativeType; + } + + /** + * Return true if BINARY(16) storage is preferred over VARCHAR(40). + */ + public boolean useBinary() { + return binary; + } } } 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 16aac20d5..edf934518 100644 --- a/src/main/java/com/avaje/ebean/config/dbplatform/DatabasePlatform.java +++ b/src/main/java/com/avaje/ebean/config/dbplatform/DatabasePlatform.java @@ -182,8 +182,11 @@ public class DatabasePlatform { public DatabasePlatform() { } - public void configure(Properties properties) { - // by default do nothing + /** + * Configure UUID Storage etc based on ServerConfig settings. + */ + public void configure(ServerConfig serverConfig) { + dbTypeMap.config(nativeUuidType, serverConfig.getDbUuid()); } /** 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 4c51be3de..1242cfa5d 100644 --- a/src/main/java/com/avaje/ebean/config/dbplatform/DbType.java +++ b/src/main/java/com/avaje/ebean/config/dbplatform/DbType.java @@ -152,4 +152,10 @@ public class DbType { return sb.toString(); } + /** + * Create a copy of the type with a new default length. + */ + public DbType withLength(int defaultLength) { + return new DbType(name, defaultLength); + } } diff --git a/src/main/java/com/avaje/ebean/config/dbplatform/DbTypeMap.java b/src/main/java/com/avaje/ebean/config/dbplatform/DbTypeMap.java index bbf138bdf..56ec250f6 100644 --- a/src/main/java/com/avaje/ebean/config/dbplatform/DbTypeMap.java +++ b/src/main/java/com/avaje/ebean/config/dbplatform/DbTypeMap.java @@ -1,5 +1,7 @@ package com.avaje.ebean.config.dbplatform; +import com.avaje.ebean.config.ServerConfig; + import java.sql.Types; import java.util.HashMap; import java.util.Map; @@ -9,6 +11,8 @@ import java.util.Map; */ 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"); @@ -66,7 +70,7 @@ public class DbTypeMap { /** * 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. */ @@ -104,8 +108,6 @@ public class DbTypeMap { put(Types.BLOB, new DbType("blob")); put(Types.CLOB, new DbType("clob")); - // DB native UUID support (H2 and Postgres) - put(DbType.UUID, new DbType("uuid")); put(Types.ARRAY, new DbType("array")); if (logicalTypes) { @@ -116,6 +118,7 @@ public class DbTypeMap { 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 @@ -123,6 +126,7 @@ public class DbTypeMap { 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")); @@ -133,7 +137,6 @@ public class DbTypeMap { put(Types.DATE, new DbType("date")); put(Types.TIME, new DbType("time")); put(Types.TIMESTAMP, new DbType("timestamp")); - } /** @@ -191,4 +194,17 @@ public class DbTypeMap { 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/H2Platform.java b/src/main/java/com/avaje/ebean/config/dbplatform/H2Platform.java index ae44bd34f..25ba2073d 100644 --- a/src/main/java/com/avaje/ebean/config/dbplatform/H2Platform.java +++ b/src/main/java/com/avaje/ebean/config/dbplatform/H2Platform.java @@ -1,6 +1,7 @@ package com.avaje.ebean.config.dbplatform; import com.avaje.ebean.BackgroundExecutor; +import com.avaje.ebean.config.ServerConfig; import com.avaje.ebean.dbmigration.ddlgeneration.platform.H2Ddl; import javax.sql.DataSource; @@ -34,11 +35,14 @@ public class H2Platform extends DatabasePlatform { } @Override - public void configure(Properties properties) { - super.configure(properties); - String idType = properties.getProperty("ebean.h2.idtype"); - if (idType != null) { - this.dbIdentity.setIdType(IdType.valueOf(idType)); + public void configure(ServerConfig serverConfig) { + super.configure(serverConfig); + Properties properties = serverConfig.getProperties(); + if (properties != null) { + String idType = properties.getProperty("ebean.h2.idtype"); + if (idType != null) { + this.dbIdentity.setIdType(IdType.valueOf(idType)); + } } } 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 da1b842c9..70dbb8009 100644 --- a/src/main/java/com/avaje/ebean/config/dbplatform/PostgresPlatform.java +++ b/src/main/java/com/avaje/ebean/config/dbplatform/PostgresPlatform.java @@ -64,12 +64,15 @@ public class PostgresPlatform extends DatabasePlatform { } @Override - public void configure(Properties properties) { - super.configure(properties); - 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)); + public void configure(ServerConfig serverConfig) { + super.configure(serverConfig); + Properties properties = serverConfig.getProperties(); + if (properties != null) { + 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)); + } } } diff --git a/src/main/java/com/avaje/ebean/dbmigration/DbMigration.java b/src/main/java/com/avaje/ebean/dbmigration/DbMigration.java index af24792c2..c27787114 100644 --- a/src/main/java/com/avaje/ebean/dbmigration/DbMigration.java +++ b/src/main/java/com/avaje/ebean/dbmigration/DbMigration.java @@ -204,7 +204,7 @@ public class DbMigration { // use this flag to stop other plugins like full DDL generation if (!online) { - DbOffline.setRunningMigration(); + DbOffline.setGenerateMigration(); } setDefaults(); try { diff --git a/src/main/java/com/avaje/ebean/dbmigration/DbOffline.java b/src/main/java/com/avaje/ebean/dbmigration/DbOffline.java index bd0eef45f..f0f8c3783 100644 --- a/src/main/java/com/avaje/ebean/dbmigration/DbOffline.java +++ b/src/main/java/com/avaje/ebean/dbmigration/DbOffline.java @@ -14,7 +14,7 @@ public class DbOffline { private static final String KEY = "ebean.dboffline"; - private static boolean runningMigration; + private static boolean generateMigration; /** * Set the platform to use when creating the next EbeanServer instance. @@ -55,23 +55,23 @@ public class DbOffline { * Return true if the migration is running. This typically means don't run the * plugins like full DDL generation. */ - public static boolean isRunningMigration() { - return runningMigration; + public static boolean isGenerateMigration() { + return generateMigration; } /** * Called when the migration is running is order to stop other plugins * like the full DDL generation from executing. */ - public static void setRunningMigration() { - runningMigration = true; + public static void setGenerateMigration() { + generateMigration = true; } /** * Reset the offline platform and runningMigration flag. */ public static void reset() { - runningMigration = false; + generateMigration = false; System.clearProperty(KEY); logger.debug("reset"); } diff --git a/src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/platform/PlatformDdl.java b/src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/platform/PlatformDdl.java index 38470fed5..e0e8b025c 100644 --- a/src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/platform/PlatformDdl.java +++ b/src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/platform/PlatformDdl.java @@ -26,6 +26,8 @@ import java.util.List; */ public class PlatformDdl { + protected final DatabasePlatform platform; + protected PlatformHistoryDdl historyDdl = new NoHistorySupportDdl(); /** @@ -98,6 +100,7 @@ public class PlatformDdl { protected final DbDefaultValue dbDefaultValue; public PlatformDdl(DatabasePlatform platform) { + this.platform = platform; this.dbIdentity = platform.getDbIdentity(); this.dbDefaultValue = platform.getDbDefaultValue(); this.typeConverter = new PlatformTypeConverter(platform.getDbTypeMap()); @@ -107,6 +110,7 @@ public class PlatformDdl { * Set configuration options. */ public void configure(ServerConfig serverConfig) { + platform.configure(serverConfig); historyDdl.configure(serverConfig, this); naming = serverConfig.getConstraintNaming(); } diff --git a/src/main/java/com/avaje/ebean/dbmigration/model/CurrentModel.java b/src/main/java/com/avaje/ebean/dbmigration/model/CurrentModel.java index b7e06e98a..99dd89acf 100644 --- a/src/main/java/com/avaje/ebean/dbmigration/model/CurrentModel.java +++ b/src/main/java/com/avaje/ebean/dbmigration/model/CurrentModel.java @@ -11,7 +11,6 @@ import com.avaje.ebean.dbmigration.model.visitor.VisitAllUsing; import com.avaje.ebeaninternal.api.SpiEbeanServer; import java.io.IOException; -import java.util.List; /** * Reads EbeanServer bean descriptors to build the current model. @@ -24,6 +23,8 @@ public class CurrentModel { private final DbConstraintNaming.MaxLength maxLength; + private final boolean platformTypes; + private ModelContainer model; private ChangeSet changeSet; @@ -31,32 +32,31 @@ public class CurrentModel { private DdlWrite write; /** - * Construct with a given EbeanServer instance. + * Construct with a given EbeanServer instance for DDL create all generation, not migration. */ public CurrentModel(SpiEbeanServer server) { - this(server, server.getServerConfig().getConstraintNaming()); + this(server, server.getServerConfig().getConstraintNaming(), true); } /** * Construct with a given EbeanServer, platformDdl and constraintNaming convention. *

- * Note the EbeanServer is just used to read the BeanDescriptors and platformDdl supplies - * the platform specific handling on + * Note the EbeanServer is just used to read the BeanDescriptors and platformDdl supplies + * the platform specific handling on *

*/ public CurrentModel(SpiEbeanServer server, DbConstraintNaming constraintNaming) { + this(server, constraintNaming, false); + } + + private CurrentModel(SpiEbeanServer server, DbConstraintNaming constraintNaming, boolean platformTypes) { this.server = server; this.constraintNaming = constraintNaming; this.maxLength = maxLength(server, constraintNaming); + this.platformTypes = platformTypes; } - public CurrentModel(SpiEbeanServer server, DbConstraintNaming constraintNaming, int maxConstraintLength) { - this.server = server; - this.constraintNaming = constraintNaming; - this.maxLength = new DefaultConstraintMaxLength(maxConstraintLength); - } - - private DbConstraintNaming.MaxLength maxLength(SpiEbeanServer server, DbConstraintNaming naming) { + private static DbConstraintNaming.MaxLength maxLength(SpiEbeanServer server, DbConstraintNaming naming) { if (naming.getMaxLength() != null) { return naming.getMaxLength(); @@ -73,7 +73,7 @@ public class CurrentModel { if (model == null) { model = new ModelContainer(); - ModelBuildContext context = new ModelBuildContext(model, constraintNaming, maxLength); + ModelBuildContext context = new ModelBuildContext(model, constraintNaming, maxLength, platformTypes); ModelBuildBeanVisitor visitor = new ModelBuildBeanVisitor(context); VisitAllUsing visit = new VisitAllUsing(visitor, server); visit.visitAllBeans(); 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 dc1c3cf49..949e6b154 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 @@ -29,10 +29,13 @@ public class ModelBuildContext { private final DbConstraintNaming.MaxLength maxLength; - public ModelBuildContext(ModelContainer model, DbConstraintNaming naming, DbConstraintNaming.MaxLength maxLength) { + private final boolean platformTypes; + + public ModelBuildContext(ModelContainer model, DbConstraintNaming naming, DbConstraintNaming.MaxLength maxLength, boolean platformTypes) { this.model = model; this.constraintNaming = naming; this.maxLength = maxLength; + this.platformTypes = platformTypes; } /** @@ -132,7 +135,7 @@ public class ModelBuildContext { } // can be the logical JSON types (JSON, JSONB, JSONClob, JSONBlob, JSONVarchar) - int dbType = p.getDbType(); + int dbType = p.getDbType(platformTypes); if (dbType == 0) { throw new RuntimeException("No scalarType defined for " + p.getFullBeanName()); } diff --git a/src/main/java/com/avaje/ebeaninternal/server/core/DefaultContainer.java b/src/main/java/com/avaje/ebeaninternal/server/core/DefaultContainer.java index b1caba532..8ff82fcd9 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/core/DefaultContainer.java +++ b/src/main/java/com/avaje/ebeaninternal/server/core/DefaultContainer.java @@ -122,22 +122,20 @@ public class DefaultContainer implements SpiContainer { // generate and run DDL if required // if there are any other tasks requiring action in their plugins, do them as well - if (!DbOffline.isRunningMigration()) { + if (!DbOffline.isGenerateMigration()) { server.executePlugins(online); - } - // initialise prior to registering with clusterManager - server.initialise(); - - if (online) { - if (clusterManager.isClustering()) { - // register the server once it has been created - clusterManager.registerServer(server); + // initialise prior to registering with clusterManager + server.initialise(); + if (online) { + if (clusterManager.isClustering()) { + // register the server once it has been created + clusterManager.registerServer(server); + } } + // start any services after registering with clusterManager + server.start(); } - - // start any services after registering with clusterManager - server.start(); DbOffline.reset(); return server; } @@ -244,7 +242,7 @@ public class DefaultContainer implements SpiContainer { if (dbPlatform == null) { DatabasePlatformFactory factory = new DatabasePlatformFactory(); DatabasePlatform db = factory.create(config); - db.configure(config.getProperties()); + db.configure(config); config.setDatabasePlatform(db); logger.info("DatabasePlatform name:" + config.getName() + " platform:" + db.getName()); } 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 7138ebf1b..fb888d34b 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanProperty.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanProperty.java @@ -27,6 +27,7 @@ import com.avaje.ebeaninternal.server.type.DataBind; import com.avaje.ebeaninternal.server.type.ScalarType; import com.avaje.ebeaninternal.server.type.ScalarTypeBoolean; import com.avaje.ebeaninternal.server.type.ScalarTypeEnum; +import com.avaje.ebeaninternal.server.type.ScalarTypeLogicalType; import com.avaje.ebeaninternal.util.ValueUtil; import com.avaje.ebeanservice.docstore.api.mapping.DocMappingBuilder; import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyMapping; @@ -413,7 +414,7 @@ public class BeanProperty implements ElPropertyValue, Property { this.generatedProperty = source.getGeneratedProperty(); this.getter = source.getter; this.setter = source.setter; - this.dbType = source.getDbType(); + this.dbType = source.getDbType(true); this.scalarType = source.scalarType; this.lob = isLobType(dbType); this.propertyType = source.getPropertyType(); @@ -1087,9 +1088,14 @@ public class BeanProperty implements ElPropertyValue, Property { /** * Return the database jdbc data type this is mapped to. + * + * @param platformTypes Set as false when we want logical platform agnostic types. */ - public int getDbType() { - return dbType; + public int getDbType(boolean platformTypes) { + if (platformTypes || !(scalarType instanceof ScalarTypeLogicalType)) { + return dbType; + } + return ((ScalarTypeLogicalType)scalarType).getLogicalType(); } /** 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 b9ecf719b..9ced06aaf 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/type/DefaultTypeManager.java +++ b/src/main/java/com/avaje/ebeaninternal/server/type/DefaultTypeManager.java @@ -11,6 +11,7 @@ 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.dbmigration.DbOffline; import com.avaje.ebeaninternal.server.core.bootup.BootupClasses; import com.avaje.ebeaninternal.server.type.reflect.CheckImmutable; import com.avaje.ebeaninternal.server.type.reflect.CheckImmutableResponse; @@ -156,6 +157,8 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable { private final boolean postgres; + private final boolean offlineMigrationGeneration; + // OPTIONAL ScalarTypes registered if Jackson/JsonNode is in the classpath /** @@ -198,6 +201,7 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable { this.extraTypeFactory = new DefaultTypeFactory(config); this.postgres = isPostgres(config.getDatabasePlatform()); + this.offlineMigrationGeneration = DbOffline.isGenerateMigration(); initialiseStandard(jsonDateTime, config); initialiseJavaTimeTypes(jsonDateTime, config); @@ -961,15 +965,13 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable { nativeMap.put(Types.BIT, booleanType); } - boolean nativeUuidType = databasePlatform.isNativeUuidType(); ServerConfig.DbUuid dbUuid = config.getDbUuid(); - if (nativeUuidType && dbUuid == ServerConfig.DbUuid.AUTO) { - // DB has native support for UUID + if (offlineMigrationGeneration || (databasePlatform.isNativeUuidType() && dbUuid.useNativeType())) { typeMap.put(UUID.class, new ScalarTypeUUIDNative()); } else { // Store UUID as binary(16) or varchar(40) - ScalarType uuidType = (ServerConfig.DbUuid.BINARY == dbUuid) ? new ScalarTypeUUIDBinary() : new ScalarTypeUUIDVarchar(); + ScalarType uuidType = dbUuid.useBinary() ? new ScalarTypeUUIDBinary() : new ScalarTypeUUIDVarchar(); typeMap.put(UUID.class, uuidType); } diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLogicalType.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLogicalType.java new file mode 100644 index 000000000..328ae72a0 --- /dev/null +++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLogicalType.java @@ -0,0 +1,12 @@ +package com.avaje.ebeaninternal.server.type; + +/** + * Marks types that can be mapped differently to different DB platforms. + */ +public interface ScalarTypeLogicalType { + + /** + * Return the DB agnostic logical type. + */ + int getLogicalType(); +} 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 9c9a18bae..3fc5c6dbc 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeUUIDBase.java +++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeUUIDBase.java @@ -1,5 +1,6 @@ package com.avaje.ebeaninternal.server.type; +import com.avaje.ebean.config.dbplatform.DbType; import com.avaje.ebeaninternal.server.core.BasicTypeConverter; import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyType; import com.fasterxml.jackson.core.JsonGenerator; @@ -13,12 +14,17 @@ import java.util.UUID; /** * Base UUID type for string formatting, json handling etc. */ -public abstract class ScalarTypeUUIDBase extends ScalarTypeBase { +public abstract class ScalarTypeUUIDBase extends ScalarTypeBase implements ScalarTypeLogicalType { public ScalarTypeUUIDBase(boolean jdbcNative, int jdbcType) { super(UUID.class, jdbcNative, jdbcType); } + @Override + public int getLogicalType() { + return DbType.UUID; + } + @Override public boolean isMutable() { return false; 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 3b59a14ff..2aaa510bd 100644 --- a/src/test/java/com/avaje/ebean/config/dbplatform/MySqlPlatformTest.java +++ b/src/test/java/com/avaje/ebean/config/dbplatform/MySqlPlatformTest.java @@ -1,5 +1,6 @@ package com.avaje.ebean.config.dbplatform; +import com.avaje.ebean.config.ServerConfig; import com.avaje.ebean.dbmigration.ddlgeneration.platform.PlatformDdl; import org.junit.Test; @@ -20,4 +21,27 @@ public class MySqlPlatformTest { assertThat(ddl.convert("bit", false)).isEqualTo("tinyint(1) default 0"); } + @Test + public void uuid_default() { + + MySqlPlatform platform = new MySqlPlatform(); + platform.configure(new ServerConfig()); + + DbType dbType = platform.getDbTypeMap().get(DbType.UUID); + assertThat(dbType.renderType(0, 0)).isEqualTo("varchar(40)"); + } + + + @Test + public void uuid_as_binary() { + + MySqlPlatform platform = new MySqlPlatform(); + ServerConfig serverConfig = new ServerConfig(); + serverConfig.setDbUuid(ServerConfig.DbUuid.AUTO_BINARY); + platform.configure(serverConfig); + + DbType dbType = platform.getDbTypeMap().get(DbType.UUID); + assertThat(dbType.renderType(0, 0)).isEqualTo("binary(16)"); + } + } \ No newline at end of file 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 cc7a4d2b3..bde690e40 100644 --- a/src/test/java/com/avaje/ebean/config/dbplatform/OraclePlatformTest.java +++ b/src/test/java/com/avaje/ebean/config/dbplatform/OraclePlatformTest.java @@ -1,5 +1,6 @@ package com.avaje.ebean.config.dbplatform; +import com.avaje.ebean.config.ServerConfig; import com.avaje.ebean.dbmigration.ddlgeneration.platform.PlatformDdl; import org.junit.Test; @@ -29,4 +30,27 @@ public class OraclePlatformTest { } + @Test + public void uuid_default() { + + OraclePlatform platform = new OraclePlatform(); + platform.configure(new ServerConfig()); + DbType dbType = platform.getDbTypeMap().get(DbType.UUID); + + assertThat(dbType.renderType(0, 0)).isEqualTo("varchar2(40)"); + } + + + @Test + public void uuid_as_binary() { + + OraclePlatform platform = new OraclePlatform(); + ServerConfig serverConfig = new ServerConfig(); + serverConfig.setDbUuid(ServerConfig.DbUuid.AUTO_BINARY); + + platform.configure(serverConfig); + + DbType dbType = platform.getDbTypeMap().get(DbType.UUID); + assertThat(dbType.renderType(0, 0)).isEqualTo("binary(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 68a534e93..1f5516199 100644 --- a/src/test/java/com/avaje/ebean/config/dbplatform/PostgresPlatformTest.java +++ b/src/test/java/com/avaje/ebean/config/dbplatform/PostgresPlatformTest.java @@ -1,5 +1,6 @@ package com.avaje.ebean.config.dbplatform; +import com.avaje.ebean.config.ServerConfig; import com.avaje.ebean.dbmigration.ddlgeneration.platform.PlatformDdl; import org.junit.Test; @@ -7,11 +8,12 @@ import static org.assertj.core.api.Assertions.assertThat; public class PostgresPlatformTest { - PostgresPlatform platform = new PostgresPlatform(); + @Test public void testTypeConversion() { + PostgresPlatform platform = new PostgresPlatform(); PlatformDdl ddl = platform.getPlatformDdl(); assertThat(ddl.convert("clob", false)).isEqualTo("text"); @@ -30,4 +32,16 @@ public class PostgresPlatformTest { } + @Test + public void testUuidType() { + + PostgresPlatform platform = new PostgresPlatform(); + platform.configure(new ServerConfig()); + + DbType dbType = platform.getDbTypeMap().get(DbType.UUID); + String columnDefn = dbType.renderType(0, 0); + + assertThat(columnDefn).isEqualTo("uuid"); + } + } \ No newline at end of file diff --git a/src/test/java/com/avaje/ebean/dbmigration/model/build/ModelBuildBeanVisitorTest.java b/src/test/java/com/avaje/ebean/dbmigration/model/build/ModelBuildBeanVisitorTest.java index aee252ffc..6dcdbc8a8 100644 --- a/src/test/java/com/avaje/ebean/dbmigration/model/build/ModelBuildBeanVisitorTest.java +++ b/src/test/java/com/avaje/ebean/dbmigration/model/build/ModelBuildBeanVisitorTest.java @@ -25,7 +25,7 @@ public class ModelBuildBeanVisitorTest extends BaseTestCase { DbConstraintNaming constraintNaming = defaultServer.getServerConfig().getConstraintNaming(); DefaultConstraintMaxLength maxLength = new DefaultConstraintMaxLength(60); - ModelBuildContext ctx = new ModelBuildContext(model, constraintNaming, maxLength); + ModelBuildContext ctx = new ModelBuildContext(model, constraintNaming, maxLength, true); ModelBuildBeanVisitor addTable = new ModelBuildBeanVisitor(ctx);