From bd1359e7bb3b4d007fbf66d32576c1f949d5eaae Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Fri, 2 Mar 2007 04:36:04 +0000 Subject: [PATCH] Return whether we updated or inserted. --- src/java/com/samskivert/jdbc/depot/DepotRepository.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/java/com/samskivert/jdbc/depot/DepotRepository.java b/src/java/com/samskivert/jdbc/depot/DepotRepository.java index 61d4718..41bb26a 100644 --- a/src/java/com/samskivert/jdbc/depot/DepotRepository.java +++ b/src/java/com/samskivert/jdbc/depot/DepotRepository.java @@ -535,14 +535,15 @@ public class DepotRepository * is null or zero), it will be inserted directly. Otherwise an update will first be attempted * and if that matches zero rows, the object will be inserted. * - * @return the number of rows modified by this action, this should always be one. + * @return true if the record was created, false if it was updated. */ - protected int store (T record) + protected boolean store (T record) throws PersistenceException { final DepotMarshaller marsh = _ctx.getMarshaller(record.getClass()); final Key key = marsh.hasPrimaryKey() ? marsh.getPrimaryKey(record) : null; - return _ctx.invoke(new CachingModifier(record, key, key) { + final boolean[] created = new boolean[1]; + _ctx.invoke(new CachingModifier(record, key, key) { public int invoke (Connection conn) throws SQLException { PreparedStatement stmt = null; try { @@ -563,6 +564,7 @@ public class DepotRepository stmt = marsh.createInsert(conn, _result); int mods = stmt.executeUpdate(); updateKey(marsh.assignPrimaryKey(conn, _result, true)); + created[0] = true; return mods; } finally { @@ -570,6 +572,7 @@ public class DepotRepository } } }); + return created[0]; } /**