#1646 - Ensure that java.sql.Array.free() is called

This commit is contained in:
rob bygrave
2019-03-07 09:25:48 +13:00
parent e7e6e00473
commit 197852857d
3 changed files with 36 additions and 26 deletions
@@ -0,0 +1,30 @@
package io.ebeaninternal.server.type;
import io.ebeanservice.docstore.api.mapping.DocPropertyType;
import java.sql.Array;
import java.sql.SQLException;
abstract class ScalarTypeArrayBase<T> extends ScalarTypeJsonCollection<T> {
ScalarTypeArrayBase(Class<T> type, int dbType, DocPropertyType docPropertyType) {
super(type, dbType, docPropertyType);
}
@Override
public T read(DataReader reader) throws SQLException {
Array array = reader.getArray();
if (array == null) {
return null;
} else {
try {
return fromArray((Object[]) array.getArray());
} finally {
array.free();
}
}
}
protected abstract T fromArray(Object[] array1);
}
@@ -11,7 +11,6 @@ import io.ebeanservice.docstore.api.mapping.DocPropertyType;
import javax.persistence.PersistenceException;
import java.io.IOException;
import java.lang.reflect.Type;
import java.sql.Array;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
@@ -22,7 +21,7 @@ import java.util.UUID;
* Type mapped for DB ARRAY type (Postgres only effectively).
*/
@SuppressWarnings("rawtypes")
public class ScalarTypeArrayList extends ScalarTypeJsonCollection<List> implements ScalarTypeArray {
public class ScalarTypeArrayList extends ScalarTypeArrayBase<List> implements ScalarTypeArray {
private static ScalarTypeArrayList UUID = new ScalarTypeArrayList("uuid", DocPropertyType.UUID, ArrayElementConverter.UUID);
private static ScalarTypeArrayList LONG = new ScalarTypeArrayList("bigint", DocPropertyType.LONG, ArrayElementConverter.LONG);
@@ -101,7 +100,8 @@ public class ScalarTypeArrayList extends ScalarTypeJsonCollection<List> implemen
}
@SuppressWarnings("unchecked")
private List fromArray(Object[] array1) {
@Override
protected List fromArray(Object[] array1) {
List list = new ArrayList(array1.length);
for (Object element : array1) {
list.add(converter.toElement(element));
@@ -113,16 +113,6 @@ public class ScalarTypeArrayList extends ScalarTypeJsonCollection<List> implemen
return converter.toDbArray(value.toArray());
}
@Override
public List read(DataReader reader) throws SQLException {
Array array = reader.getArray();
if (array == null) {
return null;
} else {
return fromArray((Object[]) array.getArray());
}
}
@Override
public void bind(DataBind bind, List value) throws SQLException {
if (value == null) {
@@ -11,7 +11,6 @@ import io.ebeanservice.docstore.api.mapping.DocPropertyType;
import javax.persistence.PersistenceException;
import java.io.IOException;
import java.lang.reflect.Type;
import java.sql.Array;
import java.sql.SQLException;
import java.sql.Types;
import java.util.LinkedHashSet;
@@ -21,7 +20,7 @@ import java.util.UUID;
/**
* Type mapped for DB ARRAY type (Postgres only effectively).
*/
public class ScalarTypeArraySet<T> extends ScalarTypeJsonCollection<Set<T>> implements ScalarTypeArray {
public class ScalarTypeArraySet<T> extends ScalarTypeArrayBase<Set<T>> implements ScalarTypeArray {
private static final ScalarTypeArraySet<UUID> UUID = new ScalarTypeArraySet<>("uuid", DocPropertyType.UUID, ArrayElementConverter.UUID);
private static final ScalarTypeArraySet<Long> LONG = new ScalarTypeArraySet<>("bigint", DocPropertyType.LONG, ArrayElementConverter.LONG);
@@ -100,7 +99,8 @@ public class ScalarTypeArraySet<T> extends ScalarTypeJsonCollection<Set<T>> impl
return arrayType + "[]";
}
private Set<T> fromArray(Object[] array1) {
@Override
protected Set<T> fromArray(Object[] array1) {
Set<T> set = new LinkedHashSet<>();
for (Object element : array1) {
set.add(converter.toElement(element));
@@ -112,16 +112,6 @@ public class ScalarTypeArraySet<T> extends ScalarTypeJsonCollection<Set<T>> impl
return converter.toDbArray(value.toArray());
}
@Override
public Set<T> read(DataReader reader) throws SQLException {
Array array = reader.getArray();
if (array == null) {
return null;
} else {
return fromArray((Object[]) array.getArray());
}
}
@Override
public void bind(DataBind bind, Set<T> value) throws SQLException {
if (value == null) {