1
2
3
4 package com.github.smokestack.jpa;
5
6 import java.sql.Time;
7 import java.sql.Timestamp;
8 import java.util.Calendar;
9 import java.util.Date;
10 import java.util.HashMap;
11 import java.util.List;
12 import java.util.Map;
13
14 import javax.persistence.FlushModeType;
15 import javax.persistence.Query;
16 import javax.persistence.TemporalType;
17
18 import org.apache.commons.lang.builder.ReflectionToStringBuilder;
19 import org.apache.commons.lang.builder.ToStringStyle;
20
21 import com.github.smokestack.exception.NeedsMockDefinitionException;
22 import com.github.smokestack.exception.NotYetImplementedException;
23
24
25
26
27
28
29 public abstract class MockBaseQuery implements Query {
30
31 protected int startPosition;
32 protected FlushModeType flushMode;
33 protected Map<String, Object> hints=new HashMap<String, Object>();
34 protected int maxResult;
35
36
37
38
39 protected MockBaseQuery() {
40 }
41
42
43
44
45 public int executeUpdate() {
46 return _executeUpdate();
47 }
48
49 public int _executeUpdate() {
50 throw new NeedsMockDefinitionException();
51 }
52
53
54
55
56 public List getResultList() {
57 return _getResultList();
58 }
59
60 public List _getResultList() {
61 throw new NeedsMockDefinitionException();
62 }
63
64
65
66
67 public Object getSingleResult() {
68 return _getSingleResult();
69 }
70
71 public Object _getSingleResult() {
72 throw new NeedsMockDefinitionException();
73 }
74
75
76
77
78 public Query setFirstResult(int startPosition) {
79 _setFirstResult(startPosition);
80 this.startPosition=startPosition;
81 return this;
82 }
83
84 public Query _setFirstResult(int startPosition2) {
85 return null;
86 }
87
88
89
90
91 public Query setFlushMode(FlushModeType flushMode) {
92 _setFlushMode(flushMode);
93 this.flushMode=flushMode;
94 return this;
95 }
96
97 public Query _setFlushMode(FlushModeType flushMode) {
98 return null;
99 }
100
101
102
103
104 public Query setHint(String hintName, Object value) {
105 _setHint(hintName, value);
106 hints.put(hintName, value);
107 return this;
108 }
109
110 public Query _setHint(String hintName, Object value) {
111 return null;
112 }
113
114
115
116
117 public Query setMaxResults(int maxResult) {
118 _setMaxResults(maxResult);
119 this.maxResult=maxResult;
120 return this;
121 }
122
123 public Query _setMaxResults(int maxResult) {
124 return null;
125 }
126
127
128
129
130 public Query setParameter(String name, Object value) {
131 _setParameter(name, value);
132 throw new NotYetImplementedException();
133 }
134
135 public Query _setParameter(String name, Object value) {
136 return null;
137 }
138
139
140
141
142 public Query setParameter(int position, Object value) {
143 _setParameter(position, value);
144 return this;
145 }
146
147 public Query _setParameter(int position, Object value) {
148 return null;
149 }
150
151
152
153
154 public Query setParameter(String name, Date value, TemporalType temporalType) {
155 _setParameter(name, value, temporalType);
156 return setParameter(name, getTemporalType(value, temporalType));
157 }
158
159 public Query _setParameter(String name, Date value,
160 TemporalType temporalType) {
161 return null;
162 }
163
164
165
166
167 public Query setParameter(String name, Calendar value, TemporalType temporalType) {
168 _setParameter(name, value, temporalType);
169 return setParameter(name, getTemporalType(value, temporalType));
170 }
171
172 public Query _setParameter(String name, Calendar value,
173 TemporalType temporalType) {
174 return null;
175 }
176
177
178
179
180 public Query setParameter(int position, Date value, TemporalType temporalType) {
181 throw new NotYetImplementedException();
182 }
183
184
185
186
187 public Query setParameter(int position, Calendar value, TemporalType temporalType) {
188 throw new NotYetImplementedException();
189 }
190
191
192
193
194
195
196
197 protected Object getTemporalType(Date value, TemporalType type) {
198 switch (type) {
199 case DATE:
200 return value;
201 case TIME:
202 return new Time(value.getTime());
203 case TIMESTAMP:
204 return new Timestamp(value.getTime());
205 default:
206 return null;
207 }
208 }
209
210
211
212
213
214
215
216 protected Object getTemporalType(Calendar value, TemporalType type) {
217 _getTemporalType(value, type);
218 return getTemporalType(value.getTime(), type);
219 }
220
221 public Object _getTemporalType(Calendar value, TemporalType type) {
222 return null;
223 }
224
225
226
227
228 public String toString(){
229 return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
230 }
231 }