#824 - Refactor com.avaje.ebean.config.dbplatform DbType & DbPlatformType - handle logical and plaform ddl conversion

This commit is contained in:
Robin Bygrave
2016-10-03 22:04:37 +13:00
parent d26203db1f
commit f1eb494e0d
4 changed files with 18 additions and 12 deletions
@@ -59,16 +59,17 @@ public class DbPlatformTypeMapping {
put(DbType.TIMESTAMP);
put(DbType.LONGVARBINARY);
put(DbType.LONGVARCHAR);
put(DbType.VARBINARY, new DbPlatformType("varbinary", 255));
put(DbType.BINARY, new DbPlatformType("binary", 255));
put(DbType.REAL, new DbPlatformType("float")); // most commonly read maps to db float
put(DbType.DECIMAL, new DbPlatformType("decimal", 38));
put(DbType.VARCHAR, new DbPlatformType("varchar", 255));
put(DbType.CHAR, new DbPlatformType("char", 1));
// most commonly real maps to db float
put(DbType.REAL, new DbPlatformType("float"));
if (logicalTypes) {
// keep it logical for 2 layer DDL generation
put(DbType.VARCHAR, new DbPlatformType("varchar"));
put(DbType.DECIMAL, new DbPlatformType("decimal"));
put(DbType.VARBINARY, new DbPlatformType("varbinary"));
put(DbType.BINARY, new DbPlatformType("binary"));
put(DbType.CHAR, new DbPlatformType("char"));
put(DbType.HSTORE, new DbPlatformType("hstore", false));
put(DbType.JSON, new DbPlatformType("json", false));
put(DbType.JSONB, new DbPlatformType("jsonb", false));
@@ -78,6 +79,12 @@ public class DbPlatformTypeMapping {
put(DbType.UUID, UUID_NATIVE);
} else {
put(DbType.VARCHAR, new DbPlatformType("varchar", 255));
put(DbType.DECIMAL, new DbPlatformType("decimal", 38));
put(DbType.VARBINARY, new DbPlatformType("varbinary", 255));
put(DbType.BINARY, new DbPlatformType("binary", 255));
put(DbType.CHAR, new DbPlatformType("char", 1));
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);
@@ -14,11 +14,11 @@ class DbPlatformTypeParser {
int openPos = columnDefinition.indexOf('(');
if (openPos == -1) {
return new DbPlatformType(columnDefinition);
return new DbPlatformType(columnDefinition, false);
}
int closePos = columnDefinition.indexOf(')', openPos);
if (closePos == -1) {
return new DbPlatformType(columnDefinition);
return new DbPlatformType(columnDefinition, false);
}
try {
int commaPos = columnDefinition.indexOf(',', openPos);
@@ -34,7 +34,7 @@ class DbPlatformTypeParser {
return new DbPlatformType(type, scale);
}
} catch (RuntimeException e) {
return new DbPlatformType(columnDefinition);
return new DbPlatformType(columnDefinition, false);
}
}
}
@@ -110,7 +110,6 @@ public class PlatformDdl {
* Set configuration options.
*/
public void configure(ServerConfig serverConfig) {
platform.configure(serverConfig);
historyDdl.configure(serverConfig, this);
naming = serverConfig.getConstraintNaming();
}