Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Food for though concept of multiple dimension array support #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/java/net/kaleidos/hibernate/usertype/ArrayType.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class ArrayType implements UserType, ParameterizedType {
}

private Class<?> typeClass;
private int[] arrayDimensions;
private BidiEnumMap bidiMap;

@Override
Expand Down Expand Up @@ -78,11 +79,14 @@ public void setParameterValues(Properties parameters) {
if (typeClass == null) {
throw new RuntimeException("The user type needs to be configured with the type. None provided");
}
Integer dimension = 1;
if (parameters.containsKey("dim")) dimension = (Integer)(parameters.get("dim"));
arrayDimensions = new int[dimension];
}

@Override
public Class<?> returnedClass() {
return java.lang.reflect.Array.newInstance(typeClass, 0).getClass();
return java.lang.reflect.Array.newInstance(typeClass, arrayDimensions).getClass();
}

@Override
Expand All @@ -103,7 +107,7 @@ public int[] sqlTypes() {
@Override
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException {
Object result = null;
Class typeArrayClass = java.lang.reflect.Array.newInstance(typeClass, 0).getClass();
Class typeArrayClass = java.lang.reflect.Array.newInstance(typeClass, arrayDimensions).getClass();
Array sqlArray = rs.getArray(names[0]);
if (!rs.wasNull()) {
Object array = sqlArray.getArray();
Expand All @@ -128,7 +132,7 @@ public void nullSafeSet(PreparedStatement st, Object value, int index, SessionIm
}

Object[] valueToSet = (Object[]) value;
Class typeArrayClass = java.lang.reflect.Array.newInstance(typeClass, 0).getClass();
Class typeArrayClass = java.lang.reflect.Array.newInstance(typeClass, arrayDimensions).getClass();

if (typeClass.isEnum()) {
typeArrayClass = Integer[].class;
Expand Down