[jboss-cvs] JBossCache/src/org/jboss/cache/pojo/impl ...
Jason Thomas Greene
jgreene at jboss.com
Wed May 16 14:29:18 EDT 2007
User: jgreene
Date: 07/05/16 14:29:18
Modified: src/org/jboss/cache/pojo/impl AdvisedPojoHandler.java
InternalHelper.java ObjectGraphHandler.java
PojoCacheDelegate.java PojoCacheImpl.java
Log:
Move object refs from subnodes to fields
Revision Changes Path
1.4 +4 -5 JBossCache/src/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AdvisedPojoHandler.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- AdvisedPojoHandler.java 23 Apr 2007 02:53:22 -0000 1.3
+++ AdvisedPojoHandler.java 16 May 2007 18:29:18 -0000 1.4
@@ -36,7 +36,7 @@
*
* @author Ben Wang
* Date: Aug 4, 2005
- * @version $Id: AdvisedPojoHandler.java,v 1.3 2007/04/23 02:53:22 jgreene Exp $
+ * @version $Id: AdvisedPojoHandler.java,v 1.4 2007/05/16 18:29:18 jgreene Exp $
*/
class AdvisedPojoHandler
{
@@ -185,13 +185,12 @@
Field field = (Field) o;
Object value = subPojoMap.get(field);
if (value == null) continue; // really no need to map the POJO.
- Fqn tmpFqn = new Fqn(fqn, field.getName());
- pCache_.attach(tmpFqn, value);
+ pCache_.attach(fqn, value, field.getName());
// If it is Collection classes, we replace it with dynamic proxy.
// But we will have to ignore it if value is null
if (value instanceof Map || value instanceof List || value instanceof Set)
{
- Object newValue = pCache_.getObject(tmpFqn);
+ Object newValue = pCache_.getObject(fqn, field.getName());
util_.inMemorySubstitution(obj, field, newValue);
}
}
@@ -215,7 +214,7 @@
Object value = null;
if (!fieldType.isImmediate())
{
- value = pCache_.detach(new Fqn(fqn, field.getName()));
+ value = pCache_.detach(fqn, field.getName());
// Check for Collection. If it is, we need to reset the original reference.
if ((value instanceof Map || value instanceof List || value instanceof Set))
1.2 +33 -7 JBossCache/src/org/jboss/cache/pojo/impl/InternalHelper.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: InternalHelper.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/pojo/impl/InternalHelper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- InternalHelper.java 13 Jan 2007 15:55:06 -0000 1.1
+++ InternalHelper.java 16 May 2007 18:29:18 -0000 1.2
@@ -72,11 +72,19 @@
return (PojoInstance) get(fqn, PojoInstance.KEY, false);
}
- PojoReference getPojoReference(Fqn fqn) throws CacheException
+ PojoReference getPojoReference(Fqn fqn, String field) throws CacheException
{
// Not very efficient now since we are peeking every single time.
// Should have cache it without going to local cache.
- return (PojoReference) get(fqn, PojoReference.KEY, false);
+ if (field == null)
+ field = PojoReference.KEY;
+
+ return (PojoReference) get(fqn, field, false);
+ }
+
+ PojoReference getPojoReference(Fqn fqn) throws CacheException
+ {
+ return getPojoReference(fqn, null);
}
PojoReference getPojoReferenceWithGravitation(Fqn fqn) throws CacheException
@@ -246,9 +254,9 @@
put(fqn, PojoInstance.KEY, pojoInstance);
}
- Object getPojo(Fqn fqn) throws CacheException
+ Object getPojo(Fqn fqn, String field) throws CacheException
{
- PojoReference pojoReference = getPojoReference(fqn);
+ PojoReference pojoReference = getPojoReference(fqn, field);
Fqn realFqn = null;
if (pojoReference != null)
{
@@ -257,6 +265,10 @@
}
else
{
+ // If we are looking for a field then there must be a reference
+ if (field != null)
+ return null;
+
// This is the internal node.
realFqn = fqn;
}
@@ -322,7 +334,15 @@
void putPojoReference(Fqn fqn, PojoReference pojoReference) throws CacheException
{
- put(fqn, PojoReference.KEY, pojoReference);
+ putPojoReference(fqn, pojoReference, PojoReference.KEY);
+ }
+
+ void putPojoReference(Fqn fqn, PojoReference pojoReference, String field) throws CacheException
+ {
+ if (field == null)
+ field = PojoReference.KEY;
+
+ put(fqn, field, pojoReference);
}
void putAopClazz(Fqn fqn, Class clazz) throws CacheException
@@ -350,10 +370,16 @@
cache_.remove(fqn, InternalConstant.CLASS_INTERNAL);
}
- void cleanUp(Fqn fqn) throws CacheException
+ void cleanUp(Fqn fqn, String field) throws CacheException
{
+ if (field != null)
+ {
+ cache_.remove(fqn, field);
+ return;
+ }
+
// We can't do a brute force remove anymore?
- if (cache_.getRoot().getChild(fqn).getChildren() != null)
+ if (cache_.getRoot().getChild(fqn).getChildren().size() == 0)
{
// remove everything
cache_.removeNode(fqn);
1.3 +3 -3 JBossCache/src/org/jboss/cache/pojo/impl/ObjectGraphHandler.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ObjectGraphHandler.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/pojo/impl/ObjectGraphHandler.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- ObjectGraphHandler.java 25 Jan 2007 21:54:05 -0000 1.2
+++ ObjectGraphHandler.java 16 May 2007 18:29:18 -0000 1.3
@@ -31,7 +31,7 @@
*
* @author Ben Wang
* Date: Aug 4, 2005
- * @version $Id: ObjectGraphHandler.java,v 1.2 2007/01/25 21:54:05 genman Exp $
+ * @version $Id: ObjectGraphHandler.java,v 1.3 2007/05/16 18:29:18 jgreene Exp $
*/
class ObjectGraphHandler
{
@@ -60,7 +60,7 @@
return obj; // No need to set the instance under fqn. It is located in refFqn anyway.
}
- void put(Fqn fqn, Object obj) throws CacheException
+ void put(Fqn fqn, Object obj, String field) throws CacheException
{
CachedType type = pCache_.getCachedType(obj.getClass());
@@ -93,7 +93,7 @@
PojoReference pojoReference = new PojoReference();
pojoReference.setFqn(originalFqn);
pojoReference.setPojoClass(type.getType());
- internal_.putPojoReference(fqn, pojoReference);
+ internal_.putPojoReference(fqn, pojoReference, field);
}
boolean isMultipleReferenced(Fqn internalFqn)
1.6 +47 -44 JBossCache/src/org/jboss/cache/pojo/impl/PojoCacheDelegate.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PojoCacheDelegate.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/pojo/impl/PojoCacheDelegate.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- PojoCacheDelegate.java 26 Apr 2007 15:23:27 -0000 1.5
+++ PojoCacheDelegate.java 16 May 2007 18:29:18 -0000 1.6
@@ -79,10 +79,10 @@
return bulkRemove_.get();
}
- public Object getObject(Fqn fqn) throws CacheException
+ public Object getObject(Fqn fqn, String field) throws CacheException
{
// TODO Must we really to couple with BR? JBCACHE-669
- Object pojo = internal_.getPojo(fqn);
+ Object pojo = internal_.getPojo(fqn, field);
if (pojo != null)
{
// we already have an advised instance
@@ -103,7 +103,7 @@
{
cache_.getRegionManager().setContextClassLoaderAsCurrent(fqn);
}
- return getObjectInternal(fqn);
+ return getObjectInternal(fqn, field);
}
finally
{
@@ -111,10 +111,10 @@
}
}
- public Object putObjectI(Fqn fqn, Object obj) throws CacheException
+ public Object putObjectI(Fqn fqn, Object obj, String field) throws CacheException
{
// Skip some un-necessary update if obj is the same class as the old one
- Object oldValue = internal_.getPojo(fqn);
+ Object oldValue = internal_.getPojo(fqn, field);
if (oldValue == obj && (obj instanceof Advised || obj instanceof ClassProxy))
{
if (log.isDebugEnabled())
@@ -129,10 +129,10 @@
/**
* Note that caller of this method will take care of synchronization within the <code>fqn</code> sub-tree.
*/
- public Object putObjectII(Fqn fqn, Object obj) throws CacheException
+ public Object putObjectII(Fqn fqn, Object obj, String field) throws CacheException
{
// Skip some un-necessary update if obj is the same class as the old one
- Object oldValue = internal_.getPojo(fqn);
+ Object oldValue = internal_.getPojo(fqn, field);
if (oldValue == obj)
{
if (log.isDebugEnabled())
@@ -144,32 +144,32 @@
// remove old value before overwriting it. This is necessary to detach any interceptor.
// TODO Or can we simply walk thru that somewhere? Well, there is also implication of Collection though
- pCache_.detach(fqn);
+ pCache_.detach(fqn, field);
if (obj == null)
{
return oldValue;// we are done
}
- // This create a PojoReference to store a pointer to the real fqn.
- Fqn internalFqn = createInternalFqn(fqn, obj);
- setPojoReference(fqn, obj, internalFqn);
// creates the internal node first without going thru the interceptor.
// This way we don't block on __JBossInternal__ node.
//createChildNodeFirstWithoutLocking(internalFqn);
+ if ((obj instanceof Advised || obj instanceof ClassProxy) && isMultipleReferencedPut(obj))
+ {
+ // we pass in the originating fqn intentionaly
+ graphHandler_.put(fqn, obj, field);
+ }
+ else
+ {
+ Fqn internalFqn = createInternalFqn(fqn, obj);
if (log.isDebugEnabled())
{
log.debug("putObject(): id: " + fqn + " will store the pojo in the internal area: "
+ internalFqn);
}
- if ((obj instanceof Advised || obj instanceof ClassProxy) && isMultipleReferencedPut(obj))
- {
- // we pass in the originating fqn intentionaly
- graphHandler_.put(fqn, obj);
- }
- else if (obj instanceof Advised)
+ if (obj instanceof Advised)
{
advisedHandler_.put(internalFqn, fqn, obj);
}
@@ -184,6 +184,9 @@
serializableHandler_.put(internalFqn, obj);
}
+ setPojoReference(fqn, obj, field, internalFqn);
+ }
+
return oldValue;
}
@@ -193,7 +196,7 @@
return AopUtil.createInternalFqn(fqn, cache_);
}
- Fqn setPojoReference(Fqn fqn, Object obj, Fqn internalFqn) throws CacheException
+ Fqn setPojoReference(Fqn fqn, Object obj, String field, Fqn internalFqn) throws CacheException
{
// Create PojoReference
CachedType type = pCache_.getCachedType(obj.getClass());
@@ -202,7 +205,7 @@
// store PojoReference
pojoReference.setFqn(internalFqn);
- internal_.putPojoReference(fqn, pojoReference);
+ internal_.putPojoReference(fqn, pojoReference, field);
if (log.isDebugEnabled())
{
log.debug("put(): inserting PojoReference with id: " + fqn);
@@ -233,10 +236,10 @@
* @return
* @throws CacheException
*/
- public Object removeObject(Fqn fqn) throws CacheException
+ public Object removeObject(Fqn fqn, String field) throws CacheException
{
// the class attribute is implicitly stored as an immutable read-only attribute
- PojoReference pojoReference = internal_.getPojoReference(fqn);
+ PojoReference pojoReference = internal_.getPojoReference(fqn, field);
if (pojoReference == null)
{
// clazz and pojoReference can be not null if this node is the replicated brother node.
@@ -269,21 +272,21 @@
else if (Advised.class.isAssignableFrom(clazz))
{
advisedHandler_.remove(internalFqn, result, clazz);
- internal_.cleanUp(internalFqn);
+ internal_.cleanUp(internalFqn, null);
}
else if (isCollectionGet(clazz))
{
// We need to return the original reference
result = collectionHandler_.remove(internalFqn, result);
- internal_.cleanUp(internalFqn);
+ internal_.cleanUp(internalFqn, null);
}
else
{// Just Serializable objects. Do a brute force remove is ok.
serializableHandler_.remove();
- internal_.cleanUp(internalFqn);
+ internal_.cleanUp(internalFqn, null);
}
- internal_.cleanUp(fqn);
+ internal_.cleanUp(fqn, field);
// remove the interceptor as well.
return result;
}
@@ -293,7 +296,7 @@
// Traverse from fqn to do getObject, if it return a pojo we then stop.
Map map = new HashMap();
- Object pojo = getObject(fqn);
+ Object pojo = getObject(fqn, null);
if (pojo != null)
{
map.put(fqn, pojo);// we are done!
@@ -308,10 +311,10 @@
return map;
}
- private Object getObjectInternal(Fqn fqn) throws CacheException
+ private Object getObjectInternal(Fqn fqn, String field) throws CacheException
{
// the class attribute is implicitly stored as an immutable read-only attribute
- PojoReference pojoReference = internal_.getPojoReference(fqn);
+ PojoReference pojoReference = internal_.getPojoReference(fqn, field);
if (pojoReference == null)
{
// clazz and pojoReference can be not null if this node is the replicated brother node.
@@ -542,7 +545,7 @@
// Need to do a getObject just in case this is a failover removeObject.
if (value == null)
{
- value = getObject(new Fqn(interceptor.getFqn(), field.getName()));
+ value = getObject(new Fqn(interceptor.getFqn(), field.getName()), null);
}
if (value == null) continue;// this is no brainer.
@@ -611,7 +614,7 @@
Fqn newFqn = n.getFqn();
if (InternalHelper.isInternalNode(newFqn)) continue;// skip
- Object pojo = getObject(newFqn);
+ Object pojo = getObject(newFqn, null);
if (pojo != null)
{
map.put(newFqn, pojo);
1.7 +37 -13 JBossCache/src/org/jboss/cache/pojo/impl/PojoCacheImpl.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PojoCacheImpl.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/pojo/impl/PojoCacheImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- PojoCacheImpl.java 23 Apr 2007 02:53:22 -0000 1.6
+++ PojoCacheImpl.java 16 May 2007 18:29:18 -0000 1.7
@@ -43,7 +43,7 @@
* Implementation class for PojoCache interface
*
* @author Ben Wang
- * @version $Id: PojoCacheImpl.java,v 1.6 2007/04/23 02:53:22 jgreene Exp $
+ * @version $Id: PojoCacheImpl.java,v 1.7 2007/05/16 18:29:18 jgreene Exp $
*/
public class PojoCacheImpl implements PojoCache
{
@@ -118,7 +118,21 @@
{
try
{
- Object obj = putObject(id, pojo);
+ Object obj = putObject(id, pojo, null);
+ return obj;
+ }
+ catch (CacheException e)
+ {
+ throw new PojoCacheException("putObject failed " + id, e);
+ }
+ }
+
+ @Attach
+ public Object attach(Fqn id, Object pojo, String field) throws PojoCacheException
+ {
+ try
+ {
+ Object obj = putObject(id, pojo, field);
return obj;
}
catch (CacheException e)
@@ -130,17 +144,17 @@
/**
* This public API is called from internal package only.
*/
- public Object putObject(Fqn id, Object pojo)
+ public Object putObject(Fqn id, Object pojo, String field)
throws CacheException
{
Object obj = null;
// Maybe this is the same instance already.
- obj = delegate_.putObjectI(id, pojo);
+ obj = delegate_.putObjectI(id, pojo, field);
if (obj != null) return obj;
notifyAttach(pojo, true);
- obj = delegate_.putObjectII(id, pojo);
+ obj = delegate_.putObjectII(id, pojo, field);
notifyAttach(pojo, false);
return obj;
}
@@ -151,15 +165,15 @@
}
@Detach
- public Object detach(Fqn id) throws PojoCacheException
+ public Object detach(Fqn id, String field) throws PojoCacheException
{
try
{
- Object pojo = find(id);// TODO need optimization here since it will be redundant here
+ Object pojo = getObject(id, field);// TODO need optimization here since it will be redundant here
if (pojo == null) return pojo;
notifyDetach(pojo, true);
- Object obj = removeObject(id);
+ Object obj = removeObject(id, field);
notifyDetach(pojo, false);
return obj;
}
@@ -169,10 +183,15 @@
}
}
- public Object removeObject(Fqn id) throws CacheException
+ public Object detach(Fqn id) throws PojoCacheException
+ {
+ return detach(id, null);
+ }
+
+ public Object removeObject(Fqn id, String field) throws CacheException
{
delegate_.setBulkRemove(false);
- return delegate_.removeObject(id);
+ return delegate_.removeObject(id, field);
}
public String getPojoID(Object pojo)
@@ -198,12 +217,17 @@
}
}
- public Object getObject(Fqn id)
- throws CacheException
+ public Object getObject(Fqn id) throws CacheException
{
- return delegate_.getObject(id);
+ return getObject(id, null);
}
+ public Object getObject(Fqn id, String field) throws CacheException
+ {
+ return delegate_.getObject(id, field);
+ }
+
+
public Map findAll(String id) throws PojoCacheException
{
return findAll(Fqn.fromString(id));
More information about the jboss-cvs-commits
mailing list