1 package org.paneris.jammyjoes.mvp;
2
3 import java.util.Date;
4 import java.util.Enumeration;
5
6 import org.melati.poem.Table;
7 import org.paneris.jammyjoes.model.Affiliate;
8 import org.paneris.jammyjoes.util.JammyJoesUtil;
9
10 public class HitsSelection implements Selection {
11
12 private Table _hits;
13 private Affiliate _affiliate;
14 private Date _startDate;
15 private final Date endDate;
16
17 public HitsSelection(Table hits, Affiliate affiliate, Date startDate, Date endDate) {
18 _hits = hits;
19 _affiliate = affiliate;
20 _startDate = startDate;
21 this.endDate = endDate;
22 }
23
24 public void visitEach(Command command) {
25 String selection = "affiliate="+ _affiliate.getTroid();
26 if (_startDate != null) {
27 selection += " and hit >= " + JammyJoesUtil.formatDateForPostgresSQL(_startDate);
28 }
29 if (endDate != null) {
30 selection += " and hit < " + JammyJoesUtil.formatDateForPostgresSQL(endDate);
31 }
32 Enumeration enumeration = _hits.selection(selection);
33 while (enumeration.hasMoreElements()) {
34 command.visit(enumeration.nextElement());
35 }
36
37 }
38 }