19 package testsuite.clusterj;
21 import testsuite.clusterj.model.Dn2id;
22 import com.mysql.clusterj.query.QueryBuilder;
23 import com.mysql.clusterj.query.QueryDomainType;
24 import com.mysql.clusterj.query.Predicate;
25 import com.mysql.clusterj.query.PredicateOperand;
26 import com.mysql.clusterj.Query;
27 import java.util.HashSet;
28 import java.util.List;
30 import testsuite.clusterj.model.Dn2id;
36 createSessionFactory();
39 createDn2idInstances(10);
44 }
catch (Throwable t) {
50 addTearDownClasses(
Dn2id.class);
57 uniqueKeyBetweenQuery();
58 uniqueKeyEqualQuery();
59 uniqueKeyGreaterEqualQuery();
60 uniqueKeyGreaterThanQuery();
61 uniqueKeyLessEqualQuery();
62 uniqueKeyLessThanQuery();
65 public void uniqueKeyEqualQuery() {
85 query.setParameter(
"eid", (
long)8);
87 List<Dn2id> results = query.getResultList();
89 consistencyCheck(results);
90 Set<Long> expected =
new HashSet<Long>();
91 expected.add((
long)8);
92 Set<Long> actual =
new HashSet<Long>();
93 for (
Dn2id dn2id: results) {
94 actual.add(dn2id.getEid());
96 errorIfNotEqual(
"Wrong Dn2id eids returned from uniqueKeyEqualQuery query: ",
101 public void uniqueKeyGreaterThanQuery() {
110 PredicateOperand param = dobj.param(
"eid");
112 PredicateOperand column = dobj.get(
"eid");
114 Predicate compare = column.greaterThan(param);
121 query.setParameter(
"eid", (
long)6);
125 consistencyCheck(results);
127 Set<Long> expected =
new HashSet<Long>();
128 expected.add((
long)7);
129 expected.add((
long)8);
130 expected.add((
long)9);
132 for (Dn2id dn2id: results) {
133 actual.add(dn2id.getEid());
135 errorIfNotEqual(
"Wrong Dn2id eids returned from uniqueKeyGreaterThanQuery query: ",
140 public void uniqueKeyGreaterEqualQuery() {
149 PredicateOperand param = dobj.param(
"eid");
151 PredicateOperand column = dobj.get(
"eid");
153 Predicate compare = column.greaterEqual(param);
160 query.setParameter(
"eid", (
long)7);
164 consistencyCheck(results);
166 Set<Long> expected =
new HashSet<Long>();
167 expected.add((
long)7);
168 expected.add((
long)8);
169 expected.add((
long)9);
171 for (Dn2id dn2id: results) {
172 actual.add(dn2id.getEid());
174 errorIfNotEqual(
"Wrong Dn2id eids returned from uniqueKeyGreaterEqualQuery query: ",
179 public void uniqueKeyLessThanQuery() {
188 PredicateOperand param = dobj.param(
"eid");
190 PredicateOperand column = dobj.get(
"eid");
192 Predicate compare = column.lessThan(param);
199 query.setParameter(
"eid", (
long)3);
203 consistencyCheck(results);
205 Set<Long> expected =
new HashSet<Long>();
206 expected.add((
long)0);
207 expected.add((
long)1);
208 expected.add((
long)2);
210 for (Dn2id dn2id: results) {
211 actual.add(dn2id.getEid());
213 errorIfNotEqual(
"Wrong Dn2id eids returned from uniqueKeyLessThanQuery query: ",
218 public void uniqueKeyLessEqualQuery() {
227 PredicateOperand param = dobj.param(
"eid");
229 PredicateOperand column = dobj.get(
"eid");
231 Predicate compare = column.lessEqual(param);
238 query.setParameter(
"eid", (
long)2);
242 consistencyCheck(results);
244 Set<Long> expected =
new HashSet<Long>();
245 expected.add((
long)0);
246 expected.add((
long)1);
247 expected.add((
long)2);
249 for (Dn2id dn2id: results) {
250 actual.add(dn2id.getEid());
252 errorIfNotEqual(
"Wrong Dn2id eids returned from uniqueKeyLessEqualQuery query: ",
257 public void uniqueKeyBetweenQuery() {
266 PredicateOperand lower = dobj.param(
"lower");
268 PredicateOperand upper = dobj.param(
"upper");
270 PredicateOperand column = dobj.get(
"eid");
272 Predicate compare = column.between(lower, upper);
279 query.setParameter(
"lower", (
long)5);
280 query.setParameter(
"upper", (
long)7);
284 consistencyCheck(results);
286 Set<Long> expected =
new HashSet<Long>();
287 expected.add((
long)5);
288 expected.add((
long)6);
289 expected.add((
long)7);
291 for (Dn2id dn2id: results) {
292 actual.add(dn2id.getEid());
294 errorIfNotEqual(
"Wrong Dn2id eids returned from uniqueKeyBetweenQuery query: ",