IntArrayMarshaller was doing things in the wrong places to work

as a delegate for a TransformingMarshaller.
This commit is contained in:
Ray Greenwell
2010-12-01 20:59:12 +00:00
parent 52f432270d
commit 7a1f87f2a0
@@ -662,36 +662,41 @@ public abstract class FieldMarshaller<T>
} }
} }
protected static class IntArrayMarshaller extends FieldMarshaller<byte[]> { protected static class IntArrayMarshaller extends FieldMarshaller<int[]> {
@Override public String getColumnType (ColumnTyper typer, int length) { @Override public String getColumnType (ColumnTyper typer, int length) {
return typer.getBlobType(length*4); return typer.getBlobType(length*4);
} }
@Override public byte[] getFromObject (Object po) @Override public int[] getFromObject (Object po)
throws IllegalArgumentException, IllegalAccessException { throws IllegalArgumentException, IllegalAccessException {
int[] values = (int[]) _field.get(po); return (int[]) _field.get(po);
if (values == null) {
return null;
} }
ByteBuffer bbuf = ByteBuffer.allocate(values.length * 4); @Override public int[] getFromSet (ResultSet rs)
bbuf.asIntBuffer().put(values);
return bbuf.array();
}
@Override public byte[] getFromSet (ResultSet rs)
throws SQLException { throws SQLException {
return (byte[]) rs.getObject(getColumnName()); byte[] raw = (byte[]) rs.getObject(getColumnName());
int[] value;
if (raw == null) {
value = null;
} else {
value = new int[raw.length/4];
ByteBuffer.wrap(raw).asIntBuffer().get(value);
} }
@Override public void writeToObject (Object po, byte[] data) return value;
}
@Override public void writeToObject (Object po, int[] value)
throws IllegalArgumentException, IllegalAccessException { throws IllegalArgumentException, IllegalAccessException {
int[] value = null;
if (data != null) {
value = new int[data.length/4];
ByteBuffer.wrap(data).asIntBuffer().get(value);
}
_field.set(po, value); _field.set(po, value);
} }
@Override public void writeToStatement (PreparedStatement ps, int column, byte[] value) @Override public void writeToStatement (PreparedStatement ps, int column, int[] value)
throws SQLException { throws SQLException {
ps.setObject(column, value); byte[] raw;
if (value == null) {
raw = null;
} else {
ByteBuffer bbuf = ByteBuffer.allocate(value.length*4);
bbuf.asIntBuffer().put(value);
raw = bbuf.array();
}
ps.setObject(column, raw);
} }
} }