Author: michiel
Date: 2009-05-29 15:42:17 +0200 (Fri, 29 May 2009)
New Revision: 35525

Modified:
   mmbase/trunk/src/org/mmbase/bridge/implementation/BasicTransaction.java
   mmbase/trunk/src/org/mmbase/module/core/MMObjectBuilder.java
   mmbase/trunk/src/org/mmbase/module/core/TransactionManager.java
   mmbase/trunk/src/org/mmbase/module/core/TransactionResolver.java
Log:
Changed transactions stuff a bit so that things done in commitprocessors are in 
the same transaction. The transaction must be resolve twice (that happend 
already, but didn't work quite good)

Modified: 
mmbase/trunk/src/org/mmbase/bridge/implementation/BasicTransaction.java
===================================================================
--- mmbase/trunk/src/org/mmbase/bridge/implementation/BasicTransaction.java     
2009-05-29 13:40:17 UTC (rev 35524)
+++ mmbase/trunk/src/org/mmbase/bridge/implementation/BasicTransaction.java     
2009-05-29 13:42:17 UTC (rev 35525)
@@ -184,9 +184,6 @@
                 BasicCloudContext.transactionManager.commit(userContext, 
transactionName);
 
 
-
-
-
             } catch (TransactionManagerException e) {
                 // do we drop the transaction here or delete the trans context?
                 // return false;

Modified: mmbase/trunk/src/org/mmbase/module/core/MMObjectBuilder.java
===================================================================
--- mmbase/trunk/src/org/mmbase/module/core/MMObjectBuilder.java        
2009-05-29 13:40:17 UTC (rev 35524)
+++ mmbase/trunk/src/org/mmbase/module/core/MMObjectBuilder.java        
2009-05-29 13:42:17 UTC (rev 35525)
@@ -89,6 +89,10 @@
      */
     public static final String TMP_FIELD_NUMBER = "_number";
     public static final String TMP_FIELD_EXISTS = "_exists";
+    /**
+     * @since MMBase-1.9.1
+     */
+    static final String TMP_FIELD_RESOLVED = "_resolved";
 
     /**
      * Default (system) owner name for the owner field.
@@ -277,7 +281,9 @@
      * This is overridden from FunctionProvider, because this one needs to be 
(also) a NodeFunction
      * @since MMBase-1.8
      */
-    protected Function<Collection<? extends Function>> getFunctions = new 
NodeFunction<Collection<? extends Function>>("getFunctions", 
Parameter.emptyArray(), ReturnType.COLLECTION) {
+    protected Function<Collection<? extends Function>> getFunctions = new 
NodeFunction<Collection<? extends Function>>("getFunctions",
+                                                                               
                                        Parameter.emptyArray(),
+                                                                               
                                        new ReturnType<Collection<? extends 
Function>>(Collection.class, "Collection")) {
             {
                 setDescription("The 'getFunctions' returns a Map of al 
Function object which are available on this FunctionProvider");
             }
@@ -501,6 +507,7 @@
             // add temporary fields
             checkAddTmpField(TMP_FIELD_NUMBER);
             checkAddTmpField(TMP_FIELD_EXISTS);
+            checkAddTmpField(TMP_FIELD_RESOLVED);
 
             // get property of maximum number of queries..
             String property = getInitParameter(MAX_NODES_FROM_QUERY_PROPERTY);

Modified: mmbase/trunk/src/org/mmbase/module/core/TransactionManager.java
===================================================================
--- mmbase/trunk/src/org/mmbase/module/core/TransactionManager.java     
2009-05-29 13:40:17 UTC (rev 35524)
+++ mmbase/trunk/src/org/mmbase/module/core/TransactionManager.java     
2009-05-29 13:42:17 UTC (rev 35525)
@@ -194,15 +194,14 @@
         // MM: I think we need an actual Transaction object! with e.g. a 
property 'resolved'.
 
         Collection<MMObjectNode> transaction = getTransaction(transactionName);
-        if (transaction instanceof ArrayList) { // a bit of a trick to see if 
it is resolved already
+        if (transaction instanceof ArrayList) { // a bit of a trick to see if 
it is committed already
             try {
                 getTransactionResolver().resolve(transaction);
-                transactions.put(transactionName, 
Collections.unmodifiableCollection(transaction)); // makes it recognizable, and 
also the transaction is unusable after that
             } catch (TransactionManagerException te) {
                 throw new TransactionManagerException("Can't resolve 
transaction " + transactionName + " (it has " + transaction.size() + " nodes)", 
te);
             }
         } else {
-            log.service("Resolved already " + transaction.getClass());
+            log.service("Committed already " + transaction.getClass());
             return false;
         }
         return true;
@@ -212,10 +211,12 @@
         Collection<MMObjectNode> transaction = getTransaction(transactionName);
         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);
             }
 
+
         } finally {
             // remove nodes from the temporary node cache
             MMObjectBuilder builder = MMBase.getMMBase().getTypeDef();
@@ -268,6 +269,8 @@
             }
             if (commitOK) {
                 state.state = State.COMMITED;
+                node.storeValue(MMObjectBuilder.TMP_FIELD_RESOLVED, null);
+
             } else {
                 state.state = State.FAILED;
             }
@@ -281,6 +284,7 @@
             }
             if (insertOK > 0) {
                 state.state = State.COMMITED;
+                node.storeValue(MMObjectBuilder.TMP_FIELD_RESOLVED, null);
             } else {
                 state.state = State.FAILED;
                 String message = "When this failed, it is possible that the 
creation of an insrel went right, which leads to a database inconsistency..  
stop now.. (transaction 2.0: [rollback?])";
@@ -300,6 +304,7 @@
 
         log.debug("Checking types and existance");
 
+        System.out.println("Commtting " + nodes);
         for (MMObjectNode node : nodes) {
             // Nodes are uncommited by default
             NodeState state = new NodeState();

Modified: mmbase/trunk/src/org/mmbase/module/core/TransactionResolver.java
===================================================================
--- mmbase/trunk/src/org/mmbase/module/core/TransactionResolver.java    
2009-05-29 13:40:17 UTC (rev 35524)
+++ mmbase/trunk/src/org/mmbase/module/core/TransactionResolver.java    
2009-05-29 13:42:17 UTC (rev 35525)
@@ -34,7 +34,7 @@
      * Given a map where the keys are temporary identifiers, sets the values 
to actual new node
      * numbers, unless this was already done.
      */
-    private void getNewNumbers(Map<String, Integer> numbers) {
+    private void getNewNumbers(final Map<String, Integer> numbers) {
         // Get the numbers
         for (Map.Entry<String, Integer> numberEntry : numbers.entrySet()) {
             Integer num = numberEntry.getValue();
@@ -52,7 +52,8 @@
         }
     }
 
-    private void setNewNumbers(Map<MMObjectNode, Collection<String>> nnodes, 
Map<String, Integer> numbers) {
+    private void setNewNumbers(final Map<MMObjectNode, Collection<String>> 
nnodes,
+                               final Map<String, Integer> numbers) {
         // put numbers in the right place
         for (Map.Entry<MMObjectNode, Collection<String>> nnodeEntry : 
nnodes.entrySet()) {
             MMObjectNode node = nnodeEntry.getKey();
@@ -104,8 +105,8 @@
      * @throws TransactionManagerException if the transactiosn could not be 
successfully completely resolved.
     */
     void resolve(final Collection<MMObjectNode> nodes) throws 
TransactionManagerException {
-        Map<String, Integer> numbers = new HashMap<String, Integer>(); /* Temp 
key -> Real node number */
-        Map<MMObjectNode, Collection<String>> nnodes  = new 
HashMap<MMObjectNode, Collection<String>>(); /* MMObjectNode --> List of 
changed fields */
+        final Map<String, Integer> numbers = new HashMap<String, Integer>(); 
/* Temp key -> Real node number */
+        final Map<MMObjectNode, Collection<String>> nnodes  = new 
HashMap<MMObjectNode, Collection<String>>(); /* MMObjectNode --> List of 
changed fields */
 
 
 
@@ -116,6 +117,10 @@
             if (log.isDebugEnabled()) {
                 log.debug("TransactionResolver - builder " + node.getName() + 
" builder " + bul);
             }
+            if 
(Boolean.TRUE.equals(node.getValue(MMObjectBuilder.TMP_FIELD_RESOLVED))) {
+                log.debug("Node was resolved already");
+                continue;
+            }
             for (CoreField fd : bul.getFields()) {
                 int dbtype = fd.getType();
                 if (log.isDebugEnabled()) {
@@ -127,6 +132,7 @@
                         String field = fd.getName();
                         String tmpField = "_" + field;
                         if (node.getDBState(tmpField) == Field.STATE_VIRTUAL) {
+
                             if (node.isNull(field)) {
                                 if (! node.isNull(tmpField)) {
                                     String key = node.getStringValue(tmpField);
@@ -175,6 +181,8 @@
                     }
                 }
             }
+            node.storeValue(MMObjectBuilder.TMP_FIELD_RESOLVED, Boolean.TRUE);
+
         }
 
         if (log.isDebugEnabled()) {
@@ -187,5 +195,6 @@
         setNewNumbers(nnodes, numbers);
 
         check(nodes);
+
     }
 }

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

Reply via email to