19 package com.mysql.clusterj.openjpatest;
21 import com.mysql.clusterj.jpatest.AbstractJPABaseTest;
22 import com.mysql.clusterj.jpatest.model.LongLongStringFKManyOne;
23 import com.mysql.clusterj.jpatest.model.LongLongStringPKOneMany;
24 import com.mysql.clusterj.jpatest.model.LongLongStringOid;
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.HashSet;
28 import java.util.List;
35 private int NUMBER_OF_A = 2;
36 private int OFFSET_A = 100;
37 private int NUMBER_OF_B = 4;
38 private int OFFSET_B = 10;
41 private List<LongLongStringPKOneMany> as =
new ArrayList<LongLongStringPKOneMany>();
44 private boolean print =
false;
61 em = emf.createEntityManager();
64 int countB = em.createQuery(
"DELETE FROM LongLongStringFKManyOne").executeUpdate();
65 int countA = em.createQuery(
"DELETE FROM LongLongStringPKOneMany").executeUpdate();
66 print (
"Deleted " + countB +
" instances of LongLongStringFKManyOne " +
67 countA +
" instances of LongLongStringFKManyOne ");
71 em = emf.createEntityManager();
73 print(
"Creating " + NUMBER_OF_A +
" instances of LongLongStringPKOneMany.");
74 for (
int i = OFFSET_A;
i < OFFSET_A + NUMBER_OF_A; ++
i) {
78 Collection<LongLongStringFKManyOne> bs =
new HashSet<LongLongStringFKManyOne>();
79 print(
"Creating " + NUMBER_OF_B +
" instances of LongLongStringFKManyOne.");
80 for (
int i = OFFSET_B;
i < OFFSET_B + NUMBER_OF_B; ++
i) {
82 b.setLongLongStringPKRelationship(a0);
86 a0.setLongLongStringFKRelationships(bs);
87 print(
"Before commit, " + a0.toString());
92 em = emf.createEntityManager();
93 print(
"Finding " + NUMBER_OF_A +
" instances of LongLongStringPKOneMany.");
95 for (
int i = OFFSET_A;
i < OFFSET_A + NUMBER_OF_A; ++
i) {
99 print(
"Finding " + NUMBER_OF_B +
" instances of LongLongStringFKManyOne.");
100 for (
int i = OFFSET_B;
i < OFFSET_B + NUMBER_OF_B; ++
i) {
109 em = emf.createEntityManager();
110 print(
"Finding 1 instance of A.");
114 print(
"Finding 2 instances of B.");
115 for (
int i = OFFSET_B;
i < OFFSET_B + NUMBER_OF_B;
i += 2) {
119 b.setLongLongStringPKRelationship(a);
122 print(
"After update: " + a0.toString());
126 em = emf.createEntityManager();
127 print(
"Finding " + NUMBER_OF_A +
" instances of A.");
129 for (
int i = OFFSET_A;
i < OFFSET_A + NUMBER_OF_A; ++
i) {
135 print(
"Finding " + NUMBER_OF_B +
" instances of B.");
136 for (
int i = OFFSET_B;
i < OFFSET_B + NUMBER_OF_B; ++
i) {
141 errorIfNotEqual(
"Mismatch in relationship longLongStringPKRelationship",
142 as.get(0), b.getLongLongStringPKOneMany());
143 errorIfNotEqual(
"A.longLongStringFKRelationships should contain longLongStringFKRelationship",
144 true, as.get(0).getLongLongStringFKRelationships().contains(b));
146 errorIfNotEqual(
"Mismatch in relationship longLongStringPKRelationship",
147 as.get(1), b.getLongLongStringPKOneMany());
148 errorIfNotEqual(
"A.longLongStringFKRelationships should contain longLongStringFKRelationship",
149 true, as.get(1).getLongLongStringFKRelationships().contains(b));
157 private void print(
String string) {
159 System.out.println(
string);
168 errorIfNotEqual(
"Mismatch longpk1", oid.longpk1, instance.getLongpk1());
169 errorIfNotEqual(
"Mismatch longpk2", oid.longpk2, instance.getLongpk2());
170 errorIfNotEqual(
"Mismatch stringpk", oid.stringpk, instance.getStringpk());