18 package testsuite.clusterj;
20 import com.mysql.clusterj.Query;
22 import com.mysql.clusterj.query.QueryDomainType;
23 import com.mysql.clusterj.query.Predicate;
24 import com.mysql.clusterj.query.QueryBuilder;
26 import java.util.ArrayList;
27 import java.util.HashSet;
28 import java.util.List;
31 import testsuite.clusterj.model.Dn2id;
35 private static final int NUMBER_OF_INSTANCES = 10;
67 createSessionFactory();
73 }
catch (Throwable t) {
76 addTearDownClasses(
Dn2id.class);
79 protected void setupQuery() {
86 equalA0 = dobj.get(
"a0").equal(dobj.param(
"a0"));
87 equalA1 = dobj.get(
"a1").equal(dobj.param(
"a1"));
88 equalA2 = dobj.get(
"a2").equal(dobj.param(
"a2"));
89 equalA3 = dobj.get(
"a3").equal(dobj.param(
"a3"));
90 lessA3 = dobj.get(
"a3").lessThan(dobj.param(
"a3Upper"));
91 lessEqualA3 = dobj.get(
"a3").lessEqual(dobj.param(
"a3Upper"));
92 greaterA3 = dobj.get(
"a3").greaterThan(dobj.param(
"a3Lower"));
93 greaterEqualA3 = dobj.get(
"a3").greaterEqual(dobj.param(
"a3Lower"));
94 betweenA3 = dobj.get(
"a3").between(dobj.param(
"a3Lower"), dobj.param(
"a3Upper"));
95 equalA4 = dobj.get(
"a4").equal(dobj.param(
"a4"));
96 equalA5 = dobj.get(
"a5").equal(dobj.param(
"a5"));
97 equalA6 = dobj.get(
"a6").equal(dobj.param(
"a6"));
98 equalA7 = dobj.get(
"a7").equal(dobj.param(
"a7"));
99 equalA8 = dobj.get(
"a8").equal(dobj.param(
"a8"));
100 equalA9 = dobj.get(
"a9").equal(dobj.param(
"a9"));
101 equalA10 = dobj.get(
"a10").equal(dobj.param(
"a10"));
102 equalA11 = dobj.get(
"a11").equal(dobj.param(
"a11"));
103 equalA12 = dobj.get(
"a12").equal(dobj.param(
"a12"));
104 equalA13 = dobj.get(
"a13").equal(dobj.param(
"a13"));
105 equalA14 = dobj.get(
"a14").equal(dobj.param(
"a14"));
106 equalA15 = dobj.get(
"a15").equal(dobj.param(
"a15"));
112 queryEqualPartialPrimaryKey();
113 queryLessEqualGreaterEqualPartialPrimaryKey();
114 queryLessGreaterEqualPartialPrimaryKey();
115 queryLessEqualGreaterPartialPrimaryKey();
116 queryLessGreaterPartialPrimaryKey();
117 queryBetweenPartialPrimaryKey();
118 queryCompletePrimaryKey();
125 private void insert() {
126 createDn2idInstances(NUMBER_OF_INSTANCES);
133 protected void findByPrimaryKey() {
135 for (
int i = 0;
i < NUMBER_OF_INSTANCES; ++
i) {
136 dn2idPK[1] = getA1for(NUMBER_OF_INSTANCES,
i);
137 dn2idPK[3] =
"employeenumber=100000" +
i;
138 Dn2id d = session.
find(Dn2id.class, dn2idPK);
141 long actual = d.getEid();
142 if (expected != actual) {
143 error(
"findByPrimaryKey failed to find dn2id " +
i
144 +
" expected eid " + expected
145 +
" actual eid " + actual);
151 private void queryEqualPartialPrimaryKey() {
155 dobj.where(equalA0.
and(equalA1.
and(equalA2.
and(equalA3))));
160 query.setParameter(
"a0",
"dc=com");
161 query.setParameter(
"a1", getA1for(NUMBER_OF_INSTANCES, 8));
162 query.setParameter(
"a2",
"ou=people");
163 query.setParameter(
"a3", getA3for(8));
167 consistencyCheck(results);
169 Set<Long> expected =
new HashSet<Long>();
170 expected.add((
long)8);
172 for (Dn2id d: results) {
173 actual.add(d.getEid());
175 errorIfNotEqual(
"queryEqualPartialPrimaryKey wrong Dn2id eids returned from query: ",
180 private void queryLessEqualGreaterEqualPartialPrimaryKey() {
184 dobj.where(equalA0.
and(equalA1.
and(equalA2.
and(
185 lessEqualA3.
and(greaterEqualA3)))));
190 query.setParameter(
"a0",
"dc=com");
191 query.setParameter(
"a1", getA1for(NUMBER_OF_INSTANCES, 8));
192 query.setParameter(
"a2",
"ou=people");
193 query.setParameter(
"a3Upper", getA3for(9));
194 query.setParameter(
"a3Lower", getA3for(8));
198 consistencyCheck(results);
200 Set<Long> expected =
new HashSet<Long>();
201 expected.add((
long)8);
202 expected.add((
long)9);
204 for (Dn2id d: results) {
205 actual.add(d.getEid());
207 errorIfNotEqual(
"queryLessEqualGreaterEqualPartialPrimaryKey wrong Dn2id eids returned from query: ",
212 private void queryLessGreaterEqualPartialPrimaryKey() {
216 dobj.where(equalA0.
and(equalA1.
and(equalA2.
and(
217 lessA3.
and(greaterEqualA3)))));
222 query.setParameter(
"a0",
"dc=com");
223 query.setParameter(
"a1", getA1for(NUMBER_OF_INSTANCES, 8));
224 query.setParameter(
"a2",
"ou=people");
225 query.setParameter(
"a3Lower", getA3for(8));
226 query.setParameter(
"a3Upper", getA3for(9));
230 consistencyCheck(results);
232 Set<Long> expected =
new HashSet<Long>();
233 expected.add((
long)8);
235 for (Dn2id d: results) {
236 actual.add(d.getEid());
238 errorIfNotEqual(
"queryLessGreaterEqualPartialPrimaryKey wrong Dn2id eids returned from query: ",
243 private void queryLessEqualGreaterPartialPrimaryKey() {
247 dobj.where(equalA0.
and(equalA1.
and(equalA2.
and(
248 lessEqualA3.
and(greaterA3)))));
253 query.setParameter(
"a0",
"dc=com");
254 query.setParameter(
"a1", getA1for(NUMBER_OF_INSTANCES, 8));
255 query.setParameter(
"a2",
"ou=people");
256 query.setParameter(
"a3Lower", getA3for(7));
257 query.setParameter(
"a3Upper", getA3for(8));
261 consistencyCheck(results);
263 Set<Long> expected =
new HashSet<Long>();
264 expected.add((
long)8);
266 for (Dn2id d: results) {
267 actual.add(d.getEid());
269 errorIfNotEqual(
"queryLessEqualGreaterPartialPrimaryKey wrong Dn2id eids returned from query: ",
274 private void queryLessGreaterPartialPrimaryKey() {
278 dobj.where(equalA0.
and(equalA1.
and(equalA2.
and(
279 lessA3.
and(greaterA3)))));
284 query.setParameter(
"a0",
"dc=com");
285 query.setParameter(
"a1", getA1for(NUMBER_OF_INSTANCES, 8));
286 query.setParameter(
"a2",
"ou=people");
287 query.setParameter(
"a3Lower", getA3for(7));
288 query.setParameter(
"a3Upper", getA3for(9));
292 consistencyCheck(results);
294 Set<Long> expected =
new HashSet<Long>();
295 expected.add((
long)8);
297 for (Dn2id d: results) {
298 actual.add(d.getEid());
300 errorIfNotEqual(
"queryLessGreaterPartialPrimaryKey wrong Dn2id eids returned from query: ",
305 private void queryBetweenPartialPrimaryKey() {
309 dobj.where(equalA0.
and(equalA1.
and(equalA2.
and(
315 query.setParameter(
"a0",
"dc=com");
316 query.setParameter(
"a1", getA1for(NUMBER_OF_INSTANCES, 8));
317 query.setParameter(
"a2",
"ou=people");
318 query.setParameter(
"a3Lower", getA3for(8));
319 query.setParameter(
"a3Upper", getA3for(9));
323 consistencyCheck(results);
325 Set<Long> expected =
new HashSet<Long>();
326 expected.add((
long)8);
327 expected.add((
long)9);
329 for (Dn2id d: results) {
330 actual.add(d.getEid());
332 errorIfNotEqual(
"queryBetweenPartialPrimaryKey wrong Dn2id eids returned from query: ",
337 private void queryCompletePrimaryKey() {
342 dobj.where(equalA0.
and(equalA1.
and(equalA2.
and(equalA3)))
344 .and(equalA8.
and(equalA9.
and(equalA10.
and(equalA11))))
345 .and(equalA12.
and(equalA13.
and(equalA14.
and(equalA15)))));
350 query.setParameter(
"a0",
"dc=com");
351 query.setParameter(
"a1", getA1for(NUMBER_OF_INSTANCES, 8));
352 query.setParameter(
"a2",
"ou=people");
353 query.setParameter(
"a3", getA3for(8));
354 query.setParameter(
"a4",
"");
355 query.setParameter(
"a5",
"");
356 query.setParameter(
"a6",
"");
357 query.setParameter(
"a7",
"");
358 query.setParameter(
"a8",
"");
359 query.setParameter(
"a9",
"");
360 query.setParameter(
"a10",
"");
361 query.setParameter(
"a11",
"");
362 query.setParameter(
"a12",
"");
363 query.setParameter(
"a13",
"");
364 query.setParameter(
"a14",
"");
365 query.setParameter(
"a15",
"");
369 consistencyCheck(results);
371 Set<Long> expected =
new HashSet<Long>();
372 expected.add((
long)8);
374 for (Dn2id d: results) {
375 actual.add(d.getEid());
377 errorIfNotEqual(
"queryCompletePrimaryKey wrong Dn2id eids returned from query: ",
382 private void queryUniqueKey() {
383 throw new UnsupportedOperationException(
"Not yet implemented");
391 List<Dn2id> updatedInstances =
new ArrayList<Dn2id>();
392 for (
int i = 0;
i < NUMBER_OF_INSTANCES; ++
i) {
393 dn2idPK[1] = getA1for(NUMBER_OF_INSTANCES,
i);
394 dn2idPK[3] =
"employeenumber=100000" +
i;
398 long actual = d.getEid();
399 if (expected != actual) {
400 error(
"Failed to find dn2id " +
i
401 +
" expected eid " + expected
402 +
" actual eid " + actual);
405 d.setEid(NUMBER_OF_INSTANCES + d.getEid());
406 updatedInstances.add(d);
412 for (
int i = 0;
i < NUMBER_OF_INSTANCES; ++
i) {
413 dn2idPK[1] = getA1for(NUMBER_OF_INSTANCES,
i);
414 dn2idPK[3] =
"employeenumber=100000" +
i;
417 long expected = NUMBER_OF_INSTANCES +
i;
418 long actual = d.getEid();
419 if (expected != actual) {
420 error(
"Failed to find updated dn2id " + i
421 +
" expected eid " + expected
422 +
" actual eid " + actual);
428 private void delete() {
430 for (
int i = 0;
i < NUMBER_OF_INSTANCES; ++
i) {
431 dn2idPK[1] = getA1for(NUMBER_OF_INSTANCES,
i);
432 dn2idPK[3] =
"employeenumber=100000" +
i;