19 package com.mysql.clusterj.openjpatest;
21 import com.mysql.clusterj.jpatest.AbstractJPABaseTest;
22 import com.mysql.clusterj.jpatest.model.A;
23 import com.mysql.clusterj.jpatest.model.B0;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.HashSet;
27 import java.util.List;
34 private int NUMBER_OF_A = 2;
35 private int OFFSET_A = 100;
36 private int NUMBER_OF_B = 4;
37 private int OFFSET_B = 10;
40 private boolean print =
false;
41 private List<A> as =
new ArrayList<A>();
49 em = emf.createEntityManager();
50 print(
"Removing " + NUMBER_OF_A +
" instances of A.");
52 for (
int i = OFFSET_A;
i < OFFSET_A + NUMBER_OF_A; ++
i) {
53 A a = em.find(
A.class,
i);
56 print(
"Removing " + NUMBER_OF_B +
" instances of B.");
57 for (
int i = OFFSET_B;
i < OFFSET_B + NUMBER_OF_B; ++
i) {
58 B0 b = em.find(
B0.class,
i);
64 em = emf.createEntityManager();
66 Collection<B0> bs =
new HashSet<B0>();
67 print(
"Creating " + NUMBER_OF_A +
" instances of A.");
68 for (
int i = OFFSET_A;
i < OFFSET_A + NUMBER_OF_A; ++
i) {
72 print(
"Creating " + NUMBER_OF_B +
" instances of B.");
73 for (
int i = OFFSET_B;
i < OFFSET_B + NUMBER_OF_B; ++
i) {
80 print(
"Before commit, " + a0.toString());
81 for (
B0 b:bs){print(b.toString());}
85 em = emf.createEntityManager();
86 print(
"Finding " + NUMBER_OF_A +
" instances of A.");
88 for (
int i = OFFSET_A;
i < OFFSET_A + NUMBER_OF_A; ++
i) {
89 a0 = em.find(
A.class,
i);
92 print(
"Finding " + NUMBER_OF_B +
" instances of B.");
93 for (
int i = OFFSET_B;
i < OFFSET_B + NUMBER_OF_B; ++
i) {
94 B0 b = em.find(
B0.class,
i);
100 em = emf.createEntityManager();
101 print(
"Finding 1 instance of A.");
103 A a = em.find(
A.class, OFFSET_A);
104 print(
"Finding 2 instances of B.");
105 for (
int i = OFFSET_B;
i < OFFSET_B + NUMBER_OF_B;
i += 2) {
106 B0 b = em.find(
B0.class,
i);
111 print(
"After update: " + a0.toString());
115 em = emf.createEntityManager();
116 print(
"Finding " + NUMBER_OF_A +
" instances of A.");
118 for (
int i = OFFSET_A;
i < OFFSET_A + NUMBER_OF_A; ++
i) {
119 a = em.find(
A.class,
i);
123 print(
"Finding " + NUMBER_OF_B +
" instances of B.");
124 for (
int i = OFFSET_B;
i < OFFSET_B + NUMBER_OF_B; ++
i) {
125 B0 b = em.find(
B0.class,
i);
128 assertEquals(
"Mismatch in relationship a", as.get(0), b.getA());
129 assertTrue(
"A.b0s should contain b", as.get(0).getB0s().contains(b));
131 assertEquals(
"Mismatch in relationship a", as.get(1), b.getA());
132 assertTrue(
"A.b0s should contain b", as.get(1).getB0s().contains(b));
140 private void print(
String string) {
142 System.out.println(
string);