Handles attaching instances.
| Method from org.apache.openjpa.kernel.AttachManager Detail: |
StateManagerImpl assertManaged(Object obj) {
StateManagerImpl sm = _broker.getStateManagerImpl(obj, true);
if (sm == null)
throw new UserException(_loc.get("not-managed",
Exceptions.toString(obj))).setFailedObject (obj);
return sm;
}
Throw an exception if the given object is not managed; otherwise
return its state manager. |
public Object attach(Object pc) {
if (pc == null)
return null;
CallbackException excep = null;
try {
return attach(pc, null, null, null, true);
} catch (CallbackException ce) {
excep = ce;
return null; // won't be reached as the exceps will be rethrown
} finally {
List exceps = null;
if (excep == null || !_failFast)
exceps = invokeAfterAttach(null);
else
exceps = Collections.singletonList(excep);
_attached.clear();
throwExceptions(exceps, null, false);
}
}
Return an attached version of the given instance. |
Object attach(Object toAttach,
PersistenceCapable into,
OpenJPAStateManager owner,
ValueMetaData ownerMeta,
boolean explicit) {
if (toAttach == null)
return null;
// check if already attached
Object attached = _attached.get(toAttach);
if (attached != null)
return attached;
//### need to handle ACT_CASCADE
int action = processArgument(toAttach);
if ((action & OpCallbacks.ACT_RUN) == 0)
return toAttach;
//### need to handle ACT_RUN without also ACT_CASCADE
ClassMetaData meta = _broker.getConfiguration().
getMetaDataRepositoryInstance().getMetaData(
ImplHelper.getManagedInstance(toAttach).getClass(),
_broker.getClassLoader(), true);
return getStrategy(toAttach).attach(this, toAttach, meta, into,
owner, ownerMeta, explicit);
}
|
public Object[] attachAll(Collection instances) {
Object[] attached = new Object[instances.size()];
List exceps = null;
List failed = null;
boolean opt = true;
boolean failFast = false;
try {
int i = 0;
for (Iterator itr = instances.iterator(); itr.hasNext(); i++) {
try {
attached[i] = attach(itr.next(), null, null, null, true);
} catch (OpenJPAException ke) {
// track exceptions and optimistic failed objects
if (opt && !(ke instanceof OptimisticException))
opt = false;
if (opt && ke.getFailedObject() != null)
failed = add(failed, ke.getFailedObject());
exceps = add(exceps, ke);
if (ke instanceof CallbackException && _failFast) {
failFast = true;
break;
}
}
catch (RuntimeException re) {
exceps = add(exceps, re);
}
}
} finally {
// invoke post callbacks unless all failed
if (!failFast && (exceps == null
|| exceps.size() < instances.size()))
exceps = invokeAfterAttach(exceps);
_attached.clear();
}
throwExceptions(exceps, failed, opt);
return attached;
}
Return attached versions of the given instances. |
void fireBeforeAttach(Object pc,
ClassMetaData meta) {
_broker.fireLifecycleEvent(pc, null, meta,
LifecycleEvent.BEFORE_ATTACH);
}
Fire before-attach event. |
PersistenceCapable getAttachedCopy(Object pc) {
return ImplHelper.toPersistenceCapable(_attached.get(pc),
getBroker().getConfiguration());
}
If the passed in argument has already been attached, return
the (cached) attached copy. |
public OpCallbacks getBehavior() {
return _call;
}
Return the behavior supplied on construction. |
BrokerImpl getBroker() {
return _broker;
}
|
public boolean getCopyNew() {
return _copyNew;
}
Return whether to copy new instances being persisted. |
Object getDetachedObjectId(Object pc) {
if (pc == null)
return null;
return getStrategy(pc).getDetachedObjectId(this, pc);
}
Return the detached oid of the given instance. |
ProxyManager getProxyManager() {
return _proxy;
}
|
void setAttachedCopy(Object from,
PersistenceCapable into) {
_attached.put(from, into);
}
Record the attached copy in the cache. |