From 9d7eda16f9cdacb12965376a6b9168df29c2f562 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Wed, 20 Dec 2006 19:31:46 +0000 Subject: [PATCH] Added a version of updatePartial() that takes a Map of keys and values which it converts to a list and calls the existing version. --- .../jdbc/depot/DepotRepository.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/java/com/samskivert/jdbc/depot/DepotRepository.java b/src/java/com/samskivert/jdbc/depot/DepotRepository.java index 65e5a1a..63b6c3f 100644 --- a/src/java/com/samskivert/jdbc/depot/DepotRepository.java +++ b/src/java/com/samskivert/jdbc/depot/DepotRepository.java @@ -27,6 +27,8 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; +import java.util.Map; import com.samskivert.io.PersistenceException; import com.samskivert.jdbc.ConnectionProvider; @@ -191,6 +193,29 @@ public class DepotRepository }); } + /** + * Updates the specified columns for all persistent objects matching the supplied primary key. + * + * @param type the type of the persistent object to be modified. + * @param primaryKey the primary key to match in the update. + * @param fieldsValues an mapping from the names of the fields/columns ti the values to be + * assigned. + * + * @return the number of rows modified by this action. + */ + protected int updatePartial (Class type, Comparable primaryKey, + HashMap updates) + throws PersistenceException + { + Object[] fieldsValues = new Object[updates.size()*2]; + int idx = 0; + for (Map.Entry entry : updates.entrySet()) { + fieldsValues[idx++] = entry.getKey(); + fieldsValues[idx++] = entry.getValue(); + } + return updatePartial(type, primaryKey, fieldsValues); + } + /** * Updates the specified columns for all persistent objects matching the supplied primary key. *