Update of /var/cvs/src/org/mmbase/bridge/implementation
In directory james.mmbase.org:/tmp/cvs-serv11560/implementation

Modified Files:
        BasicCloud.java BasicNode.java BasicTransaction.java 
Log Message:
  MMB-1815, Plus some issues that made test-cases fail. Like that fact that 
commit processors where sometimes not called, or called too often. See 
ProcessorTest.java for what is garanteed to work now.


See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/bridge/implementation
See also: http://www.mmbase.org/jira/browse/MMB-1815


Index: BasicCloud.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/bridge/implementation/BasicCloud.java,v
retrieving revision 1.196
retrieving revision 1.197
diff -u -b -r1.196 -r1.197
--- BasicCloud.java     25 Nov 2008 13:25:44 -0000      1.196
+++ BasicCloud.java     30 Apr 2009 14:46:39 -0000      1.197
@@ -29,7 +29,7 @@
  * @author Rob Vermeulen
  * @author Pierre van Rooden
  * @author Michiel Meeuwissen
- * @version $Id: BasicCloud.java,v 1.196 2008/11/25 13:25:44 michiel Exp $
+ * @version $Id: BasicCloud.java,v 1.197 2009/04/30 14:46:39 michiel Exp $
  */
 public class BasicCloud implements Cloud, Cloneable, Comparable<Cloud>, 
SizeMeasurable, Serializable {
 
@@ -849,6 +849,7 @@
         return resultNodeList;
     }
 
+
     //javadoc inherited
     public NodeList getList(
         String startNodes,
@@ -1153,4 +1154,34 @@
             throw new java.lang.SecurityException("You (' " + userContext + 
"') are now allowed to shutdown mmbase (" + action + ")");
         }
     }
+
+    /**
+     * Calls the delete processor for every field.
+     * @since MMBase-1.9.1
+     */
+    protected void processDeleteProcessors(Node n) {
+        if (log.isDebugEnabled()) {
+            log.debug("Calling delete processors on " + n);
+        }
+        for (Field field : n.getNodeManager().getFields()) {
+            field.getDataType().getDeleteProcessor().commit(n, field);
+        }
+    }
+    /**
+     * Calls the commit processor for every field.
+     * @since MMBase-1.9.1
+     */
+    protected  void processCommitProcessors(Node n) {
+        if (log.isDebugEnabled()) {
+            log.debug("Calling commit processors on " + n);
+        }
+        for (Field field : n.getNodeManager().getFields()) {
+            field.getDataType().getCommitProcessor().commit(n, field);
+        }
+    }
+
+    protected void setValue(BasicNode node, String fieldName, Object value) {
+        node.getNode().setValue(fieldName, value);
+    }
+
 }


Index: BasicNode.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/bridge/implementation/BasicNode.java,v
retrieving revision 1.235
retrieving revision 1.236
diff -u -b -r1.235 -r1.236
--- BasicNode.java      24 Apr 2009 15:13:27 -0000      1.235
+++ BasicNode.java      30 Apr 2009 14:46:39 -0000      1.236
@@ -31,7 +31,7 @@
  * @author Rob Vermeulen
  * @author Pierre van Rooden
  * @author Michiel Meeuwissen
- * @version $Id: BasicNode.java,v 1.235 2009/04/24 15:13:27 michiel Exp $
+ * @version $Id: BasicNode.java,v 1.236 2009/04/30 14:46:39 michiel Exp $
  * @see org.mmbase.bridge.Node
  * @see org.mmbase.module.core.MMObjectNode
  */
@@ -279,14 +279,7 @@
      */
     @Override
     protected void setValueWithoutChecks(String fieldName, Object value) {
-        String result = 
BasicCloudContext.tmpObjectManager.setObjectField(account, "" + 
temporaryNodeId, fieldName, value);
-        if (TemporaryNodeManager.UNKNOWN == result) {
-            throw new BridgeException("Can't change unknown field '" + 
fieldName + "', of node " + getNumber() +
-                                      " of nodeManager '" + 
getNodeManager().getName() +"'");
-        } else if (TemporaryNodeManager.INVALID_VALUE == result) {
-            log.debug("Storing value");
-            getNode().setValue(fieldName, value); // commit() will throw that 
invalid.
-        }
+        cloud.setValue(this, fieldName, value);
     }
     @Override
     protected Integer toNodeNumber(Object v) {
@@ -507,7 +500,7 @@
             getCloud().setProperty(CLOUD_COMMITNODE_KEY, prev);
         }
 
-        processCommit();
+        cloud.processCommitProcessors(this);
         if (log.isDebugEnabled()) {
             log.debug("committing " + noderef.getChanged() + " " + 
noderef.getValues());
         }
@@ -552,6 +545,7 @@
     @Override
     public void delete(boolean deleteRelations) {
         checkDelete();
+        cloud.processDeleteProcessors(this);
         if (isNew()) {
             // remove from the Transaction
             // note that the node is immediately destroyed !
@@ -586,6 +580,7 @@
                 if (temporaryNodeId != -1) {
                     BasicCloudContext.tmpObjectManager.deleteTmpNode(account, 
"" + temporaryNodeId);
                 }
+
                 MMObjectNode node = getNode();
                 //node.getBuilder().removeNode(node);
                 node.remove(cloud.getUser());


Index: BasicTransaction.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/bridge/implementation/BasicTransaction.java,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -b -r1.45 -r1.46
--- BasicTransaction.java       27 Apr 2009 12:00:05 -0000      1.45
+++ BasicTransaction.java       30 Apr 2009 14:46:39 -0000      1.46
@@ -23,7 +23,7 @@
  * which means that changes are committed only if you commit the transaction 
itself.
  * This mechanism allows you to rollback changes if something goes wrong.
  * @author Pierre van Rooden
- * @version $Id: BasicTransaction.java,v 1.45 2009/04/27 12:00:05 michiel Exp $
+ * @version $Id: BasicTransaction.java,v 1.46 2009/04/30 14:46:39 michiel Exp $
  */
 public class BasicTransaction extends BasicCloud implements Transaction {
 
@@ -40,6 +40,9 @@
 
     protected BasicCloud parentCloud; // not final because of deserialization
 
+    private final Set<String> commitProcessed = new HashSet<String>();
+    private final Set<String> deleteProcessed = new HashSet<String>();
+
     /**
      * @since MMBase 1.9
      */
@@ -128,45 +131,58 @@
             try {
                 assert 
BasicCloudContext.transactionManager.getTransaction(transactionName).size() == 
getNodes().size();
 
-
-                //log.info("Commiting " + getNodes());
-
                 if (log.isDebugEnabled()) {
-                    log.debug("Resolving " + getNodes().size() + " nodes");
+                    log.debug("Resolving transaction '" + transactionName + "' 
with " + getCoreNodes().size() + " nodes");
                 }
 
                 BasicCloudContext.transactionManager.resolve(transactionName);
 
+                List<Node> nodes = getNodes();
+
                 if (log.isDebugEnabled()) {
-                    log.debug("Committing " + getNodes().size() + " nodes");
+                    log.debug("Committing " + nodes.size() + " nodes");
                 }
 
-                BasicCloudContext.transactionManager.commit(userContext, 
transactionName);
 
                 if (log.isDebugEnabled()) {
-                    log.debug("Commitprocessing " + getNodes().size() + " 
nodes");
+                    log.debug("Commitprocessing " + nodes.size() + " nodes");
                 }
 
-                // This is a hack to call the commitprocessors which are only 
available in the
-                // bridge.
+                // Now calling commit processors. They have real nodes numbers 
now.
 
-                for (Node n : getNodes()) {
+                for (Node n : nodes) {
                     if (n == null) {
                         log.warn("Found null in transaction");
                         continue;
                     }
                     if (! n.isChanged() && ! n.isNew()) {
-                        log.debug("Ignored because not changed " + 
n.isChanged() + "/" + n.isNew());
+                        log.debug("Node not changed, not calling commit 
processors");
                         continue;
                     }
                     if 
(TransactionManager.EXISTS_NOLONGER.equals(n.getStringValue("_exists"))) {
-                        log.debug("Ignored because exists no longer.");
-                        continue;
+                        log.debug("Deleted");
+                        processDeleteProcessors(n);
+                    } else {
+                        log.debug("Committing");
+                        processCommitProcessors(n);
                     }
-                    log.debug("Calling commit on " + n);
-                    n.commit();
                 }
 
+                if (log.isDebugEnabled()) {
+                    log.debug("Resolving transaction '" + transactionName + "' 
again with " + getCoreNodes().size() + " nodes");
+                }
+
+                BasicCloudContext.transactionManager.resolve(transactionName);
+
+
+                if (log.isDebugEnabled()) {
+                    log.debug("Commit transaction '" + transactionName + "' 
with " + getCoreNodes().size() + " nodes");
+                }
+
+
+                BasicCloudContext.transactionManager.commit(userContext, 
transactionName);
+
+
 
 
 
@@ -379,5 +395,34 @@
     public Cloud getNonTransactionalCloud() {
         return parentCloud.getNonTransactionalCloud();
     }
+
+
+    @Override
+    protected void processDeleteProcessors(Node n) {
+        String tempId = n.getStringValue("_number");
+        if (! deleteProcessed.contains(tempId)) {
+            super.processDeleteProcessors(n);
+            deleteProcessed.add(tempId);
+        } else {
+        }
+    }
+
+    @Override
+    protected  void processCommitProcessors(Node n) {
+        String tempId = n.getStringValue("_number");
+        if (! commitProcessed.contains(tempId)) {
+            super.processCommitProcessors(n);
+            commitProcessed.add(tempId);
+        } else {
+            log.debug("Not commit processing " + n + " because that happend 
already (Call to commit?");
+        }
+    }
+    @Override
+    protected void setValue(BasicNode node, String fieldName, Object value) {
+        super.setValue(node, fieldName, value);
+        // changed, so commit processor _must_ be called again
+        String tempId = node.getStringValue("_number");
+        commitProcessed.remove(tempId);
+    }
 }
 
_______________________________________________
Cvs mailing list
Cvs@lists.mmbase.org
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to