[jboss-cvs] JBossCache/src-50/org/jboss/cache/pojo ...
Ben Wang
bwang at jboss.com
Tue Oct 10 06:49:54 EDT 2006
User: bwang
Date: 06/10/10 06:49:54
Modified: src-50/org/jboss/cache/pojo MethodDeclarations.java
PojoUtil.java PojoInstance.java
Log:
First cut for JBCACHE-763 transaction rollback problem for collection.
Revision Changes Path
1.5 +15 -1 JBossCache/src-50/org/jboss/cache/pojo/MethodDeclarations.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MethodDeclarations.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/MethodDeclarations.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- MethodDeclarations.java 17 Sep 2006 05:55:04 -0000 1.4
+++ MethodDeclarations.java 10 Oct 2006 10:49:54 -0000 1.5
@@ -10,15 +10,17 @@
import org.jboss.aop.InstanceAdvisor;
import org.jboss.aop.advice.Interceptor;
import org.jboss.cache.pojo.observable.Observer;
+import org.jboss.cache.Fqn;
import java.lang.reflect.Method;
import java.lang.reflect.Field;
+import java.util.List;
/**
* Method declarations for rollback method mostly.
*
* @author Ben Wang
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
public class MethodDeclarations
{
@@ -28,6 +30,10 @@
public static final Method undoDetachInterceptor;;
public static final Method inMemorySubstitution;;
public static final Method undoInMemorySubstitution;;
+ public static final Method incrementReferenceCount;
+ public static final Method decrementReferenceCount;
+ public static final Method undoIncrementReferenceCount;
+ public static final Method undoDecrementReferenceCount;
static
{
@@ -45,6 +51,14 @@
new Class[] {Object.class, Field.class, Object.class});
undoInMemorySubstitution = PojoUtil.class.getDeclaredMethod("undoInMemorySubstitution",
new Class[] {Object.class, Field.class, Object.class});
+ incrementReferenceCount = PojoUtil.class.getDeclaredMethod("incrementReferenceCount",
+ new Class[] {Fqn.class, int.class, List.class});
+ decrementReferenceCount = PojoUtil.class.getDeclaredMethod("decrementReferenceCount",
+ new Class[] {Fqn.class, int.class, List.class});
+ undoIncrementReferenceCount = PojoUtil.class.getDeclaredMethod("undoIncrementReferenceCount",
+ new Class[] {Fqn.class, int.class, List.class});
+ undoDecrementReferenceCount = PojoUtil.class.getDeclaredMethod("undoDecrementReferenceCount",
+ new Class[] {Fqn.class, int.class, List.class});
}
catch (NoSuchMethodException ex)
{
1.12 +37 -1 JBossCache/src-50/org/jboss/cache/pojo/PojoUtil.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PojoUtil.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/PojoUtil.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- PojoUtil.java 17 Sep 2006 05:55:04 -0000 1.11
+++ PojoUtil.java 10 Oct 2006 10:49:54 -0000 1.12
@@ -18,13 +18,15 @@
import org.jboss.cache.pojo.observable.Subject;
import org.jboss.cache.pojo.interceptors.dynamic.CacheFieldInterceptor;
import org.jboss.cache.pojo.interceptors.dynamic.ReentrancyStopperInterceptor;
+import org.jboss.cache.Fqn;
import java.lang.reflect.Field;
+import java.util.List;
/**
* Utility class for method wrappers that we are interested to rollback (i.e., rollback).
* @author Ben Wang
- * @version $Id: PojoUtil.java,v 1.11 2006/09/17 05:55:04 bwang Exp $
+ * @version $Id: PojoUtil.java,v 1.12 2006/10/10 10:49:54 bwang Exp $
*/
public class PojoUtil
{
@@ -157,4 +159,38 @@
}
}
}
+
+ @TxUndo
+ public int incrementReferenceCount(Fqn sourceFqn, int count, List refList)
+ {
+ return _incrementReferenceCount(sourceFqn, count, refList);
+ }
+
+ public int undoIncrementReferenceCount(Fqn sourceFqn, int count, List refList)
+ {
+ return _decrementReferenceCount(sourceFqn, count, refList);
+ }
+
+ private int _incrementReferenceCount(Fqn sourceFqn, int count, List refList)
+ {
+ refList.add(sourceFqn);
+ return count++;
+ }
+
+ @TxUndo
+ public int decrementReferenceCount(Fqn sourceFqn, int count, List refList)
+ {
+ return _decrementReferenceCount(sourceFqn, count, refList);
+ }
+
+ public int undoDecrementReferenceCount(Fqn sourceFqn, int count, List refList)
+ {
+ return _incrementReferenceCount(sourceFqn, count, refList);
+ }
+
+ private int _decrementReferenceCount(Fqn sourceFqn, int count, List refList)
+ {
+ refList.remove(sourceFqn);
+ return count--;
+ }
}
1.2 +26 -18 JBossCache/src-50/org/jboss/cache/pojo/PojoInstance.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PojoInstance.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/PojoInstance.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- PojoInstance.java 17 Jul 2006 09:07:08 -0000 1.1
+++ PojoInstance.java 10 Oct 2006 10:49:54 -0000 1.2
@@ -44,6 +44,7 @@
// List of fqns that reference this fqn. Assume list size is not big since it may not be efficient.
private List referencedBy_ = null;
private Class clazz_ = null;
+ private PojoUtil util_ = new PojoUtil();
public PojoInstance()
{
@@ -91,8 +92,11 @@
synchronized public int incrementRefCount(Fqn sourceFqn)
{
- if(sourceFqn != null)
+ if(sourceFqn == null)
{
+ throw new IllegalStateException("PojoInstance.incrementRefCount(): null sourceFqn");
+ }
+
if (referencedBy_ == null)
{
referencedBy_ = new ArrayList();
@@ -102,25 +106,29 @@
throw new IllegalStateException("PojoReference.incrementRefCount(): source fqn: " +
sourceFqn + " is already present.");
- referencedBy_.add(sourceFqn);
- }
- refCount_ += 1;
+ refCount_ = util_.incrementReferenceCount(sourceFqn, refCount_, referencedBy_);
+// referencedBy_.add(sourceFqn);
+
+// refCount_ += 1;
//logger_.info("incrementRefCount(): current ref count " +refCount_);
return refCount_;
}
synchronized public int decrementRefCount(Fqn sourceFqn)
{
- if(sourceFqn != null)
+ if(sourceFqn == null)
{
+ throw new IllegalStateException("PojoInstance.incrementRefCount(): null sourceFqn");
+ }
+
if (!referencedBy_.contains(sourceFqn))
throw new IllegalStateException("PojoReference.decrementRefCount(): source fqn: " +
sourceFqn + " is not present.");
- referencedBy_.remove(sourceFqn);
- }
+ refCount_ = util_.decrementReferenceCount(sourceFqn, refCount_, referencedBy_);
+// referencedBy_.remove(sourceFqn);
- refCount_ -= 1;
+// refCount_ -= 1;
//logger_.info("decrementRefCount(): current ref count " +refCount_);
return refCount_;
}
More information about the jboss-cvs-commits
mailing list