// first insertion of the userObject into editing context
Object swizzledObject = swizzlingStrategy.swizzle(userObject, null, _pb, this);
entry = new ContextEntry(swizzledObject);
if (entry.handler != null)
{
ObjectCopyStrategy copyStrategy = _tx.getKit().getCopyStrategy(oid);
entry.cacheObject = copyStrategy.copy(userObject, _pb);
// Assume that object exists, otherwise were the proxy came from?
_objects.put(oid, entry);
lockManager.ensureLock(oid, _tx, lock, _pb); // lock after _objects.put to avoid hanged locks
entry.handler.addListener(this);
}
else
{
Object origCacheObj = _pb.getObjectByIdentity(oid);
if ((origCacheObj == null) && !canCreate)
{
// we don't create the objects by reachability
throw new IllegalStateException("Related object is neither persistent, nor otm-depentent: " + oid);
}
if (origCacheObj != null)
{
entry.cacheObject = origCacheObj;
}
buildingObject = true;
_objects.put(oid, entry);
lockManager.ensureLock(oid, _tx, lock, _pb); // lock after _objects.put to avoid hanged locks
if (userObject != null)
{
if ((origCacheObj == null) && canCreate)
{
ObjectCopyStrategy copyStrategy = _tx.getKit().getCopyStrategy(oid);
entry.cacheObject = copyStrategy.copy(userObject, _pb);
entry.state = State.PERSISTENT_NEW;
if (kit.isEagerInsert(userObject)
|| hasBidirectionalAssociation(userObject.getClass()))
{
_pb.store(entry.cacheObject, entry.state);