#1344 - ENH: Add initial Cockroach DB support ... need to review JSON

Adds in the DB ARRAY support (exactly the same as Postgres)
This commit is contained in:
Rob Bygrave
2018-03-09 17:40:34 +13:00
parent 8ac1b745df
commit eda6350d89
8 changed files with 68 additions and 18 deletions
@@ -381,6 +381,13 @@ public class DatabasePlatform {
this.historySupport = historySupport;
}
/**
* So no except for Postgres and CockroachDB.
*/
public boolean isNativeArrayType() {
return false;
}
/**
* Return true if the DB supports native UUID.
*/
@@ -88,6 +88,14 @@ public class PostgresPlatform extends DatabasePlatform {
return new DbPlatformType("geometry(" + type + "," + srid + ")");
}
/**
* So we can generate varchar[], int[], uuid[] column definitions and use the associated scalar types.
*/
@Override
public boolean isNativeArrayType() {
return true;
}
/**
* Create a Postgres specific sequence IdGenerator.
*/
@@ -17,10 +17,10 @@ public class CockroachDdl extends PlatformDdl {
this.columnSetNull = "drop not null";
}
// @Override
// protected String convertArrayType(String logicalArrayType) {
// TODO: Need to look at DB Array support ...
// }
@Override
protected String convertArrayType(String logicalArrayType) {
return NativeDbArray.logicalToNative(logicalArrayType);
}
/**
* Map bigint, integer and smallint all into serial.
@@ -0,0 +1,20 @@
package io.ebeaninternal.dbmigration.ddlgeneration.platform;
/**
* Helper for logical type conversion.
*/
class NativeDbArray {
/**
* Covert the 'logical' array type to a native one (for Postgres and Cockroach).
*/
static String logicalToNative(String logicalArrayType) {
int colonPos = logicalArrayType.lastIndexOf(']');
if (colonPos == -1) {
return logicalArrayType;
} else {
// trim of the fallback varchar length
return logicalArrayType.substring(0, colonPos + 1);
}
}
}
@@ -18,13 +18,7 @@ public class PostgresDdl extends PlatformDdl {
@Override
protected String convertArrayType(String logicalArrayType) {
int colonPos = logicalArrayType.lastIndexOf(']');
if (colonPos == -1) {
return logicalArrayType;
} else {
// trim of the fallback varchar length
return logicalArrayType.substring(0, colonPos + 1);
}
return NativeDbArray.logicalToNative(logicalArrayType);
}
/**
@@ -189,8 +189,8 @@ public final class DefaultTypeManager implements TypeManager {
this.extraTypeFactory = new DefaultTypeFactory(config);
this.postgres = isPostgres(config.getDatabasePlatform());
this.arrayTypeListFactory = arrayTypeListFactory(postgres, config.getDatabasePlatform());
this.arrayTypeSetFactory = arrayTypeSetFactory(postgres, config.getDatabasePlatform());
this.arrayTypeListFactory = arrayTypeListFactory(config.getDatabasePlatform());
this.arrayTypeSetFactory = arrayTypeSetFactory(config.getDatabasePlatform());
this.offlineMigrationGeneration = DbOffline.isGenerateMigration();
@@ -211,8 +211,8 @@ public final class DefaultTypeManager implements TypeManager {
/**
* Return the factory to use to support DB ARRAY types.
*/
private PlatformArrayTypeFactory arrayTypeListFactory(boolean postgres, DatabasePlatform databasePlatform) {
if (postgres) {
private PlatformArrayTypeFactory arrayTypeListFactory(DatabasePlatform databasePlatform) {
if (databasePlatform.isNativeArrayType()) {
return ScalarTypeArrayList.factory();
} else if (databasePlatform.isPlatform(Platform.H2)) {
return ScalarTypeArrayListH2.factory();
@@ -224,8 +224,8 @@ public final class DefaultTypeManager implements TypeManager {
/**
* Return the factory to use to support DB ARRAY types.
*/
private PlatformArrayTypeFactory arrayTypeSetFactory(boolean postgres, DatabasePlatform databasePlatform) {
if (postgres) {
private PlatformArrayTypeFactory arrayTypeSetFactory(DatabasePlatform databasePlatform) {
if (databasePlatform.isNativeArrayType()) {
return ScalarTypeArraySet.factory();
} else if (databasePlatform.isPlatform(Platform.H2)) {
return ScalarTypeArraySetH2.factory();