+ if (verb==null) {
+ nrBatchesToProcess = ParameterExpander.evaluateIntegerExpressionWithDefault( aValueMap, defaultNrBatchesToProcessExpression, -1 );
+ }
+ else {
+ nrBatchesToProcess=verb.nrBatchesToProcess;
+ }
+
+ expandedWhereClause = ParameterExpander.expandExpression( aValueMap, whereClause );
+ expandedOrderByClause = ParameterExpander.expandExpression( aValueMap, orderByClause );
+
+ nrEntitiesToSkip = ParameterExpander.evaluateIntegerExpression( aValueMap, nrEntitiesToSkipExpression);
+ nrEntitiesPerBatch = ParameterExpander.evaluateIntegerExpression( aValueMap, nrEntitiesPerBatchExpression);
+ minNrEntitiesInFirstBatch = ParameterExpander.evaluateIntegerExpression( aValueMap, minNrEntitiesInFirstBatchExpression);
+
+ batchesData = new Vector();
+ batchLocations = new Vector();
+
+ nrEntities = model.getMappingForName(definition).getStorage().getSize(expandedWhereClause)-nrEntitiesToSkip;
+ nrEntitiesInFirstBatch = nrEntities % nrEntitiesPerBatch;
+ while (nrEntitiesInFirstBatch<minNrEntitiesInFirstBatch && nrEntities-nrEntitiesInFirstBatch>=nrEntitiesPerBatch)
+ nrEntitiesInFirstBatch = nrEntitiesInFirstBatch + nrEntitiesPerBatch;
+ nrBatchesAfterFirst = (nrEntities-nrEntitiesInFirstBatch)/nrEntitiesPerBatch;
+
+ batchLocations.add(new BatchLocation(nrBatchesAfterFirst*nrEntitiesPerBatch, nrEntitiesInFirstBatch));
+ batchData = new HashMap();
+ batchData.put("identifier", "");
+ batchData.put("index", new Integer(nrBatchesAfterFirst+1));
+ batchData.put("size", new Integer(nrEntitiesInFirstBatch));
+ batchesData.add(batchData);
+
+ for (i=0; i<nrBatchesAfterFirst; i++) {
+ batchLocations.add(1, new BatchLocation(i*nrEntitiesPerBatch, nrEntitiesPerBatch));
+ batchData = new HashMap();
+ batchData.put("identifier", new Integer(i));
+ batchData.put("index", new Integer(i+1));
+ batchData.put("size", new Integer(nrEntitiesPerBatch));
+ batchesData.add(1, batchData);
+ }
+
+ batchData = new HashMap();
+ 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", new Integer(batchesData.size()));
+
+ if (batchListSubNode!=null) {
+ batchListSubNode.produce(aValueMap, aVerb, aLogger);
+ }
+
+ if (nrBatchesToProcess<0 || nrBatchesToProcess>nrBatchesAfterFirst+1) {
+ nrBatchesToProcess = nrBatchesAfterFirst+1;
+ }
+
+ if (batchSubNode!=null) {
+ for (i=0; i<nrBatchesToProcess; i++) {
+ location = (BatchLocation) batchLocations.get(i);
+
+ batchData.put("current", batchesData.get(i));
+ if (i>0)
+ batchData.put("previous", batchesData.get(i-1));
+ else
+ batchData.put("previous", null);
+
+ if (i<batchesData.size()-1)
+ batchData.put("next", batchesData.get(i+1));
+ else
+ batchData.put("next", null);
+
+ 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());
+
+ ParameterExpander.setValueForKey(aValueMap, batchDataKey, entities );
+
+ batchSubNode.produce(aValueMap, aVerb, aLogger);
+ }