mirror of https://github.com/apache/openjpa.git
OPENJPA-245
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@615317 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2a45dc5929
commit
2a612c1053
|
@ -98,11 +98,7 @@ class AttachManager {
|
||||||
|
|
||||||
CallbackException excep = null;
|
CallbackException excep = null;
|
||||||
try {
|
try {
|
||||||
PersistenceCapable into = findFromDatabase(pc);
|
return attach(pc, null, null, null, true);
|
||||||
OpenJPAStateManager owner = (into == null) ? null
|
|
||||||
: (OpenJPAStateManager) into.pcGetStateManager();
|
|
||||||
return attach(pc, into, owner, null, true);
|
|
||||||
|
|
||||||
} catch (CallbackException ce) {
|
} catch (CallbackException ce) {
|
||||||
excep = ce;
|
excep = ce;
|
||||||
return null; // won't be reached as the exceps will be rethrown
|
return null; // won't be reached as the exceps will be rethrown
|
||||||
|
@ -339,30 +335,4 @@ class AttachManager {
|
||||||
Exceptions.toString(obj))).setFailedObject (obj);
|
Exceptions.toString(obj))).setFailedObject (obj);
|
||||||
return sm;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,13 @@ class VersionAttachStrategy
|
||||||
public Object attach(AttachManager manager, Object toAttach,
|
public Object attach(AttachManager manager, Object toAttach,
|
||||||
ClassMetaData meta, PersistenceCapable into, OpenJPAStateManager owner,
|
ClassMetaData meta, PersistenceCapable into, OpenJPAStateManager owner,
|
||||||
ValueMetaData ownerMeta, boolean explicit) {
|
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();
|
BrokerImpl broker = manager.getBroker();
|
||||||
PersistenceCapable pc = ImplHelper.toPersistenceCapable(toAttach,
|
PersistenceCapable pc = ImplHelper.toPersistenceCapable(toAttach,
|
||||||
meta.getRepository().getConfiguration());
|
meta.getRepository().getConfiguration());
|
||||||
|
@ -342,4 +349,29 @@ class VersionAttachStrategy
|
||||||
}
|
}
|
||||||
return (copy == null) ? map : copy;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue