whoops ;-)
[mir.git] / source / mir / producer / EntityBatchingProducerNode.java
index e12bd79..2f49115 100755 (executable)
@@ -1,3 +1,34 @@
+/*
+ * Copyright (C) 2001, 2002  The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mir is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with the com.oreilly.servlet library, any library
+ * licensed under the Apache Software License, The Sun (tm) Java Advanced
+ * Imaging library (JAI), The Sun JIMI library (or with modified versions of
+ * the above that use the same license as the above), and distribute linked
+ * combinations including the two.  You must obey the GNU General Public
+ * License in all respects for all of the code used other than the above
+ * mentioned libraries.  If you modify this file, you may extend this exception
+ * to your version of the file, but you are not obligated to do so.  If you do
+ * not wish to do so, delete this exception statement from your version.
+ */
+
 package mir.producer;
 
 import java.util.*;
@@ -8,8 +39,6 @@ import mir.storage.*;
 import mir.util.*;
 
 public class EntityBatchingProducerNode implements ProducerNode {
-  private Map verbs;
-
   private String batchInfoKey;
   private String batchDataKey;
   private EntityAdapterModel model;
@@ -19,7 +48,7 @@ public class EntityBatchingProducerNode implements ProducerNode {
   private String nrEntitiesToSkipExpression;
   private String nrEntitiesPerBatchExpression;
   private String minNrEntitiesInFirstBatchExpression;
-  private String defaultNrBatchesToProcessExpression;
+  private String nrBatchesToProcessExpression;
   private ProducerNode batchSubNode;
   private ProducerNode batchListSubNode;
 
@@ -30,57 +59,16 @@ public class EntityBatchingProducerNode implements ProducerNode {
         String aDefinition,
         String aWhereClause,
         String anOrderByClause,
-        int anrEntitiesPerBatchExpression,
-        int aminNrEntitiesInFirstBatchExpression,
-        int anrEntitiesToSkipExpression,
-        ProducerNode aBatchSubNode) {
-    this(aBatchDataKey, aBatchInfoKey, aModel, aDefinition, aWhereClause,
-        anOrderByClause, anrEntitiesPerBatchExpression, aminNrEntitiesInFirstBatchExpression, anrEntitiesToSkipExpression,
-        aBatchSubNode, null);
-  }
-
-  public EntityBatchingProducerNode(
-        String aBatchDataKey,
-        String aBatchInfoKey,
-        EntityAdapterModel aModel,
-        String aDefinition,
-        String aWhereClause,
-        String anOrderByClause,
-        int aNrEntitiesPerBatch,
-        int aMinNrEntitiesInFirstBatch,
-        int aNrEntitiesToSkip,
-        ProducerNode aBatchSubNode,
-        ProducerNode aBatchListSubNode) {
-
-    this(aBatchDataKey, aBatchInfoKey, aModel, aDefinition,
-         aWhereClause, anOrderByClause,
-        Integer.toString(aNrEntitiesPerBatch),
-        Integer.toString(aMinNrEntitiesInFirstBatch),
-        Integer.toString(aNrEntitiesToSkip),
-        "1",
-        aBatchSubNode, aBatchListSubNode);
-
-  }
-
-  public EntityBatchingProducerNode(
-        String aBatchDataKey,
-        String aBatchInfoKey,
-        EntityAdapterModel aModel,
-        String aDefinition,
-        String aWhereClause,
-        String anOrderByClause,
         String anrEntitiesPerBatchExpression,
         String aminNrEntitiesInFirstBatchExpression,
         String anrEntitiesToSkipExpression,
-        String aDefaultNrBatchesToProcessExpression,
+        String aNrBatchesToProcessExpression,
         ProducerNode aBatchSubNode,
         ProducerNode aBatchListSubNode) {
 
     batchSubNode = aBatchSubNode;
     batchListSubNode = aBatchListSubNode;
 
-    verbs = new HashMap();
-
     batchDataKey = aBatchDataKey;
     batchInfoKey = aBatchInfoKey;
     model = aModel;
@@ -90,7 +78,14 @@ public class EntityBatchingProducerNode implements ProducerNode {
     nrEntitiesToSkipExpression = anrEntitiesToSkipExpression;
     nrEntitiesPerBatchExpression = anrEntitiesPerBatchExpression;
     minNrEntitiesInFirstBatchExpression = aminNrEntitiesInFirstBatchExpression;
-    defaultNrBatchesToProcessExpression = aDefaultNrBatchesToProcessExpression;
+    nrBatchesToProcessExpression = aNrBatchesToProcessExpression;
+  }
+
+  protected boolean isAborted(Map aValueMap) {
+    Object producerValue = aValueMap.get(NodedProducer.PRODUCER_KEY);
+    return (
+       (producerValue instanceof NodedProducer) &&
+      ((NodedProducer) producerValue).getIsAborted());
   }
 
   public void produce(Map aValueMap, String aVerb, PrintWriter aLogger) throws ProducerFailure {
@@ -105,7 +100,6 @@ public class EntityBatchingProducerNode implements ProducerNode {
     Map batchData;
     String expandedWhereClause;
     String expandedOrderByClause;
-    EntityBatchingProducerNodeVerb verb = (EntityBatchingProducerNodeVerb) verbs.get(aVerb);
 
     List batchLocations;
     BatchLocation location;
@@ -119,12 +113,7 @@ public class EntityBatchingProducerNode implements ProducerNode {
 
 
     try {
-      if (verb==null) {
-        nrBatchesToProcess = ParameterExpander.evaluateIntegerExpressionWithDefault( aValueMap, defaultNrBatchesToProcessExpression, -1 );
-      }
-      else {
-        nrBatchesToProcess=verb.nrBatchesToProcess;
-      }
+      nrBatchesToProcess = ParameterExpander.evaluateIntegerExpressionWithDefault( aValueMap, nrBatchesToProcessExpression, -1 );
 
       expandedWhereClause = ParameterExpander.expandExpression( aValueMap, whereClause );
       expandedOrderByClause = ParameterExpander.expandExpression( aValueMap, orderByClause );
@@ -165,7 +154,7 @@ public class EntityBatchingProducerNode implements ProducerNode {
       batchData.put("last", batchesData.get(batchesData.size()-1));
       batchData.put("count", new Integer(batchesData.size()));
 
-      if (batchListSubNode!=null) {
+      if (batchListSubNode!=null && (!isAborted(aValueMap))) {
         batchListSubNode.produce(aValueMap, aVerb, aLogger);
       }
 
@@ -174,7 +163,7 @@ public class EntityBatchingProducerNode implements ProducerNode {
       }
 
       if (batchSubNode!=null) {
-        for (i=0; i<nrBatchesToProcess; i++) {
+        for (i=0; i<nrBatchesToProcess && !isAborted(aValueMap); i++) {
           location = (BatchLocation) batchLocations.get(i);
 
           batchData.put("current", batchesData.get(i));
@@ -215,21 +204,5 @@ public class EntityBatchingProducerNode implements ProducerNode {
       nrEntities = aNrEntities;
     }
   }
-
-  public Set buildVerbSet() {
-    return verbs.keySet();
-  };
-
-  public void addVerb(String aVerb, int aNrPagesToGenerate) {
-    verbs.put(aVerb, new EntityBatchingProducerNodeVerb(aNrPagesToGenerate));
-  }
-
-  private class EntityBatchingProducerNodeVerb {
-    int nrBatchesToProcess;
-
-    EntityBatchingProducerNodeVerb(int aNrBatchesToProcess) {
-      nrBatchesToProcess = aNrBatchesToProcess;
-    }
-  }
 }