1 /*package mir.producer;
5 import mir.entity.adapter.*;
10 // abstract public int getSize(String where) throws SQLException,StorageObjectException;
13 public class EntityBatchingProducerNode implements ProducerNode {
15 private EntityBatchingProducerNodeVerb defaultVerb;
18 private StorageObject storage;
19 private EntityAdapterDefinition definition;
20 private String whereClause;
21 private String orderByClause;
22 private int nrArticlesPerBatch;
23 private int minNrArticlesInFirstBatch;
24 private ProducerNode batchSubNode;
25 private ProducerNode batchListSubNode;
27 public EntityBatchingProducerNode(
29 StorageObject aStorage,
30 EntityAdapterDefinition aDefinition,
32 String anOrderByClause,
33 int aNrArticlesPerBatch,
34 int aMinNrArticlesInFirstBatch,
35 ProducerNode aBatchSubNode,
36 ProducerNode aBatchListSubNode) {
38 batchSubNode = aBatchSubNode;
39 batchListSubNode = aBatchListSubNode;
42 verbs = new HashMap();
46 definition = aDefinition;
47 whereClause = aWhereClause;
48 orderByClause = anOrderByClause;
49 nrArticlesPerBatch = aNrArticlesPerBatch;
50 minNrArticlesInFirstBatch = aMinNrArticlesInFirstBatch;
53 public void produce(Map aValueMap, String aVerb, PrintWriter aLogger) throws ProducerFailure {
54 EntityBatchingProducerNodeVerb verb = (EntityBatchingProducerNodeVerb) verbs.get(aVerb);
61 throw new ProducerFailure("EntityBatchingProducerNode: unknown verb '"+aVerb+"'", null);
64 browser = new EntityIteratorAdapter(
66 ParameterExpander.expandExpression( aValueMap, verb.whereClause ),
67 ParameterExpander.expandExpression( aValueMap, verb.orderByClause ),
71 while (browser.hasNext()) {
72 aLogger.println( verb.whereClause + ": next... ");
73 aValueMap.put(key, browser.next());
74 super.produce(aValueMap, aVerb, aLogger);
78 throw new ProducerFailure(t.getMessage(), t);
82 public Set buildVerbSet() {
85 set = super.buildVerbSet();
86 set.addAll(verbs.keySet());
91 public void addVerb(String aVerb, String aWhereClause, String anOrderByClause) {
92 verbs.put(aVerb, new EntityBatchingProducerNodeVerb(aWhereClause, anOrderByClause));
96 // int nrPagesToGenerate
99 private class EntityBatchingProducerNodeVerb {
100 int nrPagesToGenerate;
102 EntityBatchingProducerNodeVerb(String aWhereClause, String anOrderByClause) {
103 whereClause = aWhereClause;
104 orderByClause = anOrderByClause;