View Javadoc

1   package org.paneris.jammyjoes.controller;
2   
3   import java.util.Vector;
4   
5   import org.melati.poem.util.EnumUtils;
6   import org.melati.poem.util.PagedEnumeration;
7   import org.melati.util.StringUtils;
8   import org.paneris.jammyjoes.model.JammyjoesDatabase;
9   
10  /**
11   * @author Tim
12   *
13   * To change this generated comment edit the template variable "typecomment":
14   * Window>Preferences>Java>Templates.
15   * To enable and disable the creation of type comments go to
16   * Window>Preferences>Java>Code Generation.
17   */
18  public class ProductSearch {
19    
20    private JammyjoesDatabase db;
21    private int maxHits;
22    private Logger logger;
23    
24    public ProductSearch(JammyjoesDatabase db, int maxHits, Logger logger) {
25      this.db = db;
26      this.maxHits = maxHits;
27      this.logger = logger;
28    }
29  
30    public PagedEnumeration doSearch(SearchCriteria criteria) {
31      Vector where = new Vector();
32      criteria.constrain(where);
33      where.add(q("retailpriceincvat") + " IS NOT NULL");
34      String whereClause = EnumUtils.concatenated(" AND ", where.elements());
35      logger.logWhereClause(whereClause);
36      PagedEnumeration results = db.getProductTable().unFiltetredSelection(whereClause, criteria.order(), false, 0, maxHits);
37      logger.logHits(results.getTotalCount());
38      return results;
39    }
40  
41    public String q(String name) {
42      StringBuffer b = new StringBuffer();
43      StringUtils.appendQuoted(b, name, '"');
44      return b.toString();
45    }
46  
47  }