[jboss-cvs] JBossCache/src/org/jboss/cache/aop ...
Ben Wang
bwang at jboss.com
Thu Aug 10 12:13:02 EDT 2006
User: bwang
Date: 06/08/10 12:13:02
Modified: src/org/jboss/cache/aop Tag: JBossCache_1_4_JDOM
CacheInterceptor.java CachedType.java
TreeCacheAopDelegate.java
Log:
JBCACHE-733
Revision Changes Path
No revision
No revision
1.19.2.1.2.1 +4 -12 JBossCache/src/org/jboss/cache/aop/CacheInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/aop/CacheInterceptor.java,v
retrieving revision 1.19.2.1
retrieving revision 1.19.2.1.2.1
diff -u -b -r1.19.2.1 -r1.19.2.1.2.1
--- CacheInterceptor.java 28 Jun 2006 20:18:29 -0000 1.19.2.1
+++ CacheInterceptor.java 10 Aug 2006 16:13:02 -0000 1.19.2.1.2.1
@@ -18,7 +18,6 @@
import org.jboss.aop.Advisor;
import org.jboss.cache.Fqn;
import org.jboss.cache.aop.util.AopUtil;
-import org.jboss.cache.aop.references.FieldPersistentReference;
import java.io.Externalizable;
import java.io.ObjectInput;
@@ -106,7 +105,7 @@
// Only if this field is replicatable. static, transient and final are not.
CachedType fieldType = cache.getCachedType(field.getType());
CachedType parentType = cache.getCachedType(field.getDeclaringClass());
- if(!isNonReplicatable(field, advisor, parentType)) {
+ if(!isNonReplicatable(fieldInvocation)) {
Object value = ((FieldWriteInvocation)fieldInvocation).getValue();
if (fieldType.isImmediate() || hasSerializableAnnotation(field, advisor, parentType)) {
cache.put(fqn, field.getName(), value);
@@ -125,7 +124,7 @@
// Only if this field is replicatable
CachedType fieldType = cache.getCachedType(field.getType());
CachedType parentType = cache.getCachedType(field.getDeclaringClass());
- if( !isNonReplicatable(field, advisor, parentType)) {
+ if( !isNonReplicatable(fieldInvocation)) {
Object result;
if (fieldType.isImmediate()|| hasSerializableAnnotation(field, advisor, parentType)) {
result = cache.get(fqn, field.getName());
@@ -176,16 +175,9 @@
/**
* See if this field is non-replicatable such as @Transient or transient modifier.
*/
- private boolean isNonReplicatable(Field field, Advisor advisor, CachedType type)
+ private boolean isNonReplicatable(FieldInvocation fieldInvocation)
{
- if(CachedType.hasAnnotation(field.getDeclaringClass(), advisor, type))
- {
- if(CachedType.hasTransientAnnotation(field, advisor)) return true;
- }
-
- if(CachedType.isPrimitiveNonReplicatable(field)) return true;
-
- return false;
+ return CachedType.isNonReplicatable(fieldInvocation);
}
private boolean hasSerializableAnnotation(Field field, Advisor advisor, CachedType type)
1.9.2.1.2.1 +79 -27 JBossCache/src/org/jboss/cache/aop/CachedType.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CachedType.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/aop/CachedType.java,v
retrieving revision 1.9.2.1
retrieving revision 1.9.2.1.2.1
diff -u -b -r1.9.2.1 -r1.9.2.1.2.1
--- CachedType.java 28 Jun 2006 20:18:29 -0000 1.9.2.1
+++ CachedType.java 10 Aug 2006 16:13:02 -0000 1.9.2.1.2.1
@@ -4,6 +4,9 @@
import org.jboss.aop.Advisor;
import org.jboss.cache.aop.references.FieldPersistentReference;
import org.jboss.cache.aop.references.PersistentReference;
+import org.jboss.cache.aop.annotation.Transient;
+import org.jboss.cache.aop.annotation.Serializable;
+import org.jboss.cache.aop.annotation.NonTransient;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@@ -93,7 +96,7 @@
* A <code>List<Field></code> of all of this type's replicatable
* fields.
*
- * @see #isPrimitiveNonReplicatable(Field)
+ * @see #isStaticOrFinalField(Field)
*/
public List getFields()
{
@@ -232,7 +235,7 @@
Field[] classFields = clazz.getDeclaredFields();
for (int i = 0; i < classFields.length; i++) {
Field f = classFields[i];
- if(isPrimitiveNonReplicatable(f)) continue;
+ if(isStaticOrFinalField(f)) continue;
f.setAccessible(true);
@@ -280,20 +283,32 @@
return false;
}
- protected static boolean isPrimitiveNonReplicatable(Field f) {
+ protected static boolean isStaticOrFinalField(Field f) {
int mods = f.getModifiers();
/**
* The following modifiers are ignored in the cache, i.e., they will not be stored in the cache.
* Whenever, user trying to access these fields, it will be accessed from the in-memory version.
*/
if (Modifier.isStatic(mods)
- || Modifier.isTransient(mods)
+// || Modifier.isTransient(mods)
|| Modifier.isFinal(mods)) {
return true;
}
return false;
}
+ protected static boolean isTransientField(Field f) {
+ int mods = f.getModifiers();
+ /**
+ * The following modifiers are ignored in the cache, i.e., they will not be stored in the cache.
+ * Whenever, user trying to access these fields, it will be accessed from the in-memory version.
+ */
+ if (Modifier.isTransient(mods)) {
+ return true;
+ }
+ return false;
+ }
+
/**
* Check if we have @Transient annotation.
@@ -302,7 +317,22 @@
*/
protected static boolean hasTransientAnnotation(FieldInvocation invocation)
{
- Object obj = invocation.resolveAnnotation(org.jboss.cache.aop.annotation.Transient.class);
+ Object obj = invocation.resolveAnnotation(Transient.class);
+ if(obj != null)
+ {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Check if we have @NonTransient annotation.
+ * @param invocation
+ * @return true if @NonTransient is present.
+ */
+ protected static boolean hasNonTransientAnnotation(FieldInvocation invocation)
+ {
+ Object obj = invocation.resolveAnnotation(NonTransient.class);
if(obj != null)
{
return true;
@@ -312,12 +342,23 @@
protected static boolean hasFieldAnnotation(Field field, Advisor advisor)
{
- return hasTransientAnnotation(field, advisor) || hasSerializableAnnotation(field, advisor);
+ return hasTransientAnnotation(field, advisor) || hasSerializableAnnotation(field, advisor)
+ || hasNonTransientAnnotation(field, advisor);
}
protected static boolean hasTransientAnnotation(Field field, Advisor advisor)
{
- Object obj = advisor.resolveAnnotation(field, org.jboss.cache.aop.annotation.Transient.class);
+ Object obj = advisor.resolveAnnotation(field, Transient.class);
+ if(obj != null)
+ {
+ return true;
+ }
+ return false;
+ }
+
+ protected static boolean hasNonTransientAnnotation(Field field, Advisor advisor)
+ {
+ Object obj = advisor.resolveAnnotation(field, NonTransient.class);
if(obj != null)
{
return true;
@@ -327,7 +368,7 @@
public static boolean hasSerializableAnnotation(Field field, Advisor advisor)
{
- Object obj = advisor.resolveAnnotation(field, org.jboss.cache.aop.annotation.Serializable.class);
+ Object obj = advisor.resolveAnnotation(field, Serializable.class);
if(obj != null)
{
return true;
@@ -337,7 +378,7 @@
public static boolean hasSerializableAnnotation(FieldInvocation invocation)
{
- Object obj = invocation.resolveAnnotation(org.jboss.cache.aop.annotation.Serializable.class);
+ Object obj = invocation.resolveAnnotation(Serializable.class);
if(obj != null)
{
return true;
@@ -347,7 +388,18 @@
public static boolean isNonReplicatable(FieldInvocation fieldInvocation)
{
- return hasTransientAnnotation(fieldInvocation) || isPrimitiveNonReplicatable(fieldInvocation.getField());
+ return hasTransientAnnotation(fieldInvocation)
+ || isStaticOrFinalField(fieldInvocation.getField())
+ || (isTransientField(fieldInvocation.getField()) &&
+ !hasNonTransientAnnotation(fieldInvocation));
+ }
+
+ public static boolean isNonReplicatable(Field field, Advisor advisor)
+ {
+ return hasTransientAnnotation(field, advisor)
+ || isStaticOrFinalField(field)
+ || (isTransientField(field) &&
+ !hasNonTransientAnnotation(field, advisor));
}
@@ -393,7 +445,7 @@
* that
*
* @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
- * @version $Id: CachedType.java,v 1.9.2.1 2006/06/28 20:18:29 bstansberry Exp $
+ * @version $Id: CachedType.java,v 1.9.2.1.2.1 2006/08/10 16:13:02 bwang Exp $
*/
private class FieldsIterator implements Iterator
{
1.74.2.4.2.1 +2 -3 JBossCache/src/org/jboss/cache/aop/TreeCacheAopDelegate.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TreeCacheAopDelegate.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/aop/TreeCacheAopDelegate.java,v
retrieving revision 1.74.2.4
retrieving revision 1.74.2.4.2.1
diff -u -b -r1.74.2.4 -r1.74.2.4.2.1
--- TreeCacheAopDelegate.java 7 Aug 2006 02:41:22 -0000 1.74.2.4
+++ TreeCacheAopDelegate.java 10 Aug 2006 16:13:02 -0000 1.74.2.4.2.1
@@ -17,7 +17,6 @@
import org.jboss.cache.aop.util.AopUtil;
import org.jboss.cache.aop.util.SecurityActions;
import org.jboss.cache.aop.collection.AbstractCollectionInterceptor;
-import org.jboss.cache.aop.references.FieldPersistentReference;
import org.jboss.cache.Fqn;
import org.jboss.cache.CacheException;
import org.jboss.cache.GlobalTransaction;
@@ -329,7 +328,7 @@
}
// check for non-replicatable types
- if(CachedType.isPrimitiveNonReplicatable(field))
+ if(CachedType.isNonReplicatable(field, ((Advised)obj)._getAdvisor()))
{
continue;
}
@@ -437,7 +436,7 @@
}
// check for non-replicatable types
- if(CachedType.isPrimitiveNonReplicatable(field))
+ if(CachedType.isNonReplicatable(field, ((Advised)obj)._getAdvisor()))
{
continue;
}
More information about the jboss-cvs-commits
mailing list