OPENJPA-245

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@615317 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Patrick Linskey 2008-01-25 19:41:57 +00:00
parent 2a45dc5929
commit 2a612c1053
2 changed files with 33 additions and 31 deletions

View File

@ -98,11 +98,7 @@ class AttachManager {
CallbackException excep = null;
try {
PersistenceCapable into = findFromDatabase(pc);
OpenJPAStateManager owner = (into == null) ? null
: (OpenJPAStateManager) into.pcGetStateManager();
return attach(pc, into, owner, null, true);
return attach(pc, null, null, null, true);
} catch (CallbackException ce) {
excep = ce;
return null; // won't be reached as the exceps will be rethrown
@ -339,30 +335,4 @@ class AttachManager {
Exceptions.toString(obj))).setFailedObject (obj);
return sm;
}
/**
* Find a PersistenceCapable instance of an Object if it exists in the
* database. If the object is null or can't be found in the database.
*
* @param pc An object which will be attached into the current context. The
* object may or may not correspond to a row in the database.
*
* @return If the object is null or can't be found in the database this
* method returns null. Otherwise a PersistenceCapable representation of the
* object is returned.
*/
protected PersistenceCapable findFromDatabase(Object pc) {
PersistenceCapable rval = null;
if (pc != null) {
Object oid = _broker.newObjectId(pc.getClass(),
getDetachedObjectId(pc));
if (oid != null) {
rval = ImplHelper.toPersistenceCapable(_broker.find(oid, true,
null), getBroker().getConfiguration());
}
}
return rval;
}
}

View File

@ -68,6 +68,13 @@ class VersionAttachStrategy
public Object attach(AttachManager manager, Object toAttach,
ClassMetaData meta, PersistenceCapable into, OpenJPAStateManager owner,
ValueMetaData ownerMeta, boolean explicit) {
// VersionAttachStrategy is invoked in the case where no more
// intelligent strategy could be found; let's be more lenient
// about new vs. detached record determination.
if (into == null)
into = findFromDatabase(manager, toAttach);
BrokerImpl broker = manager.getBroker();
PersistenceCapable pc = ImplHelper.toPersistenceCapable(toAttach,
meta.getRepository().getConfiguration());
@ -342,4 +349,29 @@ class VersionAttachStrategy
}
return (copy == null) ? map : copy;
}
/**
* Find a PersistenceCapable instance of an Object if it exists in the
* database. If the object is null or can't be found in the database.
*
* @param pc An object which will be attached into the current context. The
* object may or may not correspond to a row in the database.
*
* @return If the object is null or can't be found in the database this
* method returns null. Otherwise a PersistenceCapable representation of the
* object is returned.
*/
protected PersistenceCapable findFromDatabase(AttachManager manager,
Object pc) {
Object oid = manager.getBroker().newObjectId(pc.getClass(),
manager.getDetachedObjectId(pc));
if (oid != null) {
return ImplHelper.toPersistenceCapable(
manager.getBroker().find(oid, true, null),
manager.getBroker().getConfiguration());
} else {
return null;
}
}
}