mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#824 - Refactor com.avaje.ebean.config.dbplatform DbType & DbPlatformType
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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)");
|
||||
}
|
||||
|
||||
|
||||
@@ -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)");
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
+6
-6
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user