producer XML configuration support: Producers can be set up using an XML input
[mir.git] / source / mir / producer / EntityBatchingProducerNode.java
index e0d74c6..ce256ff 100755 (executable)
@@ -12,8 +12,8 @@ public class EntityBatchingProducerNode implements ProducerNode {
 
   private String batchInfoKey;
   private String batchDataKey;
-  private StorageObject storage;
-  private EntityAdapterDefinition definition;
+  private EntityAdapterModel model;
+  private String definition;
   private String whereClause;
   private String orderByClause;
   private int nrEntitiesToSkip;
@@ -25,15 +25,15 @@ public class EntityBatchingProducerNode implements ProducerNode {
   public EntityBatchingProducerNode(
         String aBatchDataKey,
         String aBatchInfoKey,
-        StorageObject aStorage,
-        EntityAdapterDefinition aDefinition,
+        EntityAdapterModel aModel,
+        String aDefinition,
         String aWhereClause,
         String anOrderByClause,
         int aNrEntitiesPerBatch,
         int aMinNrEntitiesInFirstBatch,
         int aNrEntitiesToSkip,
         ProducerNode aBatchSubNode) {
-    this(aBatchDataKey, aBatchInfoKey, aStorage, aDefinition, aWhereClause,
+    this(aBatchDataKey, aBatchInfoKey, aModel, aDefinition, aWhereClause,
         anOrderByClause, aNrEntitiesPerBatch, aMinNrEntitiesInFirstBatch, aNrEntitiesToSkip,
         aBatchSubNode, null);
   }
@@ -42,8 +42,8 @@ public class EntityBatchingProducerNode implements ProducerNode {
   public EntityBatchingProducerNode(
         String aBatchDataKey,
         String aBatchInfoKey,
-        StorageObject aStorage,
-        EntityAdapterDefinition aDefinition,
+        EntityAdapterModel aModel,
+        String aDefinition,
         String aWhereClause,
         String anOrderByClause,
         int aNrEntitiesPerBatch,
@@ -59,7 +59,7 @@ public class EntityBatchingProducerNode implements ProducerNode {
 
     batchDataKey = aBatchDataKey;
     batchInfoKey = aBatchInfoKey;
-    storage = aStorage;
+    model = aModel;
     definition = aDefinition;
     whereClause = aWhereClause;
     orderByClause = anOrderByClause;
@@ -99,7 +99,7 @@ public class EntityBatchingProducerNode implements ProducerNode {
       batchesData = new Vector();
       batchLocations = new Vector();
 
-      nrEntities = storage.getSize(expandedWhereClause)-nrEntitiesToSkip;
+      nrEntities = model.getMappingForName(definition).getStorage().getSize(expandedWhereClause)-nrEntitiesToSkip;
       nrEntitiesInFirstBatch = nrEntities % nrEntitiesPerBatch;
       while (nrEntitiesInFirstBatch<minNrEntitiesInFirstBatch && nrEntities-nrEntitiesInFirstBatch>=nrEntitiesPerBatch)
         nrEntitiesInFirstBatch = nrEntitiesInFirstBatch + nrEntitiesPerBatch;
@@ -108,7 +108,7 @@ public class EntityBatchingProducerNode implements ProducerNode {
       batchLocations.add(new BatchLocation(nrBatchesAfterFirst*nrEntitiesPerBatch, nrEntitiesInFirstBatch));
       batchData = new HashMap();
       batchData.put("identifier", "");
-      batchData.put("index", Integer.toString(1));
+      batchData.put("index", Integer.toString(nrBatchesAfterFirst+1));
       batchData.put("size", Integer.toString(nrEntitiesInFirstBatch));
       batchesData.add(batchData);
 
@@ -116,16 +116,17 @@ public class EntityBatchingProducerNode implements ProducerNode {
         batchLocations.add(1, new BatchLocation(i*nrEntitiesPerBatch, nrEntitiesPerBatch));
         batchData = new HashMap();
         batchData.put("identifier", Integer.toString(i));
-        batchData.put("index", Integer.toString(nrBatchesAfterFirst-i+1));
+        batchData.put("index", Integer.toString(i+1));
         batchData.put("size", Integer.toString(nrEntitiesPerBatch));
         batchesData.add(1, batchData);
       }
 
       batchData = new HashMap();
-      aValueMap.put(batchInfoKey, batchData);
+      ParameterExpander.setValueForKey(aValueMap, batchInfoKey, batchData);
       batchData.put("all", batchesData);
       batchData.put("first", batchesData.get(0));
       batchData.put("last", batchesData.get(batchesData.size()-1));
+      batchData.put("count", Integer.toString(batchesData.size()));
 
       if (batchListSubNode!=null) {
         batchListSubNode.produce(aValueMap, aVerb, aLogger);
@@ -151,14 +152,14 @@ public class EntityBatchingProducerNode implements ProducerNode {
           else
             batchData.put("next", null);
 
-          Iterator j = new EntityIteratorAdapter(storage, expandedWhereClause, expandedOrderByClause,
-                    location.nrEntities, definition, location.nrEntities, location.firstEntity);
+          Iterator j = new EntityIteratorAdapter(expandedWhereClause, expandedOrderByClause,
+                    location.nrEntities, model, definition, location.nrEntities, location.firstEntity);
           List entities = new Vector();
 
           while (j.hasNext())
             entities.add(0, j.next());
 
-          aValueMap.put( batchDataKey, entities );
+          ParameterExpander.setValueForKey(aValueMap, batchDataKey, entities );
 
           batchSubNode.produce(aValueMap, aVerb, aLogger);
         }