18 package testsuite.clusterj;
20 import java.util.ArrayList;
21 import java.util.List;
23 import com.mysql.clusterj.ClusterJUserException;
24 import com.mysql.clusterj.DynamicObject;
26 import testsuite.clusterj.model.Employee;
30 private static final String tablename =
"t_basic";
32 private static final int NUMBER_TO_INSERT = 3;
34 List<DynamicEmployee> loaded =
new ArrayList<DynamicEmployee>();
38 createSessionFactory();
40 createEmployeeInstances(NUMBER_TO_INSERT);
52 findFoundAutocommit();
61 private void create() {
65 for (
int i = 0;
i < NUMBER_TO_INSERT; ++
i) {
75 for (
int i = 0;
i < NUMBER_TO_INSERT; ++
i) {
77 errorIfNotEqual(
"load after create new employee id mismatch",
i, e.getId());
78 errorIfNotEqual(
"load before load found mismatch", null, session.
found(e));
80 errorIfNotEqual(
"load after load newInstance employee id mismatch",
i, e.getId());
81 errorIfNotEqual(
"load after load found mismatch", null, session.
found(e));
85 for (
int i = 0;
i < NUMBER_TO_INSERT; ++
i) {
87 errorIfNotEqual(
"load after flush found mismatch",
true, session.
found(e));
89 errorIfNotEqual(
"load after flush employee id mismatch",
i, e.getId());
91 consistencyCheckDynamicEmployee(e);
96 private void loadFindNoFlush() {
100 for (
int i = 0;
i < NUMBER_TO_INSERT; ++
i) {
102 errorIfNotEqual(
"loadFindNoFlush after newInstance employee id mismatch",
i, e.getId());
103 errorIfNotEqual(
"loadFindNoFlush after newInstance found mismatch", null, session.
found(e));
105 errorIfNotEqual(
"loadFindNoFlush after load employee id mismatch",
i, e.getId());
106 errorIfNotEqual(
"loadFindNoFlush after load found mismatch", null, session.
found(e));
110 for (
int i = 0;
i < NUMBER_TO_INSERT; ++
i) {
112 errorIfNotEqual(
"loadFindNoFlush after find found mismatch",
true, session.
found(e));
114 errorIfNotEqual(
"loadFindNoFlush after find employee id mismatch",
i, e.getId());
116 consistencyCheckDynamicEmployee(e);
121 private void consistencyCheckDynamicEmployee(DynamicEmployee e) {
124 errorIfNotEqual(
"consistencyCheckDynamicEmployee name mismatch",
"Employee number " +
id, name);
125 errorIfNotEqual(
"consistencyCheckDynamicEmployee age mismatch",
id, e.getAge());
126 errorIfNotEqual(
"consistencyCheckDynamicEmployee magic mismatch",
id, e.getMagic());
129 private void loadNoFlush() {
134 errorIfNotEqual(
"loadNoFlush after newInstance employee id mismatch", 0, e.getId());
136 errorIfNotEqual(
"loadNoFlush after load employee id mismatch", 0, e.getId());
137 errorIfNotEqual(
"loadNoFlush after load employee name mismatch",
145 private void loadAutocommit() {
146 DynamicEmployee e = session.
newInstance(DynamicEmployee.class, 0);
149 error(
"loadAutocommit expected exception not thrown: a transaction must be in progress for load.");
150 }
catch (ClusterJUserException ex) {
158 private void loadNotFound() {
161 DynamicEmployee e = session.
newInstance(DynamicEmployee.class, 10000);
163 errorIfNotEqual(
"loadNotFound dynamic after load found mismatch", null, session.
found(e));
165 errorIfNotEqual(
"loadNotFound dynamic after flush found mismatch",
false, session.
found(e));
172 private void findFound() {
175 DynamicEmployee e = session.
find(DynamicEmployee.class, 0);
176 errorIfNotEqual(
"findFound dynamic existing found mismatch",
true, session.
found(e));
178 errorIfNotEqual(
"findFound existing found mismatch",
true, session.
found(emp));
185 private void findFoundAutocommit() {
187 DynamicEmployee e = session.
find(DynamicEmployee.class, 0);
188 errorIfNotEqual(
"findFoundAutocommit dynamic existing found mismatch",
true, session.
found(e));
190 errorIfNotEqual(
"findFoundAutocommit existing found mismatch",
true, session.
found(emp));
193 private void foundIllegalType() {
196 session.
found(Integer.valueOf(0));
197 error(
"foundIllegalType expected exception not thrown: ClusterJUserException");
198 }
catch(ClusterJUserException ex) {
203 private void foundNull() {
204 errorIfNotEqual(
"foundNull found mismatch", null, session.
found(null));
207 public static class DynamicEmployee
extends DynamicObject {
209 public DynamicEmployee() {}
216 return (Integer)
get(0);
221 public int getAge() {
222 return (Integer)
get(2);
224 public int getMagic() {
225 return (Integer)
get(3);