diff --git a/src/java/com/samskivert/depot/DepotRepository.java b/src/java/com/samskivert/depot/DepotRepository.java index 6725af2..67e154c 100644 --- a/src/java/com/samskivert/depot/DepotRepository.java +++ b/src/java/com/samskivert/depot/DepotRepository.java @@ -531,10 +531,11 @@ public abstract class DepotRepository * values that duplicate another row already in the database. * @throws DatabaseException if any problem is encountered communicating with the database. */ - protected int updatePartial (Key key, Object... fieldsValues) + protected int updatePartial ( + Key key, ColumnExp field, Comparable value, Object... fieldsValues) throws DatabaseException { - return updatePartial(key.getPersistentClass(), key, key, fieldsValues); + return updatePartial(key.getPersistentClass(), key, key, field, value, fieldsValues); } /** @@ -552,7 +553,7 @@ public abstract class DepotRepository * @throws DatabaseException if any problem is encountered communicating with the database. */ protected int updatePartial ( - Key key, Map fieldsValues) + Key key, Map fieldsValues) throws DatabaseException { return updatePartial(key.getPersistentClass(), key, key, fieldsValues); @@ -580,17 +581,16 @@ public abstract class DepotRepository */ protected int updatePartial ( Class type, final WhereClause key, CacheInvalidator invalidator, - Map fieldsValues) + Map fieldsValues) throws DatabaseException { // separate the arguments into keys and values final ColumnExp[] fields = new ColumnExp[fieldsValues.size()]; final SQLExpression[] values = new SQLExpression[fields.length]; int ii = 0; - for (Map.Entry entry : fieldsValues.entrySet()) { + for (Map.Entry entry : fieldsValues.entrySet()) { fields[ii] = entry.getKey(); - values[ii] = entry.getValue(); - ii ++; + values[ii++] = makeValue(entry.getValue()); } return updatePartial(type, key, invalidator, fields, values); } @@ -617,19 +617,18 @@ public abstract class DepotRepository * @throws DatabaseException if any problem is encountered communicating with the database. */ protected int updatePartial ( - Class type, final WhereClause key, CacheInvalidator invalidator, Object... fieldsValues) + Class type, final WhereClause key, CacheInvalidator invalidator, + ColumnExp field, Comparable value, Object... fieldsValues) throws DatabaseException { // separate the arguments into keys and values - final ColumnExp[] fields = new ColumnExp[fieldsValues.length/2]; - final SQLExpression[] values = new SQLExpression[fields.length]; + final ColumnExp[] fields = new ColumnExp[fieldsValues.length/2+1]; + final SQLExpression[] values = new SQLExpression[fields.length+1]; + fields[0] = field; + values[0] = makeValue(value); for (int ii = 0, idx = 0; ii < fields.length; ii++) { - fields[ii] = (ColumnExp)fieldsValues[idx++]; - if (fieldsValues[idx] instanceof SQLExpression) { - values[ii] = (SQLExpression)fieldsValues[idx++]; - } else { - values[ii] = new ValueExp(fieldsValues[idx++]); - } + fields[ii+1] = (ColumnExp)fieldsValues[idx++]; + values[ii+1] = makeValue(fieldsValues[idx++]); } return updatePartial(type, key, invalidator, fields, values); } @@ -925,6 +924,11 @@ public abstract class DepotRepository } } + protected SQLExpression makeValue (Object value) + { + return (value instanceof SQLExpression) ? (SQLExpression)value : new ValueExp(value); + } + protected PersistenceContext _ctx; protected List _dataMigs = Lists.newArrayList(); } diff --git a/src/java/com/samskivert/depot/tests/TestRepository.java b/src/java/com/samskivert/depot/tests/TestRepository.java index e4ab3ce..c16dbab 100644 --- a/src/java/com/samskivert/depot/tests/TestRepository.java +++ b/src/java/com/samskivert/depot/tests/TestRepository.java @@ -25,6 +25,7 @@ import java.sql.Timestamp; import java.util.Collections; import java.util.Set; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; import com.samskivert.jdbc.StaticConnectionProvider; @@ -98,8 +99,8 @@ public class TestRepository extends DepotRepository // repo.update(record, TestRecord.AGE, TestRecord.NAME, TestRecord.NUMBERS); repo.updatePartial(TestRecord.getKey(record.recordId), - TestRecord.AGE, 25, TestRecord.NAME, "Bob", - TestRecord.NUMBERS, new int[] { 1, 2, 3, 4, 5 }); + ImmutableMap.of(TestRecord.AGE, 25, TestRecord.NAME, "Bob", + TestRecord.NUMBERS, new int[] { 1, 2, 3, 4, 5 })); System.out.println("Updated " + repo.load(TestRecord.getKey(record.recordId))); for (int ii = 2; ii < CREATE_RECORDS; ii++) {