19 package com.mysql.clusterj.openjpatest;
21 import com.mysql.clusterj.jpatest.AbstractJPABaseTest;
23 import com.mysql.clusterj.jpatest.model.LongIntStringFKOneOne;
24 import com.mysql.clusterj.jpatest.model.LongIntStringPKOneOne;
25 import com.mysql.clusterj.jpatest.model.LongIntStringOid;
32 private int NUMBER_OF_INSTANCES = 5;
33 private int OFFSET_A = 100;
34 private int OFFSET_B = 10;
40 private boolean print =
false;
59 em = emf.createEntityManager();
62 int countB = em.createQuery(
"DELETE FROM LongIntStringFKOneOne").executeUpdate();
63 int countA = em.createQuery(
"DELETE FROM LongIntStringPKOneOne").executeUpdate();
64 print (
"Deleted " + countB +
" instances of LongLongStringFKManyOne " +
65 countA +
" instances of LongLongStringFKManyOne ");
69 em = emf.createEntityManager();
71 print(
"Creating " + NUMBER_OF_INSTANCES +
" instances of LongIntStringPKOneOne and LongIntStringFKOneOne.");
72 for (
int i = 0;
i < NUMBER_OF_INSTANCES; ++
i) {
75 a.setLongIntStringFKOneOne(b);
76 b.setLongIntStringPKOneOne(a);
85 em = emf.createEntityManager();
87 print(
"Checking " + NUMBER_OF_INSTANCES +
" instances.");
88 for (
int i = 0;
i < NUMBER_OF_INSTANCES; ++
i) {
91 errorIfNull(
"Instance of LongIntStringPKOneOne for value " + (OFFSET_A +
i) +
" was not found.", a);
92 errorIfNull(
"Instance of LongIntStringFKOneOne for value " + (OFFSET_B +
i) +
" was not found.", b);
93 if (b != null && a != null) {
94 errorIfNotEqual(
"Mismatch in longIntStringFKOneOne.getLongIntStringPKOneOne",
95 a, b.getLongIntStringPKOneOne());
96 errorIfNotEqual(
"Mismatch in longIntStringPKOneOne.getLongIntStringFKOneOne",
97 b, a.getLongIntStringFKOneOne());
103 em = emf.createEntityManager();
104 print(
"Deleting some instances.");
109 b.setLongIntStringPKOneOne(null);
113 a.setLongIntStringFKOneOne(null);
118 em = emf.createEntityManager();
120 print(
"Checking deleted instances.");
122 errorIfNotEqual(
"finding deleted instance of LongIntStringPK should return null", null, a);
124 errorIfNotEqual(
"finding deleted instance of LongIntStringFK should return null", null, b);
127 errorIfNull(
"Instance of LongIntStringPKOneOne for value " + (OFFSET_A + 1) +
" was not found.", a);
128 errorIfNull(
"Instance of LongIntStringFKOneOne for value " + (OFFSET_B + 0) +
" was not found.", b);
129 if (b != null && a != null) {
130 errorIfNotEqual(
"field longIntStringFKOneOne should be null",
131 null, a.getLongIntStringFKOneOne());
132 errorIfNotEqual(
"field longIntStringPKOneOne should be null",
133 null, b.getLongIntStringPKOneOne());
138 em = emf.createEntityManager();
140 print(
"Setting fields to null");
143 b.setLongIntStringPKOneOne(null);
144 a.setLongIntStringFKOneOne(null);
148 em = emf.createEntityManager();
150 print(
"Checking fields set to null.");
153 if (b != null && a != null) {
154 errorIfNotEqual(
"field longIntStringFKOneOne should be null",
155 null, a.getLongIntStringFKOneOne());
156 errorIfNotEqual(
"field longIntStringPKOneOne should be null",
157 null, b.getLongIntStringPKOneOne());
162 em = emf.createEntityManager();
164 print(
"Swapping references.");
169 a3.setLongIntStringFKOneOne(b4);
170 b4.setLongIntStringPKOneOne(a3);
171 a4.setLongIntStringFKOneOne(b3);
172 b3.setLongIntStringPKOneOne(a4);
173 errorIfNotEqual(
"Swapped field b4.longIntStringPKOneOne should be a3",
174 a3, b4.getLongIntStringPKOneOne());
175 errorIfNotEqual(
"Swapped field a3.longIntStringFKOneOne should be b4",
176 b4, a3.getLongIntStringFKOneOne());
177 errorIfNotEqual(
"Swapped field b3.longIntStringPKOneOne should be a4",
178 a4, b3.getLongIntStringPKOneOne());
179 errorIfNotEqual(
"Swapped field a4.longIntStringFKOneOne should be b3",
180 b3, a4.getLongIntStringFKOneOne());
184 em = emf.createEntityManager();
186 print(
"Checking swapped references.");
191 errorIfNotEqual(
"Swapped field b4.longIntStringPKOneOne should be a3",
192 a3, b4.getLongIntStringPKOneOne());
193 errorIfNotEqual(
"Swapped field a3.longIntStringFKOneOne should be b4",
194 b4, a3.getLongIntStringFKOneOne());
195 errorIfNotEqual(
"Swapped field b3.longIntStringPKOneOne should be a4",
196 a4, b3.getLongIntStringPKOneOne());
197 errorIfNotEqual(
"Swapped field a4.longIntStringFKOneOne should be b3",
198 b3, a4.getLongIntStringFKOneOne());
204 private void print(
String string) {
206 System.out.println(
string);
215 errorIfNotEqual(
"Mismatch longpk", oid.longpk, instance.getLongpk());
216 errorIfNotEqual(
"Mismatch intpk", oid.intpk, instance.getIntpk());
217 errorIfNotEqual(
"Mismatch stringpk", oid.stringpk, instance.getStringpk());