mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#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:
@@ -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()) {
|
||||
|
||||
+46
-5
@@ -2,12 +2,14 @@ package io.ebeaninternal.dbmigration.ddlgeneration.platform;
|
||||
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.config.dbplatform.IdType;
|
||||
import io.ebean.config.dbplatform.h2.H2Platform;
|
||||
import io.ebean.config.dbplatform.sqlserver.SqlServerPlatform;
|
||||
import io.ebean.config.dbplatform.mysql.MySqlPlatform;
|
||||
import io.ebean.config.dbplatform.oracle.OraclePlatform;
|
||||
import io.ebean.config.dbplatform.postgres.PostgresPlatform;
|
||||
import io.ebeaninternal.dbmigration.migration.AlterColumn;
|
||||
import io.ebeaninternal.dbmigration.migration.IdentityType;
|
||||
import io.ebeaninternal.server.core.PlatformDdlBuilder;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -17,16 +19,17 @@ import static org.junit.Assert.assertNull;
|
||||
|
||||
public class PlatformDdl_AlterColumnTest {
|
||||
|
||||
PlatformDdl h2Ddl = PlatformDdlBuilder.create(new H2Platform());
|
||||
PlatformDdl pgDdl = PlatformDdlBuilder.create(new PostgresPlatform());
|
||||
PlatformDdl mysqlDdl = PlatformDdlBuilder.create(new MySqlPlatform());
|
||||
PlatformDdl oraDdl = PlatformDdlBuilder.create(new OraclePlatform());
|
||||
PlatformDdl sqlServerDdl = PlatformDdlBuilder.create(new SqlServerPlatform());
|
||||
private PlatformDdl h2Ddl = PlatformDdlBuilder.create(new H2Platform());
|
||||
private PlatformDdl pgDdl = PlatformDdlBuilder.create(new PostgresPlatform());
|
||||
private PlatformDdl mysqlDdl = PlatformDdlBuilder.create(new MySqlPlatform());
|
||||
private PlatformDdl oraDdl = PlatformDdlBuilder.create(new OraclePlatform());
|
||||
private PlatformDdl sqlServerDdl = PlatformDdlBuilder.create(new SqlServerPlatform());
|
||||
|
||||
{
|
||||
ServerConfig serverConfig = Ebean.getDefaultServer().getPluginApi().getServerConfig();
|
||||
sqlServerDdl.configure(serverConfig);
|
||||
}
|
||||
|
||||
AlterColumn alterNotNull() {
|
||||
AlterColumn alterColumn = new AlterColumn();
|
||||
alterColumn.setTableName("mytab");
|
||||
@@ -185,4 +188,42 @@ public class PlatformDdl_AlterColumnTest {
|
||||
assertThat(sql).startsWith("delimiter $$").endsWith("$$");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useIdentityType_h2() {
|
||||
assertEquals(h2Ddl.useIdentityType(null), IdType.IDENTITY);
|
||||
assertEquals(h2Ddl.useIdentityType(IdentityType.SEQUENCE), IdType.SEQUENCE);
|
||||
assertEquals(h2Ddl.useIdentityType(IdentityType.IDENTITY), IdType.IDENTITY);
|
||||
assertEquals(h2Ddl.useIdentityType(IdentityType.GENERATOR), IdType.GENERATOR);
|
||||
assertEquals(h2Ddl.useIdentityType(IdentityType.EXTERNAL), IdType.EXTERNAL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useIdentityType_postgres() {
|
||||
assertEquals(pgDdl.useIdentityType(IdentityType.GENERATOR), IdType.GENERATOR);
|
||||
assertEquals(pgDdl.useIdentityType(IdentityType.EXTERNAL), IdType.EXTERNAL);
|
||||
|
||||
assertEquals(pgDdl.useIdentityType(null), IdType.IDENTITY);
|
||||
assertEquals(pgDdl.useIdentityType(IdentityType.SEQUENCE), IdType.SEQUENCE);
|
||||
assertEquals(pgDdl.useIdentityType(IdentityType.IDENTITY), IdType.IDENTITY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useIdentityType_mysql() {
|
||||
|
||||
assertEquals(mysqlDdl.useIdentityType(null), IdType.IDENTITY);
|
||||
assertEquals(mysqlDdl.useIdentityType(IdentityType.SEQUENCE), IdType.IDENTITY);
|
||||
assertEquals(mysqlDdl.useIdentityType(IdentityType.IDENTITY), IdType.IDENTITY);
|
||||
assertEquals(mysqlDdl.useIdentityType(IdentityType.GENERATOR), IdType.GENERATOR);
|
||||
assertEquals(mysqlDdl.useIdentityType(IdentityType.EXTERNAL), IdType.EXTERNAL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useIdentityType_oracle() {
|
||||
|
||||
assertEquals(oraDdl.useIdentityType(null), IdType.SEQUENCE);
|
||||
assertEquals(oraDdl.useIdentityType(IdentityType.SEQUENCE), IdType.SEQUENCE);
|
||||
assertEquals(oraDdl.useIdentityType(IdentityType.IDENTITY), IdType.SEQUENCE);
|
||||
assertEquals(oraDdl.useIdentityType(IdentityType.GENERATOR), IdType.GENERATOR);
|
||||
assertEquals(oraDdl.useIdentityType(IdentityType.EXTERNAL), IdType.EXTERNAL);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user