So while the JRE is happy to serialize arrays, EHCache is reluctant to do so in at least one place (presumably an explicit Serializable test). Let's switch to an ArrayList until further notice.
This commit is contained in:
@@ -72,10 +72,9 @@ public class BindVisitor implements ExpressionVisitor
|
|||||||
public void visit (WhereCondition<? extends PersistentRecord> whereCondition)
|
public void visit (WhereCondition<? extends PersistentRecord> whereCondition)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
Comparable[] values = whereCondition.getValues();
|
for (Comparable value : whereCondition.getValues()) {
|
||||||
for (int ii = 0; ii < values.length; ii ++) {
|
if (value != null) {
|
||||||
if (values[ii] != null) {
|
_stmt.setObject(_argIdx ++, value);
|
||||||
_stmt.setObject(_argIdx ++, values[ii]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
package com.samskivert.jdbc.depot;
|
package com.samskivert.jdbc.depot;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -98,7 +99,7 @@ public abstract class BuildVisitor implements ExpressionVisitor
|
|||||||
{
|
{
|
||||||
Class<? extends PersistentRecord> pClass = whereCondition.getPersistentClass();
|
Class<? extends PersistentRecord> pClass = whereCondition.getPersistentClass();
|
||||||
String[] keyFields = Key.getKeyFields(pClass);
|
String[] keyFields = Key.getKeyFields(pClass);
|
||||||
Comparable[] values = whereCondition.getValues();
|
List<Comparable> values = whereCondition.getValues();
|
||||||
for (int ii = 0; ii < keyFields.length; ii ++) {
|
for (int ii = 0; ii < keyFields.length; ii ++) {
|
||||||
if (ii > 0) {
|
if (ii > 0) {
|
||||||
_builder.append(" and ");
|
_builder.append(" and ");
|
||||||
@@ -109,7 +110,7 @@ public abstract class BuildVisitor implements ExpressionVisitor
|
|||||||
_enableOverrides = true;
|
_enableOverrides = true;
|
||||||
appendRhsColumn(pClass, keyFields[ii]);
|
appendRhsColumn(pClass, keyFields[ii]);
|
||||||
_enableOverrides = saved;
|
_enableOverrides = saved;
|
||||||
_builder.append(values[ii] == null ? " is null " : " = ? ");
|
_builder.append(values.get(ii) == null ? " is null " : " = ? ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ public abstract class FindAllQuery<T extends PersistentRecord>
|
|||||||
// Single-column keys result in the compact IN(keyVal1, keyVal2, ...)
|
// Single-column keys result in the compact IN(keyVal1, keyVal2, ...)
|
||||||
Comparable[] keyFieldValues = new Comparable[fetchKeys.size()];
|
Comparable[] keyFieldValues = new Comparable[fetchKeys.size()];
|
||||||
for (int ii = 0; ii < keyFieldValues.length; ii ++) {
|
for (int ii = 0; ii < keyFieldValues.length; ii ++) {
|
||||||
keyFieldValues[ii] = fetchKeys.get(ii).condition.getValues()[0];
|
keyFieldValues[ii] = fetchKeys.get(ii).condition.getValues().get(0);
|
||||||
}
|
}
|
||||||
condition = new In(_type, _marsh.getPrimaryKeyFields()[0], keyFieldValues);
|
condition = new In(_type, _marsh.getPrimaryKeyFields()[0], keyFieldValues);
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ package com.samskivert.jdbc.depot;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -44,9 +43,10 @@ public class Key<T extends PersistentRecord> extends WhereClause
|
|||||||
implements SQLExpression, CacheKey, ValidatingCacheInvalidator, Serializable
|
implements SQLExpression, CacheKey, ValidatingCacheInvalidator, Serializable
|
||||||
{
|
{
|
||||||
/** An expression that contains our key columns and values. */
|
/** An expression that contains our key columns and values. */
|
||||||
public static class WhereCondition<U extends PersistentRecord> implements SQLExpression
|
public static class WhereCondition<U extends PersistentRecord>
|
||||||
|
implements SQLExpression, Serializable
|
||||||
{
|
{
|
||||||
public WhereCondition (Class<U> pClass, Comparable[] values)
|
public WhereCondition (Class<U> pClass, ArrayList<Comparable> values)
|
||||||
{
|
{
|
||||||
_pClass = pClass;
|
_pClass = pClass;
|
||||||
_values = values;
|
_values = values;
|
||||||
@@ -69,7 +69,7 @@ public class Key<T extends PersistentRecord> extends WhereClause
|
|||||||
return _pClass;
|
return _pClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Comparable[] getValues ()
|
public ArrayList<Comparable> getValues ()
|
||||||
{
|
{
|
||||||
return _values;
|
return _values;
|
||||||
}
|
}
|
||||||
@@ -84,17 +84,17 @@ public class Key<T extends PersistentRecord> extends WhereClause
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
WhereCondition other = (WhereCondition) obj;
|
WhereCondition other = (WhereCondition) obj;
|
||||||
return _pClass == other._pClass && Arrays.equals(_values, other._values);
|
return _pClass == other._pClass && _values.equals(other.getValues());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode ()
|
public int hashCode ()
|
||||||
{
|
{
|
||||||
return _pClass.hashCode() ^ Arrays.hashCode(_values);
|
return _pClass.hashCode() ^ _values.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Class<U> _pClass;
|
protected Class<U> _pClass;
|
||||||
protected Comparable[] _values;
|
protected ArrayList<Comparable> _values;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The expression that identifies our row. */
|
/** The expression that identifies our row. */
|
||||||
@@ -145,13 +145,19 @@ public class Key<T extends PersistentRecord> extends WhereClause
|
|||||||
String[] keyFields = getKeyFields(pClass);
|
String[] keyFields = getKeyFields(pClass);
|
||||||
|
|
||||||
// now extract the values in field order and ensure none are extra or missing
|
// now extract the values in field order and ensure none are extra or missing
|
||||||
Comparable[] newValues = new Comparable[fields.length];
|
ArrayList<Comparable> newValues = new ArrayList<Comparable>();
|
||||||
for (int ii = 0; ii < keyFields.length; ii++) {
|
for (int ii = 0; ii < keyFields.length; ii++) {
|
||||||
newValues[ii] = map.remove(keyFields[ii]);
|
Comparable nugget = map.remove(keyFields[ii]);
|
||||||
// make sure we were provided with a value for this primary key field
|
if (nugget == null) {
|
||||||
if (newValues[ii] == null) {
|
// make sure we were provided with a value for this primary key field
|
||||||
throw new IllegalArgumentException("Missing value for key field: " + keyFields[ii]);
|
throw new IllegalArgumentException("Missing value for key field: " + keyFields[ii]);
|
||||||
}
|
}
|
||||||
|
if (nugget instanceof Serializable) {
|
||||||
|
newValues.add(nugget);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Non-serializable argument [key=" + keyFields[ii] + ", arg=" + nugget + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
// finally make sure we were not given any fields that are not in fact primary key fields
|
// finally make sure we were not given any fields that are not in fact primary key fields
|
||||||
@@ -185,7 +191,7 @@ public class Key<T extends PersistentRecord> extends WhereClause
|
|||||||
// from CacheKey
|
// from CacheKey
|
||||||
public Serializable getCacheKey ()
|
public Serializable getCacheKey ()
|
||||||
{
|
{
|
||||||
return this; // TODO: Optimally return a special class here containing only _values.
|
return condition.getValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
// from ValidatingCacheInvalidator
|
// from ValidatingCacheInvalidator
|
||||||
@@ -240,7 +246,7 @@ public class Key<T extends PersistentRecord> extends WhereClause
|
|||||||
if (ii > 0) {
|
if (ii > 0) {
|
||||||
builder.append(", ");
|
builder.append(", ");
|
||||||
}
|
}
|
||||||
builder.append(keyFields[ii]).append("=").append(condition.getValues()[ii]);
|
builder.append(keyFields[ii]).append("=").append(condition.getValues().get(ii));
|
||||||
}
|
}
|
||||||
builder.append(")");
|
builder.append(")");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
|
|||||||
Reference in New Issue
Block a user