You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ol...@apache.org on 2004/03/04 23:45:02 UTC
cvs commit: db-ojb/src/java/org/apache/ojb/otm/core ConcreteEditingContext.java
olegnitz 2004/03/04 14:45:02
Modified: src/java/org/apache/ojb/otm/core ConcreteEditingContext.java
Log:
BugFix for update of a field of related object via makePersistent
Revision Changes Path
1.39 +37 -27 db-ojb/src/java/org/apache/ojb/otm/core/ConcreteEditingContext.java
Index: ConcreteEditingContext.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/core/ConcreteEditingContext.java,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- ConcreteEditingContext.java 2 Mar 2004 01:27:15 -0000 1.38
+++ ConcreteEditingContext.java 4 Mar 2004 22:45:02 -0000 1.39
@@ -66,6 +66,7 @@
import java.util.Date;
import java.util.List;
import java.util.Set;
+import java.util.Stack;
import org.apache.ojb.broker.Identity;
import org.apache.ojb.broker.OJBRuntimeException;
@@ -160,12 +161,12 @@
public void insert(Identity oid, Object obj, int lock)
throws LockingException
{
- insertInternal(oid, obj, lock, true, false, null);
+ insertInternal(oid, obj, lock, true, false, null, new Stack());
}
private ContextEntry insertInternal(Identity oid, Object newObj, int lock,
boolean mainObject, boolean isDependent,
- Identity insertBeforeThis)
+ Identity insertBeforeThis, Stack stack)
throws LockingException
{
ContextEntry entry;
@@ -284,9 +285,11 @@
// perform automatic read lock for all reachable objects
// if the inserted object is materialized
- if ((handler == null) && (newObj != null))
+ if ((handler == null) && (newObj != null) && !stack.contains(newObj))
{
- lockReachableObjects(oid, newObj, lock);
+ stack.push(newObj);
+ lockReachableObjects(oid, newObj, lock, stack);
+ stack.pop();
}
return entry;
@@ -307,7 +310,8 @@
{
ContextEntry entry;
- entry = insertInternal(oid, object, LockType.WRITE_LOCK, true, false, null);
+ entry = insertInternal(oid, object, LockType.WRITE_LOCK, true, false,
+ null, new Stack());
if (entry != null)
{
entry.state = entry.state.deletePersistent();
@@ -397,7 +401,7 @@
// if the inserted object is materialized
try
{
- lockReachableObjects(oid, object, lock);
+ lockReachableObjects(oid, object, lock, new Stack());
}
catch (LockingException ex)
{
@@ -718,9 +722,11 @@
* Lock all objects reachable via 1:N and N:1 relations,
* @param lock The lock type to use
*/
- private void lockReachableObjects(Identity oid, Object object, int lock)
+ private void lockReachableObjects(Identity oid, Object object, int lock,
+ Stack stack)
throws LockingException
{
+ ContextEntry entry;
boolean onlyDependants = !_tx.getKit().isImplicitLockingUsed();
ClassDescriptor mif = _pb.getClassDescriptor(object.getClass());
@@ -747,13 +753,13 @@
{
relOid = new Identity(relObj, _pb);
cntxRelObj = lookup(relOid);
- if (cntxRelObj == null)
- {
- insertInternal(relOid, relObj, lock, false, isDependent, oid);
- }
- else if (cntxRelObj != relObj)
+ if (cntxRelObj != relObj)
{
- f.set(object, cntxRelObj);
+ entry = insertInternal(relOid, relObj, lock, false, isDependent, oid, stack);
+ if (entry != null)
+ {
+ f.set(object, entry.object);
+ }
}
}
}
@@ -809,14 +815,14 @@
relObj = colIterator.next();
relOid = new Identity(relObj, _pb);
cntxRelObj = lookup(relOid);
- if (cntxRelObj == null)
+ if (cntxRelObj != relObj)
{
- insertInternal(relOid, relObj, lock, false, isDependent, null);
- cntxRelObj = relObj;
- }
- else if (cntxRelObj != relObj)
- {
- needToReplaceCollection = true;
+ entry = insertInternal(relOid, relObj, lock, false, isDependent, null, stack);
+ if (entry != null)
+ {
+ cntxRelObj = entry.object;
+ needToReplaceCollection = true;
+ }
}
newCol.add(cntxRelObj);
}
@@ -1530,13 +1536,13 @@
{
Object relObj = it.next();
Identity relOid = new Identity(relObj, _pb);
- Object ctxObj;
+ ContextEntry entry;
list.add(relOid);
- ctxObj = _objects.get(relOid);
- if (ctxObj != null)
+ entry = (ContextEntry) _objects.get(relOid);
+ if (entry != null)
{
- relObj = ctxObj;
+ relObj = entry.object;
}
else
{
@@ -1550,15 +1556,19 @@
try
{
- insertInternal(relOid, relObj, _lock, false,
- _cds.getOtmDependent(), null);
+ entry = insertInternal(relOid, relObj, _lock, false,
+ _cds.getOtmDependent(), null, new Stack());
+ if (entry != null)
+ {
+ relObj = entry.object;
+ }
}
catch (LockingException ex)
{
throw new LockingPassthruException(ex);
}
}
- newCol.add(ctxObj);
+ newCol.add(relObj);
}
colProxy.clear();
colProxy.addAll(newCol);
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org