From a7f04bb8b0ea663e7be1a2dfe456f56c56864815 Mon Sep 17 00:00:00 2001 From: mdb Date: Wed, 12 Apr 2006 22:21:15 +0000 Subject: [PATCH] Make the lastInsertedId available when using store(). git-svn-id: https://samskivert.googlecode.com/svn/trunk@1819 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- src/java/com/samskivert/jdbc/JORARepository.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/java/com/samskivert/jdbc/JORARepository.java b/src/java/com/samskivert/jdbc/JORARepository.java index 15b9deee..48a3f154 100644 --- a/src/java/com/samskivert/jdbc/JORARepository.java +++ b/src/java/com/samskivert/jdbc/JORARepository.java @@ -163,18 +163,22 @@ public abstract class JORARepository extends SimpleRepository * First attempts to update the supplied object and if that modifies * zero rows, inserts the object into the specified table. The table * must be configured to store items of the supplied type. + * + * @return -1 if the object was updated, the last inserted id if it was + * inserted. */ - protected void store (final Table table, final T object) + protected int store (final Table table, final T object) throws PersistenceException { - execute(new Operation() { - public Object invoke (Connection conn, DatabaseLiaison liaison) + return execute(new Operation() { + public Integer invoke (Connection conn, DatabaseLiaison liaison) throws SQLException, PersistenceException { if (table.update(object) == 0) { table.insert(object); + return liaison.lastInsertedId(conn); } - return null; + return -1; } }); }