rebuilding head
[mir.git] / source / mir / producer / EntityBatchingProducerNode.java
index b643fa7..aa0bf41 100755 (executable)
  * 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  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.  
+ * 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;
@@ -33,17 +33,35 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Vector;
+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;
+
+/**
+ * <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
+ */
 
 public class EntityBatchingProducerNode implements ProducerNode {
   private String batchInfoKey;
   private String batchDataKey;
   private EntityAdapterModel model;
+  private String mainTablePrefix;
+  private String extraTables;
   private String definition;
   private String whereClause;
   private String orderByClause;
@@ -58,6 +76,8 @@ public class EntityBatchingProducerNode implements ProducerNode {
         String aBatchDataKey,
         String aBatchInfoKey,
         EntityAdapterModel aModel,
+        String aMainTablePrefix,
+        String someExtraTables,
         String aDefinition,
         String aWhereClause,
         String anOrderByClause,
@@ -74,6 +94,8 @@ public class EntityBatchingProducerNode implements ProducerNode {
     batchDataKey = aBatchDataKey;
     batchInfoKey = aBatchInfoKey;
     model = aModel;
+    mainTablePrefix = aMainTablePrefix;
+    extraTables = someExtraTables;
     definition = aDefinition;
     whereClause = aWhereClause;
     orderByClause = anOrderByClause;
@@ -91,14 +113,12 @@ public class EntityBatchingProducerNode implements ProducerNode {
   }
 
   public void produce(Map aValueMap, String aVerb, LoggerWrapper aLogger) throws ProducerFailure {
-    Iterator browser;
     int nrEntities;
     int nrBatchesAfterFirst;
     int nrEntitiesInFirstBatch;
     int nrBatchesToProcess;
     List batchesData;
     int i;
-    int position;
     Map batchData;
     String expandedWhereClause;
     String expandedOrderByClause;
@@ -110,10 +130,6 @@ 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 {
       nrBatchesToProcess = ParameterExpander.evaluateIntegerExpressionWithDefault( aValueMap, nrBatchesToProcessExpression, -1 );
 
@@ -123,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<minNrEntitiesInFirstBatch && nrEntities-nrEntitiesInFirstBatch>=nrEntitiesPerBatch)
         nrEntitiesInFirstBatch = nrEntitiesInFirstBatch + nrEntitiesPerBatch;
@@ -179,9 +197,9 @@ public class EntityBatchingProducerNode implements ProducerNode {
           else
             batchData.put("next", null);
 
-          Iterator j = new EntityIteratorAdapter(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());