[jboss-cvs] JBossCache/src-50/org/jboss/cache/pojo ...
Ben Wang
bwang at jboss.com
Sun Jul 30 22:44:42 EDT 2006
User: bwang
Date: 06/07/30 22:44:42
Modified: src-50/org/jboss/cache/pojo MethodDeclarations.java
PojoCache.java PojoUtil.java
Log:
JBCACHE-686 Colelction handles undo properly.
Revision Changes Path
1.3 +10 -3 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.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- MethodDeclarations.java 8 Jul 2006 17:41:16 -0000 1.2
+++ MethodDeclarations.java 31 Jul 2006 02:44:42 -0000 1.3
@@ -12,19 +12,22 @@
import org.jboss.cache.pojo.observable.Observer;
import java.lang.reflect.Method;
+import java.lang.reflect.Field;
/**
- * Method declarations for undo method mostly.
+ * Method declarations for rollback method mostly.
*
* @author Ben Wang
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class MethodDeclarations
{
public static final Method attachInterceptor;
public static final Method detachInterceptor;
public static final Method undoAttachInterceptor;
- public static final Method undoDetachInterceptor;
+ public static final Method undoDetachInterceptor;;
+ public static final Method fieldReplaceNewValue;;
+ public static final Method undoFieldReplaceNewValue;;
static
{
@@ -38,6 +41,10 @@
new Class[] {Object.class, InstanceAdvisor.class, Interceptor.class, Observer.class});
undoDetachInterceptor = PojoUtil.class.getDeclaredMethod("undoDetachInterceptor",
new Class[] {InstanceAdvisor.class, Interceptor.class, Observer.class});
+ fieldReplaceNewValue = PojoUtil.class.getDeclaredMethod("fieldReplaceNewValue",
+ new Class[] {Object.class, Field.class, Object.class});
+ undoFieldReplaceNewValue = PojoUtil.class.getDeclaredMethod("undoFieldReplaceNewValue",
+ new Class[] {Object.class, Field.class, Object.class});
}
catch (NoSuchMethodException ex)
{
1.3 +2 -1 JBossCache/src-50/org/jboss/cache/pojo/PojoCache.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PojoCache.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/PojoCache.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- PojoCache.java 27 Jun 2006 05:25:43 -0000 1.2
+++ PojoCache.java 31 Jul 2006 02:44:42 -0000 1.3
@@ -40,7 +40,8 @@
*
* @param id An id String to identify the object in the cache. To promote concurrency, we
* recommend the use of hierarchical String separating by a designated separator. Default
- * is "/" but it can be set differently via a System property, jbosscache.separator.
+ * is "/" but it can be set differently via a System property, jbosscache.separator
+ * in the future release. E.g., "ben", or "student/joe", etc.
* @param pojo object to be inerted into the cache. If null, it will nullify the fqn node.
* @return Existing POJO or null if there is none.
* @throws PojoCacheException Throws if there is an error related to the cache operation.
1.8 +22 -36 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.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- PojoUtil.java 14 Jul 2006 16:35:49 -0000 1.7
+++ PojoUtil.java 31 Jul 2006 02:44:42 -0000 1.8
@@ -9,19 +9,17 @@
import org.jboss.aop.InstanceAdvisor;
import org.jboss.aop.advice.Interceptor;
-import org.jboss.cache.CacheException;
import org.jboss.cache.pojo.annotation.TxUndo;
import org.jboss.cache.pojo.observable.Observer;
import org.jboss.cache.pojo.observable.Subject;
-import org.jboss.cache.pojo.observable.SubjectInterceptor;
import org.jboss.cache.pojo.interceptors.dynamic.CacheFieldInterceptor;
import java.lang.reflect.Field;
/**
- * Utility class for method wrappers that we are interested to rollback (i.e., undo).
+ * Utility class for method wrappers that we are interested to rollback (i.e., rollback).
* @author Ben Wang
- * @version $Id: PojoUtil.java,v 1.7 2006/07/14 16:35:49 bwang Exp $
+ * @version $Id: PojoUtil.java,v 1.8 2006/07/31 02:44:42 bwang Exp $
*/
public class PojoUtil
{
@@ -55,22 +53,15 @@
_attachInterceptor(pojo, advisor, interceptor, observer);
}
-
- public void collectionReplaceWithProxy(Object obj, Field field, Object newValue)
- {
- // If value (field member) is of Collection type, e.g., composite class
- // that contains Collection member, we will swap out the old reference
- // with the proxy one.
- // This can probably be optimized with check for instanceof proxy
- try
- {
- field.set(obj, newValue);
- } catch (IllegalAccessException e)
+ @TxUndo
+ public void fieldReplaceNewValue(Object obj, Field field, Object newValue)
{
- throw new PojoCacheException(
- "PojoUtil.collectionReplaceWithProxy(): Can't swap out the Collection class of field \" " +
- "+field.getName()," + e);
+ _fieldReplaceNewValue(obj, field, newValue);
}
+
+ public void undoFieldReplaceNewValue(Object obj, Field field, Object oldValue)
+ {
+ _fieldReplaceNewValue(obj, field, oldValue);
}
private void _attachInterceptor(Object pojo, InstanceAdvisor advisor, Interceptor interceptor,
@@ -80,15 +71,25 @@
((Subject)pojo).addObserver(observer);
// Note that subject interceptor should come before the cache interceptor.
-// SubjectInterceptor si = new SubjectInterceptor();
-// advisor.appendInterceptor(si);
advisor.appendInterceptor(interceptor);
}
+ private void _fieldReplaceNewValue(Object obj, Field field, Object newValue)
+ {
+ try
+ {
+ field.set(obj, newValue);
+ } catch (IllegalAccessException e)
+ {
+ throw new PojoCacheException(
+ "PojoUtil.fieldReplaceNewValue(): Can't swap out the class of field \" " +
+ "+field.getName()," + e);
+ }
+ }
+
private void _detachInterceptor(InstanceAdvisor advisor, Interceptor interceptor, Observer observer)
{
advisor.removeInterceptor(interceptor.getName());
-// removeSubjectInterceptor(advisor);
// retrieve pojo
Object pojo = ((CacheFieldInterceptor)interceptor).getAopInstance().get();
@@ -99,19 +100,4 @@
((Subject)pojo).removeObserver(observer);
}
-
- private void removeSubjectInterceptor(InstanceAdvisor advisor)
- {
- Interceptor[] interceptors = advisor.getInterceptors();
- // Step Check for cross references
- for (int i = 0; i < interceptors.length; i++)
- {
- Interceptor interceptor = interceptors[i];
- if (interceptor instanceof SubjectInterceptor)
- {
- advisor.removeInterceptor(interceptor.getName());
- return; // assume there is only one.
- }
- }
- }
}
More information about the jboss-cvs-commits
mailing list