mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1653 - ENH: Add support for ClickHouse database
With array type conversion for primitive arrays
This commit is contained in:
@@ -49,4 +49,10 @@ public class ClickHousePlatform extends DatabasePlatform {
|
||||
dbTypeMap.put(DbType.INET, new DbPlatformType("String", false));
|
||||
dbTypeMap.put(DbType.CDIR, new DbPlatformType("String", false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNativeArrayType() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,13 +18,53 @@ abstract class ScalarTypeArrayBase<T> extends ScalarTypeJsonCollection<T> {
|
||||
return null;
|
||||
} else {
|
||||
try {
|
||||
return fromArray((Object[]) array.getArray());
|
||||
return fromArray(convertArray(array.getArray()));
|
||||
} finally {
|
||||
array.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Object[] convertArray(Object array) {
|
||||
if (array instanceof Object[]) {
|
||||
return (Object[]) array;
|
||||
}
|
||||
if (array instanceof long[]) {
|
||||
return convertLongs((long[]) array);
|
||||
}
|
||||
if (array instanceof int[]) {
|
||||
return convertInts((int[]) array);
|
||||
}
|
||||
if (array instanceof double[]) {
|
||||
return convertDoubles((double[]) array);
|
||||
}
|
||||
throw new IllegalArgumentException("Unable to convert array " + array);
|
||||
}
|
||||
|
||||
private Object[] convertLongs(long[] o) {
|
||||
Long[] list = new Long[o.length];
|
||||
for (int i = 0; i < o.length; i++) {
|
||||
list[i] = o[i];
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private Object[] convertInts(int[] o) {
|
||||
Integer[] list = new Integer[o.length];
|
||||
for (int i = 0; i < o.length; i++) {
|
||||
list[i] = o[i];
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private Object[] convertDoubles(double[] o) {
|
||||
Double[] list = new Double[o.length];
|
||||
for (int i = 0; i < o.length; i++) {
|
||||
list[i] = o[i];
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
protected abstract T fromArray(Object[] array1);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user