X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Fproducer%2FEntityBatchingProducerNode.java;h=e12bd79eb617a1086a48399d5f7ba03acf8c6fd0;hb=5757f37a1bc4e2dcad3054a66611b1a02fb7d8b3;hp=9a865c00fe42b6981e6c901f4e9ee76c13625ee3;hpb=3389d56d4d82089033fd83f9c8758126ffd7da44;p=mir.git diff --git a/source/mir/producer/EntityBatchingProducerNode.java b/source/mir/producer/EntityBatchingProducerNode.java index 9a865c00..e12bd79e 100755 --- a/source/mir/producer/EntityBatchingProducerNode.java +++ b/source/mir/producer/EntityBatchingProducerNode.java @@ -7,45 +7,43 @@ import mir.entity.*; import mir.storage.*; import mir.util.*; -// abstract public int getSize(String where) throws SQLException,StorageObjectException; - public class EntityBatchingProducerNode implements ProducerNode { private Map verbs; 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; - private int nrEntitiesPerBatch; - private int minNrEntitiesInFirstBatch; + private String nrEntitiesToSkipExpression; + private String nrEntitiesPerBatchExpression; + private String minNrEntitiesInFirstBatchExpression; + private String defaultNrBatchesToProcessExpression; private ProducerNode batchSubNode; private ProducerNode batchListSubNode; public EntityBatchingProducerNode( String aBatchDataKey, String aBatchInfoKey, - StorageObject aStorage, - EntityAdapterDefinition aDefinition, + EntityAdapterModel aModel, + String aDefinition, String aWhereClause, String anOrderByClause, - int aNrEntitiesPerBatch, - int aMinNrEntitiesInFirstBatch, - int aNrEntitiesToSkip, + int anrEntitiesPerBatchExpression, + int aminNrEntitiesInFirstBatchExpression, + int anrEntitiesToSkipExpression, ProducerNode aBatchSubNode) { - this(aBatchDataKey, aBatchInfoKey, aStorage, aDefinition, aWhereClause, - anOrderByClause, aNrEntitiesPerBatch, aMinNrEntitiesInFirstBatch, aNrEntitiesToSkip, + this(aBatchDataKey, aBatchInfoKey, aModel, aDefinition, aWhereClause, + anOrderByClause, anrEntitiesPerBatchExpression, aminNrEntitiesInFirstBatchExpression, anrEntitiesToSkipExpression, aBatchSubNode, null); } - public EntityBatchingProducerNode( String aBatchDataKey, String aBatchInfoKey, - StorageObject aStorage, - EntityAdapterDefinition aDefinition, + EntityAdapterModel aModel, + String aDefinition, String aWhereClause, String anOrderByClause, int aNrEntitiesPerBatch, @@ -54,6 +52,30 @@ public class EntityBatchingProducerNode implements ProducerNode { 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, + ProducerNode aBatchSubNode, + ProducerNode aBatchListSubNode) { + batchSubNode = aBatchSubNode; batchListSubNode = aBatchListSubNode; @@ -61,13 +83,14 @@ public class EntityBatchingProducerNode implements ProducerNode { batchDataKey = aBatchDataKey; batchInfoKey = aBatchInfoKey; - storage = aStorage; + model = aModel; definition = aDefinition; whereClause = aWhereClause; orderByClause = anOrderByClause; - nrEntitiesToSkip = aNrEntitiesToSkip; - nrEntitiesPerBatch = aNrEntitiesPerBatch; - minNrEntitiesInFirstBatch = aMinNrEntitiesInFirstBatch; + nrEntitiesToSkipExpression = anrEntitiesToSkipExpression; + nrEntitiesPerBatchExpression = anrEntitiesPerBatchExpression; + minNrEntitiesInFirstBatchExpression = aminNrEntitiesInFirstBatchExpression; + defaultNrBatchesToProcessExpression = aDefaultNrBatchesToProcessExpression; } public void produce(Map aValueMap, String aVerb, PrintWriter aLogger) throws ProducerFailure { @@ -87,21 +110,33 @@ public class EntityBatchingProducerNode implements ProducerNode { List batchLocations; BatchLocation location; + int nrEntitiesToSkip; + int nrEntitiesPerBatch; + int minNrEntitiesInFirstBatch; + // ML: The order by clause should lead to a result set in _reverse order_: the first row will be // the last entity presented on the last page - if (verb==null) - throw new ProducerFailure("EntityBatchingProducerNode: unknown verb '"+aVerb+"'", null); - try { + 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 = storage.getSize(expandedWhereClause)-nrEntitiesToSkip; + nrEntities = model.getMappingForName(definition).getStorage().getSize(expandedWhereClause)-nrEntitiesToSkip; nrEntitiesInFirstBatch = nrEntities % nrEntitiesPerBatch; while (nrEntitiesInFirstBatch=nrEntitiesPerBatch) nrEntitiesInFirstBatch = nrEntitiesInFirstBatch + nrEntitiesPerBatch; @@ -110,32 +145,32 @@ 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("size", Integer.toString(nrEntitiesInFirstBatch)); + batchData.put("index", new Integer(nrBatchesAfterFirst+1)); + batchData.put("size", new Integer(nrEntitiesInFirstBatch)); batchesData.add(batchData); for (i=0; i-1 && verb.nrBatchesToProcessnrBatchesAfterFirst+1) { + nrBatchesToProcess = nrBatchesAfterFirst+1; } if (batchSubNode!=null) { @@ -153,14 +188,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); }