Update our Modifier's key on an insert (and store) so that it can (eventually)

properly cache the results of our insert based on the newly assigned primary
key. Also avoid freakout if an attempt is made to store() a non-primary-key
using object.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@1928 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2006-09-26 19:51:58 +00:00
parent eaa520044b
commit 60bd39e8b6
2 changed files with 22 additions and 8 deletions
@@ -340,24 +340,28 @@ public class DepotMarshaller<T>
/**
* Fills in the primary key just assigned to the supplied persistence
* object by the execution of the results of {@link #createInsert}.
*
* @return the newly assigned primary key or null if the object does not
* use primary keys or this is not the right time to assign the key.
*/
public void assignPrimaryKey (
public DepotRepository.Key assignPrimaryKey (
Connection conn, Object po, boolean postFactum)
throws SQLException
{
// if we have no primary key or no generator, then we're done
if (!hasPrimaryKey() || _keyGenerator == null) {
return;
return null;
}
// run this generator either before or after the actual insertion
if (_keyGenerator.isPostFactum() != postFactum) {
return;
return null;
}
try {
int nextValue = _keyGenerator.nextGeneratedValue(conn);
_primaryKey.getField().set(po, nextValue);
return makePrimaryKey(nextValue);
} catch (Exception e) {
String errmsg = "Failed to assign primary key " +
"[type=" + _pclass + "]";