#1147 - Refactor move DbMigration internals into io.ebeaninternal - change to use DbMigration.create() - move IdentityType handling into internal from DbIdentity

This commit is contained in:
rob bygrave
2017-10-04 20:49:04 +13:00
parent 62707caf64
commit 9f9ec8ef9f
4 changed files with 78 additions and 33 deletions
@@ -1,6 +1,5 @@
package io.ebean.config.dbplatform;
import io.ebeaninternal.dbmigration.migration.IdentityType;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -121,28 +120,4 @@ public class DbIdentity {
this.idType = idType;
}
/**
* Determine the id type to use based on requested identityType and
* the support for that in the database platform.
*/
public IdType useIdentityType(IdentityType identityType) {
if (identityType == null) {
// use the default
return idType;
}
switch (identityType) {
case GENERATOR:
return IdType.GENERATOR;
case EXTERNAL:
return IdType.EXTERNAL;
case SEQUENCE:
return supportsSequence ? IdType.SEQUENCE : idType;
case IDENTITY:
return supportsIdentity ? IdType.IDENTITY : idType;
default:
return idType;
}
}
}
@@ -136,9 +136,33 @@ public class PlatformDdl {
* Return the identity type to use given the support in the underlying database
* platform for sequences and identity/autoincrement.
*/
public IdType useIdentityType(IdentityType modelIdentityType) {
public IdType useIdentityType(IdentityType modelIdentity) {
return dbIdentity.useIdentityType(modelIdentityType);
if (modelIdentity == null) {
// use the default
return dbIdentity.getIdType();
}
return identityType(modelIdentity, dbIdentity.getIdType(), dbIdentity.isSupportsSequence(), dbIdentity.isSupportsIdentity());
}
/**
* Determine the id type to use based on requested identityType and
* the support for that in the database platform.
*/
private IdType identityType(IdentityType modelIdentity, IdType platformIdType, boolean supportsSequence, boolean supportsIdentity) {
switch (modelIdentity) {
case GENERATOR:
return IdType.GENERATOR;
case EXTERNAL:
return IdType.EXTERNAL;
case SEQUENCE:
return supportsSequence ? IdType.SEQUENCE : platformIdType;
case IDENTITY:
return supportsIdentity ? IdType.IDENTITY : platformIdType;
default:
return platformIdType;
}
}
/**
@@ -11,9 +11,14 @@ import io.ebeaninternal.dbmigration.ddlgeneration.platform.PostgresDdl;
import io.ebeaninternal.dbmigration.ddlgeneration.platform.SQLiteDdl;
import io.ebeaninternal.dbmigration.ddlgeneration.platform.SqlServerDdl;
/**
* Builds platform specific DDL handler.
*/
public class PlatformDdlBuilder {
/**
* Return platform specific DDL handler.
*/
public static PlatformDdl create(DatabasePlatform platform) {
switch (platform.getPlatform()) {