1
2
3
4
5
6
7
8
9 package ca.uhn.cache.internal.hibernate.impl;
10
11 import java.text.MessageFormat;
12 import java.util.HashMap;
13 import java.util.Map;
14
15 import ca.uhn.cache.IGroupQueryParam;
16 import ca.uhn.cache.IPointQueryParam;
17 import ca.uhn.cache.impl.DateParam;
18 import ca.uhn.cache.impl.DateRangeParam;
19 import ca.uhn.cache.internal.hibernate.IQueryParamHelper;
20
21
22 /***
23 * @author <a href="mailto:alexei.guevara@uhn.on.ca">Alexei Guevara</a>
24 * @version $Revision: 1.1 $ updated on $Date: 2005/01/24 22:52:40 $ by $Author: bryan_tripp $
25 */
26 public class DateParamHelper implements IQueryParamHelper {
27
28 /***
29 */
30 public DateParamHelper() {
31 }
32
33 /***
34 * {@inheritDoc}
35 */
36 public Field createField( Record theRecord, IPointQueryParam theQueryParam ) {
37 assert theQueryParam instanceof DateParam;
38
39 return new DateParamField( theRecord, (DateParam) theQueryParam );
40 }
41
42 /***
43 * {@inheritDoc}
44 */
45 public Class getFieldClass() {
46 return DateParamField.class;
47 }
48
49 /***
50 * {@inheritDoc}
51 */
52 public String generateHql( IPointQueryParam thePointQueryParam, int theIndex ) {
53 assert thePointQueryParam instanceof DateParam;
54
55 return MessageFormat.format(
56 "( f.record = f{0}.record " +
57 "AND f{0}.dimensionName = :f{0}dimensionName " +
58 "AND f{0}.value = :f{0}value )",
59 new Object[] { new Integer(theIndex) } );
60 }
61
62 /***
63 * {@inheritDoc}
64 */
65 public Map generateHqlParamMap( IPointQueryParam thePointQueryParam, int theIndex ) {
66 assert thePointQueryParam instanceof DateParam;
67
68 Map retVal = new HashMap();
69
70 DateParam dp = (DateParam) thePointQueryParam;
71
72 retVal.put(
73 MessageFormat.format( "f{0}dimensionName", new Object[] { new Integer( theIndex ) } ),
74 dp.getDimension().getName() );
75
76 retVal.put(
77 MessageFormat.format( "f{0}value", new Object[] { new Integer( theIndex ) } ),
78 dp.getValue() );
79
80 return retVal;
81 }
82
83 /***
84 * {@inheritDoc}
85 */
86 public String generateHql( IGroupQueryParam theGroupQueryParam, int theIndex ) {
87 assert theGroupQueryParam instanceof DateRangeParam;
88
89 return MessageFormat.format(
90 "( f.record = f{0}.record " +
91 "AND f{0}.dimensionName = :f{0}dimensionName " +
92 "AND f{0}.value >= :f{0}start " +
93 "AND f{0}.value <= :f{0}end )",
94 new Object[] { new Integer(theIndex) } );
95 }
96
97 /***
98 * {@inheritDoc}
99 */
100 public Map generateHqlParamMap( IGroupQueryParam theGroupQueryParam, int theIndex ) {
101 assert theGroupQueryParam instanceof DateRangeParam;
102
103 Map retVal = new HashMap();
104
105 DateRangeParam drp = (DateRangeParam) theGroupQueryParam;
106
107 retVal.put(
108 MessageFormat.format( "f{0}dimensionName", new Object[] { new Integer( theIndex ) } ),
109 drp.getDimension().getName() );
110
111 retVal.put(
112 MessageFormat.format( "f{0}start", new Object[] { new Integer( theIndex ) } ),
113 drp.getStart() );
114
115 retVal.put(
116 MessageFormat.format( "f{0}end", new Object[] { new Integer( theIndex ) } ),
117 drp.getEnd() );
118
119 return retVal;
120 }
121
122 }