[jboss-cvs] JBossCache/src/org/jboss/cache ...
Elias Ross
genman at noderunner.net
Mon Nov 20 07:04:43 EST 2006
User: genman
Date: 06/11/20 07:04:43
Modified: src/org/jboss/cache NodeImpl.java TreeCache.java
Log:
JBCACHE-867 - Fix put(Map) not calling through cache
Revision Changes Path
1.16 +23 -12 JBossCache/src/org/jboss/cache/NodeImpl.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: NodeImpl.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/NodeImpl.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- NodeImpl.java 20 Nov 2006 03:53:54 -0000 1.15
+++ NodeImpl.java 20 Nov 2006 12:04:43 -0000 1.16
@@ -266,7 +266,13 @@
return data != null ? data.size() : 0;
}
- public synchronized void put(Map data, boolean erase)
+ public void put(Map data, boolean erase)
+ {
+ if (cache.getInvocationContext().getOptionOverrides().isBypassInterceptorChain())
+ {
+ if (log.isTraceEnabled())
+ log.trace("put " + data.size() + " erase=" + erase);
+ synchronized (this)
{
if (erase)
{
@@ -275,10 +281,18 @@
this.data.clear();
}
}
- if (data == null)
- return;
data().putAll(data);
}
+ cache.getInvocationContext().getOptionOverrides().setBypassInterceptorChain(false);
+ }
+ else
+ {
+ // TODO add erase option to Cache (?)
+ if (erase)
+ ((TreeCacheProxyImpl) cache).treeCache.removeData(fqn);
+ cache.put(fqn, data);
+ }
+ }
public Object put(Object key, Object value)
{
@@ -287,11 +301,7 @@
Object result;
synchronized (this)
{
- try {
result = data().put(key, value);
- } catch (UnsupportedOperationException e) {
- throw new IllegalStateException("data is of type " + data.getClass());
- }
}
cache.getInvocationContext().getOptionOverrides().setBypassInterceptorChain(false);
return result;
@@ -568,6 +578,7 @@
public void put(Map data)
{
+
put(data, false);
}
1.283 +38 -44 JBossCache/src/org/jboss/cache/TreeCache.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TreeCache.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/TreeCache.java,v
retrieving revision 1.282
retrieving revision 1.283
diff -u -b -r1.282 -r1.283
--- TreeCache.java 20 Nov 2006 08:51:49 -0000 1.282
+++ TreeCache.java 20 Nov 2006 12:04:43 -0000 1.283
@@ -96,7 +96,7 @@
* @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
* @author Brian Stansberry
* @author Daniel Huang (dhuang at jboss.org)
- * @version $Id: TreeCache.java,v 1.282 2006/11/20 08:51:49 genman Exp $
+ * @version $Id: TreeCache.java,v 1.283 2006/11/20 12:04:43 genman Exp $
* <p/>
* @see <a href="http://labs.jboss.com/portal/jbosscache/docs">JBossCache doc</a>
*/
@@ -1373,12 +1373,16 @@
{
if (log.isTraceEnabled())
{
- log.trace(new StringBuffer("_get(").append("\"").append(fqn).append("\", ").append(key).append(", \"").
+ log.trace(new StringBuffer("_get(").append("\"").append(fqn).append("\", \"").append(key).append("\", \"").
append(sendNodeEvent).append("\")"));
}
if (sendNodeEvent) notifier.notifyNodeVisited(fqn, true);
DataNode n = findNode(fqn);
- if (n == null) return null;
+ if (n == null)
+ {
+ log.trace("node not found");
+ return null;
+ }
if (sendNodeEvent) notifier.notifyNodeVisited(fqn, false);
return n.get(key);
}
@@ -2231,43 +2235,26 @@
log.trace(new StringBuffer("_put(").append(tx).append(", \"").append(fqn).append("\", ").append(data).append(")"));
}
- // Find the node. This will lock it (if <tt>locking</tt> is true) and
- // add the temporarily created parent nodes to the TX's node list if tx != null)
- Node n = findNode(fqn);
- if (n == null)
- {
- String errStr = "node " + fqn + " not found (gtx=" + tx + ", caller=" + Thread.currentThread() + ")";
- if (log.isTraceEnabled())
- {
- log.trace(errStr);
- }
- throw new NodeNotExistsException(errStr);
- }
+ Node n = findNodeCheck(tx, fqn);
Map rawData = n.getNodeSPI().getRawData();
notifier.notifyNodeModified(fqn, true, rawData);
- MethodCall undo_op = null;
+ getInvocationContext().getOptionOverrides().setBypassInterceptorChain(true);
+ ((DataNode)n).put(data, (boolean)erase_contents);
- // TODO: move creation of undo-operations to separate Interceptor
// create a compensating method call (reverting the effect of
// this modification) and put it into the TX's undo list.
if (tx != null && create_undo_ops)
{
// erase previous hashmap contents
- undo_op = MethodCallFactory.create(MethodDeclarations.putDataEraseMethodLocal, tx, fqn,
+ MethodCall undo_op = MethodCallFactory.create(MethodDeclarations.putDataEraseMethodLocal, tx, fqn,
new MapCopy(rawData),
false, true);
- }
-
- ((DataNode)n).put(data, (boolean)erase_contents);
-
- if (undo_op != null)
- {
- // 1. put undo-op in TX' undo-operations list (needed to rollback TX)
tx_table.addUndoOperation(tx, undo_op);
}
notifier.notifyNodeModified(fqn, false, rawData);
+
}
/**
@@ -2290,37 +2277,29 @@
public Object _put(GlobalTransaction tx, Fqn fqn, Object key, Object value, boolean create_undo_ops)
throws CacheException
{
- DataNode n = null;
- MethodCall undo_op = null;
- Object old_value = null;
-
if (log.isTraceEnabled())
{
log.trace(new StringBuffer("_put(").append(tx).append(", \"").
- append(fqn).append("\", ").append(key).append(", ").append(value).append(")"));
+ append(fqn).append("\", k=").append(key).append(", v=").append(value).append(")"));
}
-
- n = findNode(fqn);
- if (n == null)
+ // TODO remove before release
+ if (key instanceof Map)
{
- String errStr = "node " + fqn + " not found (gtx=" + tx + ", caller=" + Thread.currentThread() + ")";
- if (log.isTraceEnabled())
- {
- log.trace(errStr);
- }
- throw new NodeNotExistsException(errStr);
+ log.warn("using a map as a key in a map, did you mean to do that?");
}
+ DataNode n = findNodeCheck(tx, fqn);
Map rawData = n.getNodeSPI().getRawData();
notifier.notifyNodeModified(fqn, true, rawData);
+
getInvocationContext().getOptionOverrides().setBypassInterceptorChain(true);
- old_value = n.put(key, value);
- getInvocationContext().getOptionOverrides().setBypassInterceptorChain(false);
+ Object old_value = n.put(key, value);
// create a compensating method call (reverting the effect of
// this modification) and put it into the TX's undo list.
if (tx != null && create_undo_ops)
{
+ MethodCall undo_op;
if (old_value == null)
{
undo_op = MethodCallFactory.create(MethodDeclarations.removeKeyMethodLocal, tx, fqn, key, false);
@@ -3760,6 +3739,21 @@
}
}
+ private DataNode findNodeCheck(GlobalTransaction tx, Fqn fqn)
+ {
+ DataNode n = findNode(fqn);
+ if (n == null)
+ {
+ String errStr = "node " + fqn + " not found (gtx=" + tx + ", caller=" + Thread.currentThread() + ")";
+ if (log.isTraceEnabled())
+ {
+ log.trace(errStr);
+ }
+ throw new NodeNotExistsException(errStr);
+ }
+ return n;
+ }
+
/**
* Finds a node given a fully qualified name and DataVersion.
*/
More information about the jboss-cvs-commits
mailing list