#1011 - Create valid migration scripts for non-Postgres databases and @DbArray columns.

Merge branch 'test/dbarray-create-migration' of https://github.com/FOCONIS/ebean into FOCONIS-test/dbarray-create-migration

commit 3a8f32b173
Author: Michael Benz <michael.benz@foconis.de>
Date:   Wed Apr 19 18:16:51 2017 +0200

    adding dbmigration ddlgeneration test for Ebean @DbArray extension.
This commit is contained in:
rob bygrave
2017-05-20 23:40:02 +12:00
parent 79f7c73983
commit fe9500e6d0
11 changed files with 184 additions and 24 deletions
@@ -245,13 +245,15 @@ public class DeployUtil {
prop.setDbType(dbType);
prop.setScalarType(scalarType);
if (scalarType instanceof ScalarTypeArray) {
prop.setDbColumnDefn(((ScalarTypeArray) scalarType).getDbColumnDefn());
}
if (dbType == Types.VARCHAR) {
// determine the db column size
int dbLength = dbArray.length();
int columnLength = (dbLength > 0) ? dbLength : DEFAULT_ARRAY_VARCHAR_LENGTH;
prop.setDbLength(columnLength);
String columnDefn = ((ScalarTypeArray) scalarType).getDbColumnDefn();
if (dbArray.length() > 0) {
// fallback varchar column length when ARRAY not support by DB
columnDefn += "(" + dbArray.length() + ")";
}
prop.setDbLength(dbArray.length());
prop.setDbColumnDefn(columnDefn);
} else {
throw new RuntimeException("Not mapped to ScalarTypeArray? " + scalarType.getClass());
}
}
@@ -52,11 +52,6 @@ class ScalarTypeArrayListH2 extends ScalarTypeArrayList {
super(arrayType, docPropertyType, converter);
}
@Override
public String getDbColumnDefn() {
return "array";
}
@Override
public void bind(DataBind bind, List value) throws SQLException {
if (value == null) {
@@ -52,11 +52,6 @@ class ScalarTypeArraySetH2 extends ScalarTypeArraySet {
super(arrayType, docPropertyType, converter);
}
@Override
public String getDbColumnDefn() {
return "array";
}
@Override
public void bind(DataBind bind, Set value) throws SQLException {
if (value == null) {
@@ -6,7 +6,7 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
abstract class ScalarTypeJsonCollection<T> extends ScalarTypeBase<T> {
abstract class ScalarTypeJsonCollection<T> extends ScalarTypeBase<T> implements ScalarTypeArray {
protected DocPropertyType docPropertyType;
@@ -15,6 +15,23 @@ abstract class ScalarTypeJsonCollection<T> extends ScalarTypeBase<T> {
this.docPropertyType = docPropertyType;
}
/**
* Return the logical db column definition based on the element document type.
*/
@Override
public String getDbColumnDefn() {
switch (docPropertyType) {
case SHORT:
case INTEGER:
case LONG:
return "integer[]";
case DOUBLE:
case FLOAT:
return "decimal[]";
}
return "varchar[]";
}
/**
* Consider as a mutable type. Use the isDirty() method to check for dirty state.
*/