diff --git a/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java b/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java index 1414fa9..bad2b01 100644 --- a/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java +++ b/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java @@ -173,6 +173,14 @@ public class DepotMarshaller return _tableName; } + /** + * Returns true if our persistent object defines a primary key. + */ + public boolean hasPrimaryKey () + { + return (_primaryKey != null); + } + /** * Returns a key configured with the primary key of the supplied object. * Throws an exception if the persistent object did not declare a primary @@ -180,7 +188,7 @@ public class DepotMarshaller */ public DepotRepository.Key getPrimaryKey (Object object) { - if (_primaryKey == null) { + if (!hasPrimaryKey()) { throw new UnsupportedOperationException( getClass().getName() + " does not define a primary key"); } @@ -338,7 +346,7 @@ public class DepotMarshaller throws SQLException { // if we have no primary key or no generator, then we're done - if (_primaryKey == null || _keyGenerator == null) { + if (!hasPrimaryKey() || _keyGenerator == null) { return; } diff --git a/src/java/com/samskivert/jdbc/depot/DepotRepository.java b/src/java/com/samskivert/jdbc/depot/DepotRepository.java index 8c977cd..bfc2a3a 100644 --- a/src/java/com/samskivert/jdbc/depot/DepotRepository.java +++ b/src/java/com/samskivert/jdbc/depot/DepotRepository.java @@ -140,7 +140,7 @@ public class DepotRepository throws PersistenceException { final DepotMarshaller marsh = getMarshaller(record.getClass()); - return invoke(new Modifier(marsh.getPrimaryKey(record)) { + return invoke(new Modifier(null) { public int invoke (Connection conn) throws SQLException { marsh.assignPrimaryKey(conn, record, false); PreparedStatement stmt = marsh.createInsert(conn, record); @@ -467,7 +467,9 @@ public class DepotRepository // TODO: retry query on transient failure Connection conn = _conprov.getConnection(getIdent(), false); try { - return modifier.invoke(conn); + int result = modifier.invoke(conn); + // TODO: (optionally) cache the results of the modifier + return result; } catch (SQLException sqe) { // convert this exception to a DuplicateKeyException if appropriate