whoops ;-)
[mir.git] / source / mir / producer / EntityBatchingProducerNode.java
index fd8e8ba..2f49115 100755 (executable)
@@ -39,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;
@@ -50,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;
 
@@ -61,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;
@@ -121,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 {
@@ -136,7 +100,6 @@ public class EntityBatchingProducerNode implements ProducerNode {
     Map batchData;
     String expandedWhereClause;
     String expandedOrderByClause;
-    EntityBatchingProducerNodeVerb verb = (EntityBatchingProducerNodeVerb) verbs.get(aVerb);
 
     List batchLocations;
     BatchLocation location;
@@ -150,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 );
@@ -196,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);
       }
 
@@ -205,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));
@@ -246,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;
-    }
-  }
 }