/*
- * Copyright (C) 2001, 2002 The Mir-coders group
+ * Copyright (C) 2001-2006 The Mir-coders group
*
* This file is part of Mir.
*
*
* In addition, as a special exception, The Mir-coders gives permission to link
* the code of this program with any library licensed under the Apache Software License,
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
- * (or with modified versions of the above that use the same license as the above),
* and distribute linked combinations including the two. You must obey the
* GNU General Public License in all respects for all of the code used other than
* the above mentioned libraries. If you modify this file, you may extend this
*/
package mir.producer;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Vector;
-
import mir.entity.adapter.EntityAdapterModel;
import mir.entity.adapter.EntityIteratorAdapter;
-import mir.log.LoggerWrapper;
import mir.util.ParameterExpander;
+import mir.util.StringRoutines;
+
+import java.util.*;
/**
- * <p>Title: EntityBatchingProducerNode</p>
- * <p>Description:
- * This producer makes it possible to show articles in batches, like on archive
- * pages.
- *
- * <emph> The order by clause should lead to a result set in <b>reverse order<b>:
- * the first row will be the last entity in the last batch
- * </p>
- * <p>Copyright: Copyright (c) 2003</p>
- * <p>Company: </p>
- * @author not attributable
- * @version 1.0
+ * This producer makes it possible to show articles in batches, like on archive pages.
+ * <emph> The order by clause should lead to a result set in <b>reverse order</b>:
+ * the first row will be the last entity in the last batch </emph>
*/
public class EntityBatchingProducerNode implements ProducerNode {
private String batchDataKey;
private EntityAdapterModel model;
private String mainTablePrefix;
- private List extraTables;
+ private String extraTables;
private String definition;
private String whereClause;
private String orderByClause;
String aBatchInfoKey,
EntityAdapterModel aModel,
String aMainTablePrefix,
- List someExtraTables,
+ String someExtraTables,
String aDefinition,
String aWhereClause,
String anOrderByClause,
minNrEntitiesInFirstBatchExpression = aminNrEntitiesInFirstBatchExpression;
nrBatchesToProcessExpression = aNrBatchesToProcessExpression;
}
-
+
protected boolean isAborted(Map aValueMap) {
Object producerValue = aValueMap.get(NodedProducer.PRODUCER_KEY);
return (
((NodedProducer) producerValue).getIsAborted());
}
- public void produce(Map aValueMap, String aVerb, LoggerWrapper aLogger) throws ProducerFailure {
- Iterator browser;
+ public void produce(ProductionContext aProducerContext) throws ProducerExc, ProducerFailure {
int nrEntities;
int nrBatchesAfterFirst;
int nrEntitiesInFirstBatch;
int nrBatchesToProcess;
List batchesData;
int i;
- int position;
Map batchData;
String expandedWhereClause;
String expandedOrderByClause;
int minNrEntitiesInFirstBatch;
try {
- nrBatchesToProcess = ParameterExpander.evaluateIntegerExpressionWithDefault( aValueMap, nrBatchesToProcessExpression, -1 );
+ nrBatchesToProcess = ParameterExpander.evaluateIntegerExpressionWithDefault(aProducerContext.getValueSet(), nrBatchesToProcessExpression, -1);
- expandedWhereClause = ParameterExpander.expandExpression( aValueMap, whereClause );
- expandedOrderByClause = ParameterExpander.expandExpression( aValueMap, orderByClause );
+ expandedWhereClause = ParameterExpander.expandExpression( aProducerContext.getValueSet(), whereClause );
+ expandedOrderByClause = ParameterExpander.expandExpression( aProducerContext.getValueSet(), orderByClause );
- nrEntitiesToSkip = ParameterExpander.evaluateIntegerExpression( aValueMap, nrEntitiesToSkipExpression);
- nrEntitiesPerBatch = ParameterExpander.evaluateIntegerExpression( aValueMap, nrEntitiesPerBatchExpression);
- minNrEntitiesInFirstBatch = ParameterExpander.evaluateIntegerExpression( aValueMap, minNrEntitiesInFirstBatchExpression);
+ nrEntitiesToSkip = ParameterExpander.evaluateIntegerExpression( aProducerContext.getValueSet(), nrEntitiesToSkipExpression);
+ nrEntitiesPerBatch = ParameterExpander.evaluateIntegerExpression( aProducerContext.getValueSet(), nrEntitiesPerBatchExpression);
+ minNrEntitiesInFirstBatch = ParameterExpander.evaluateIntegerExpression( aProducerContext.getValueSet(), minNrEntitiesInFirstBatchExpression);
+ List extraTableList = StringRoutines.splitString(ParameterExpander.expandExpression( aProducerContext.getValueSet(), extraTables).trim(), ",");
- batchesData = new Vector();
- batchLocations = new Vector();
+ batchesData = new ArrayList();
+ batchLocations = new ArrayList();
- nrEntities = model.getMappingForName(definition).getStorage().getSize(expandedWhereClause)-nrEntitiesToSkip;
+ nrEntities = model.getMappingForName(definition).getDatabase().getSize(
+ mainTablePrefix, extraTableList, expandedWhereClause)-nrEntitiesToSkip;
nrEntitiesInFirstBatch = nrEntities % nrEntitiesPerBatch;
while (nrEntitiesInFirstBatch<minNrEntitiesInFirstBatch && nrEntities-nrEntitiesInFirstBatch>=nrEntitiesPerBatch)
nrEntitiesInFirstBatch = nrEntitiesInFirstBatch + nrEntitiesPerBatch;
}
batchData = new HashMap();
- ParameterExpander.setValueForKey(aValueMap, batchInfoKey, batchData);
+ ParameterExpander.setValueForKey(aProducerContext.getValueSet(), 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 && (!isAborted(aValueMap))) {
- batchListSubNode.produce(aValueMap, aVerb, aLogger);
+ if (batchListSubNode!=null && (!isAborted(aProducerContext.getValueSet()))) {
+ batchListSubNode.produce(aProducerContext);
}
if (nrBatchesToProcess<0 || nrBatchesToProcess>nrBatchesAfterFirst+1) {
}
if (batchSubNode!=null) {
- for (i=0; i<nrBatchesToProcess && !isAborted(aValueMap); i++) {
+ for (i=0; i<nrBatchesToProcess && !isAborted(aProducerContext.getValueSet()); i++) {
location = (BatchLocation) batchLocations.get(i);
batchData.put("current", batchesData.get(i));
else
batchData.put("next", null);
- Iterator j = new EntityIteratorAdapter(mainTablePrefix, extraTables, expandedWhereClause, expandedOrderByClause,
+ Iterator j = new EntityIteratorAdapter(mainTablePrefix, extraTableList, expandedWhereClause, expandedOrderByClause,
location.nrEntities, model, definition, location.nrEntities, location.firstEntity);
- List entities = new Vector();
+ List entities = new ArrayList();
while (j.hasNext())
entities.add(0, j.next());
- ParameterExpander.setValueForKey(aValueMap, batchDataKey, entities );
+ ParameterExpander.setValueForKey(aProducerContext.getValueSet(), batchDataKey, entities );
- batchSubNode.produce(aValueMap, aVerb, aLogger);
+ batchSubNode.produce(aProducerContext);
}
}
}
catch (Throwable t) {
- aLogger.error("EntityBatchingProducerNode caused an exception: " + t.getMessage());
+ aProducerContext.getLogger().warn("EntityBatchingProducerNode caused an exception: " + t.getMessage());
}
- };
+ }
private class BatchLocation {
int nrEntities;