import mir.util.*;
public class EntityBatchingProducerNode implements ProducerNode {
- private Map verbs;
-
private String batchInfoKey;
private String batchDataKey;
private EntityAdapterModel model;
private String nrEntitiesToSkipExpression;
private String nrEntitiesPerBatchExpression;
private String minNrEntitiesInFirstBatchExpression;
- private String defaultNrBatchesToProcessExpression;
+ private String nrBatchesToProcessExpression;
private ProducerNode batchSubNode;
private ProducerNode batchListSubNode;
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;
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 {
Map batchData;
String expandedWhereClause;
String expandedOrderByClause;
- EntityBatchingProducerNodeVerb verb = (EntityBatchingProducerNodeVerb) verbs.get(aVerb);
List batchLocations;
BatchLocation location;
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 );
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);
}
}
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));
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;
- }
- }
}