X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Fproducer%2FEntityBatchingProducerNode.java;h=aa0bf413081dbc7759490eea9de25a322bf3c543;hb=2b0e1c1d91eea7e201af61e1065ad12bf966d1ba;hp=fd8e8ba9a4131a8d0e91d40c79fa7e95b29652f8;hpb=8563841098b6ab3e6233f61519e58b41dcc30266;p=mir.git diff --git a/source/mir/producer/EntityBatchingProducerNode.java b/source/mir/producer/EntityBatchingProducerNode.java index fd8e8ba9..aa0bf413 100755 --- a/source/mir/producer/EntityBatchingProducerNode.java +++ b/source/mir/producer/EntityBatchingProducerNode.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2001, 2002 The Mir-coders group + * Copyright (C) 2001, 2002 The Mir-coders group * * This file is part of Mir. * @@ -18,39 +18,57 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * In addition, as a special exception, The Mir-coders gives permission to link - * the code of this program with the com.oreilly.servlet library, 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 exception - * to your version of the file, but you are not obligated to do so. If you do - * not wish to do so, delete this exception statement from your version. + * 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 + * exception to your version of the file, but you are not obligated to do so. + * If you do not wish to do so, delete this exception statement from your version. */ - package mir.producer; -import java.util.*; -import java.io.*; -import mir.entity.adapter.*; -import mir.entity.*; -import mir.storage.*; -import mir.util.*; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.ArrayList; + +import mir.entity.adapter.EntityAdapterModel; +import mir.entity.adapter.EntityIteratorAdapter; +import mir.log.LoggerWrapper; +import mir.util.ParameterExpander; +import mir.util.StringRoutines; + +/** + *

Title: EntityBatchingProducerNode

+ *

Description: + * This producer makes it possible to show articles in batches, like on archive + * pages. + * + * The order by clause should lead to a result set in reverse order: + * the first row will be the last entity in the last batch + *

+ *

Copyright: Copyright (c) 2003

+ *

Company:

+ * @author not attributable + * @version 1.0 + */ public class EntityBatchingProducerNode implements ProducerNode { - private Map verbs; - private String batchInfoKey; private String batchDataKey; private EntityAdapterModel model; + private String mainTablePrefix; + private String extraTables; private String definition; private String whereClause; private String orderByClause; private String nrEntitiesToSkipExpression; private String nrEntitiesPerBatchExpression; private String minNrEntitiesInFirstBatchExpression; - private String defaultNrBatchesToProcessExpression; + private String nrBatchesToProcessExpression; private ProducerNode batchSubNode; private ProducerNode batchListSubNode; @@ -58,85 +76,52 @@ public class EntityBatchingProducerNode implements ProducerNode { String aBatchDataKey, String aBatchInfoKey, EntityAdapterModel aModel, - 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 aMainTablePrefix, + String someExtraTables, 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; + mainTablePrefix = aMainTablePrefix; + extraTables = someExtraTables; definition = aDefinition; whereClause = aWhereClause; orderByClause = anOrderByClause; nrEntitiesToSkipExpression = anrEntitiesToSkipExpression; nrEntitiesPerBatchExpression = anrEntitiesPerBatchExpression; minNrEntitiesInFirstBatchExpression = aminNrEntitiesInFirstBatchExpression; - defaultNrBatchesToProcessExpression = aDefaultNrBatchesToProcessExpression; + nrBatchesToProcessExpression = aNrBatchesToProcessExpression; } - public void produce(Map aValueMap, String aVerb, PrintWriter aLogger) throws ProducerFailure { - Iterator browser; + 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, LoggerWrapper aLogger) throws ProducerFailure { int nrEntities; int nrBatchesAfterFirst; int nrEntitiesInFirstBatch; int nrBatchesToProcess; List batchesData; int i; - int position; Map batchData; String expandedWhereClause; String expandedOrderByClause; - EntityBatchingProducerNodeVerb verb = (EntityBatchingProducerNodeVerb) verbs.get(aVerb); List batchLocations; BatchLocation location; @@ -145,17 +130,8 @@ public class EntityBatchingProducerNode implements ProducerNode { 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 - - 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 ); @@ -163,11 +139,13 @@ public class EntityBatchingProducerNode implements ProducerNode { nrEntitiesToSkip = ParameterExpander.evaluateIntegerExpression( aValueMap, nrEntitiesToSkipExpression); nrEntitiesPerBatch = ParameterExpander.evaluateIntegerExpression( aValueMap, nrEntitiesPerBatchExpression); minNrEntitiesInFirstBatch = ParameterExpander.evaluateIntegerExpression( aValueMap, minNrEntitiesInFirstBatchExpression); + List extraTableList = StringRoutines.splitString(ParameterExpander.expandExpression( aValueMap, 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).getStorage().getSize( + mainTablePrefix, extraTableList, expandedWhereClause)-nrEntitiesToSkip; nrEntitiesInFirstBatch = nrEntities % nrEntitiesPerBatch; while (nrEntitiesInFirstBatch=nrEntitiesPerBatch) nrEntitiesInFirstBatch = nrEntitiesInFirstBatch + nrEntitiesPerBatch; @@ -196,7 +174,7 @@ public class EntityBatchingProducerNode implements ProducerNode { 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); } @@ -205,7 +183,7 @@ public class EntityBatchingProducerNode implements ProducerNode { } if (batchSubNode!=null) { - for (i=0; i