Author: michiel
Date: 2010-03-15 22:16:34 +0100 (Mon, 15 Mar 2010)
New Revision: 41370

Modified:
   
mmbase/trunk/core/src/main/java/org/mmbase/module/core/TransactionManager.java
Log:
  MMB-1941

Modified: 
mmbase/trunk/core/src/main/java/org/mmbase/module/core/TransactionManager.java
===================================================================
--- 
mmbase/trunk/core/src/main/java/org/mmbase/module/core/TransactionManager.java  
    2010-03-15 20:54:45 UTC (rev 41369)
+++ 
mmbase/trunk/core/src/main/java/org/mmbase/module/core/TransactionManager.java  
    2010-03-15 21:16:34 UTC (rev 41370)
@@ -11,6 +11,7 @@
 
 import java.util.*;
 import org.mmbase.module.corebuilders.*;
+import org.mmbase.core.event.*;
 
 import org.mmbase.util.logging.Logger;
 import org.mmbase.util.logging.Logging;
@@ -32,7 +33,7 @@
      * NO:   The node does not exists yet, but will be created on commit
      * YES:  The node already existed befor the transaction started.
      * NOLONGER: The node alreayd existed, but will be deleted by the 
transaction. Or, it was created and deleted in the transaction.
-     * UNDEFINED: Just a value used to indicte that the corresponding _exists 
field is not filled
+     * UNDEFINED: Just a value used to indicate that the corresponding _exists 
field is not filled
      */
     public static enum Exists {
         NO,
@@ -52,7 +53,7 @@
     private TemporaryNodeManager tmpNodeManager;
     private TransactionResolver transactionResolver;
 
-    protected Map<String, Collection<MMObjectNode>> transactions = new 
HashMap<String, Collection<MMObjectNode>>();
+    protected final Map<String, Collection<MMObjectNode>> transactions = new 
HashMap<String, Collection<MMObjectNode>>();
 
     public static TransactionManager instance;
 
@@ -126,6 +127,7 @@
             // That is a hack.
 
             transactions.put(transactionName, transactionNodes);
+            EventManager.getInstance().propagateEvent(new 
TransactionEvent.Create(transactionName));
             return transactionNodes;
         } else {
             throw new TransactionManagerException("Transaction " + 
transactionName + " already exists");
@@ -213,14 +215,41 @@
      * @todo Review this stuff..
      * @since MMBase-1.9
      */
-    public boolean resolve(String transactionName) throws 
TransactionManagerException {
+    public boolean resolve(final String transactionName) throws 
TransactionManagerException {
 
         // MM: I think we need an actual Transaction object! with e.g. a 
property 'resolved'.
 
         Collection<MMObjectNode> transaction = getTransaction(transactionName);
         if (transaction instanceof Vector) { // a bit of a trick to see if it 
is committed already
             try {
-                getTransactionResolver().resolve(transaction);
+                final Map<String, Integer> resolution = 
getTransactionResolver().resolve(transaction);
+                Map<Integer, Integer> integerResolution = new 
AbstractMap<Integer, Integer>() {
+                    public Set<Map.Entry<Integer, Integer>> entrySet() {
+                        return new AbstractSet<Map.Entry<Integer, Integer>>() {
+                            public int size() {
+                                return resolution.size();
+                            }
+                            public Iterator<Map.Entry<Integer, Integer>> 
iterator() {
+                                return new Iterator<Map.Entry<Integer, 
Integer>>() {
+                                    private final Iterator<Map.Entry<String, 
Integer>> i = resolution.entrySet().iterator();
+                                    public boolean hasNext() {
+                                        return i.hasNext();
+                                    }
+                                    public Map.Entry<Integer, Integer> next() {
+                                        Map.Entry<String, Integer> e = 
i.next();
+                                        return new 
org.mmbase.util.Entry<Integer, 
Integer>(Integer.parseInt(e.getKey().substring(transactionName.length() + 1)),
+                                                                               
            e.getValue());
+
+                                    }
+                                    public void remove() {
+                                        throw new 
UnsupportedOperationException();
+                                    }
+                                };
+                            }
+                        };
+                    }
+                };
+                EventManager.getInstance().propagateEvent(new 
TransactionEvent.Resolve(transactionName, integerResolution));
             } catch (TransactionManagerException te) {
                 throw new TransactionManagerException("Can't resolve 
transaction " + transactionName + " (it has " + transaction.size() + " nodes)", 
te);
             }
@@ -236,11 +265,14 @@
         try {
             resolve(transactionName);
             transactions.put(transactionName, 
Collections.unmodifiableCollection(transaction)); // makes it recognizable, and 
also the transaction is unusable after that
+
             if (!performCommits(user, transaction)) {
                 throw new TransactionManagerException("Can't commit 
transaction " + transactionName);
             }
 
+            EventManager.getInstance().propagateEvent(new 
TransactionEvent.Commit(transactionName));
 
+
         } finally {
             // remove nodes from the temporary node cache
             MMObjectBuilder builder = MMBase.getMMBase().getTypeDef();

_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to