20 package com.mysql.cluster.crund;
22 import com.mysql.clusterj.ClusterJHelper;
23 import com.mysql.clusterj.Constants;
24 import com.mysql.clusterj.Query;
25 import com.mysql.clusterj.Session;
26 import com.mysql.clusterj.SessionFactory;
27 import com.mysql.clusterj.query.QueryDomainType;
28 import com.mysql.clusterj.query.QueryBuilder;
30 import java.util.Collection;
31 import java.util.Iterator;
32 import java.util.Arrays;
41 protected String mgmdConnect;
52 protected void initProperties() {
53 super.initProperties();
55 out.print(
"setting clusterj properties ...");
57 final StringBuilder
msg =
new StringBuilder();
63 if (msg.length() == 0) {
67 out.print(msg.toString());
71 descr =
"->clusterj(" + mgmdConnect +
")";
75 protected void printProperties() {
76 super.printProperties();
79 out.println(
"clusterj settings ...");
80 out.println(
"ndb.mgmdConnect " + mgmdConnect);
81 for (Iterator<Map.Entry<Object,Object>>
i
82 = props.entrySet().iterator();
i.hasNext();) {
83 Map.Entry<Object,Object> e =
i.next();
85 if (k.startsWith(
"com.mysql.clusterj")) {
86 final StringBuilder s =
new StringBuilder(
"..");
87 s.append(k, 18, k.length());
88 while (s.length() < 31) s.append(
' ');
89 out.println(s +
" " + e.getValue());
95 protected void initLoad()
throws Exception {
100 out.print(
"creating SessionFactory ...");
103 out.println(
" [SessionFactory: 1]");
107 protected void closeLoad()
throws Exception {
109 out.print(
"closing SessionFactory ...");
111 if (sessionFactory != null)
112 sessionFactory.
close();
113 sessionFactory = null;
114 out.println(
" [ok]");
129 public void init() {}
131 public void close() {}
134 protected int checkFields(
IA o) {
135 final int cint = o.getCint();
136 final long clong = o.getClong();
137 verify(clong == cint);
138 final float cfloat = o.getCfloat();
139 verify(cfloat == cint);
140 final double cdouble = o.getCdouble();
141 verify(cdouble == cint);
145 protected int checkFields(
IB0 o) {
146 final int cint = o.getCint();
147 final long clong = o.getClong();
148 verify(clong == cint);
149 final float cfloat = o.getCfloat();
150 verify(cfloat == cint);
151 final double cdouble = o.getCdouble();
152 verify(cdouble == cint);
156 protected void initOperations() {
157 out.print(
"initializing operations ...");
165 new ClusterjOp(
"insA_" +
mode.toString().toLowerCase()) {
166 public void run(
int nOps) {
170 for (
int i = 0;
i < nOps;
i++) {
186 new ClusterjOp(
"insB0_" +
mode.toString().toLowerCase()) {
187 public void run(
int nOps) {
191 for (
int i = 0;
i < nOps;
i++) {
195 o.setCvarbinary_def(null);
208 new ClusterjOp(
"setAByPK_" +
mode.toString().toLowerCase()) {
209 public void run(
int nOps) {
213 for (
int i = 0;
i < nOps;
i++) {
220 o.setCfloat((
float)i);
221 o.setCdouble((
double)i);
234 new ClusterjOp(
"setB0ByPK_" +
mode.toString().toLowerCase()) {
235 public void run(
int nOps) {
239 for (
int i = 0; i < nOps; i++) {
246 o.setCfloat((
float)i);
247 o.setCdouble((
double)i);
260 new ClusterjOp(
"getAByPK_" +
mode.toString().toLowerCase()) {
261 public void run(
int nOps) {
266 for (
int i = 0; i < nOps; i++) {
267 final IA o = session.
find(IA.class, i);
269 final int id = o.getId();
271 final int j = checkFields(o);
275 IA[] objs =
new IA[nOps];
276 for (
int i = 0; i < nOps; ++
i) {
282 for (
int i = 0; i < nOps; ++
i) {
284 final int id = o.getId();
286 final int j = checkFields(o);
297 new ClusterjOp(
"getB0ByPK_" +
mode.toString().toLowerCase()) {
298 public void run(
int nOps) {
303 for (
int i = 0; i < nOps; i++) {
304 final IB0 o = session.
find(IB0.class, i);
306 final int id = o.getId();
308 final int j = checkFields(o);
312 IB0[] objs =
new IB0[nOps];
313 for (
int i = 0; i < nOps; ++
i) {
319 for (
int i = 0; i < nOps; ++
i) {
321 final int id = o.getId();
323 final int j = checkFields(o);
333 for (
int i = 0, l = 1; l <= maxVarbinaryBytes; l *= 10, i++) {
334 final byte[] b = bytes[
i];
335 assert l == b.length;
338 new ClusterjOp(
"setVarbinary" + l +
"_" +
mode.toString().toLowerCase()) {
339 public void run(
int nOps) {
343 for (
int i = 0; i < nOps; i++) {
348 o.setCvarbinary_def(b);
361 new ClusterjOp(
"getVarbinary" + l +
"_" +
mode.toString().toLowerCase()) {
364 public void run(
int nOps) {
368 for (
int i = 0; i < nOps; i++) {
369 final IB0 o = session.
find(IB0.class, i);
371 verify(Arrays.equals(b, o.getCvarbinary_def()));
380 new ClusterjOp(
"clearVarbinary" + l +
"_" +
mode.toString().toLowerCase()) {
381 public void run(
int nOps) {
385 for (
int i = 0; i < nOps; i++) {
390 o.setCvarbinary_def(null);
403 for (
int i = 0, l = 1; l <= maxVarcharChars; l *= 10, i++) {
405 assert l == s.length();
408 new ClusterjOp(
"setVarchar" + l +
"_" +
mode.toString().toLowerCase()) {
409 public void run(
int nOps) {
413 for (
int i = 0; i < nOps; i++) {
418 o.setCvarchar_def(s);
431 new ClusterjOp(
"getVarchar" + l +
"_" +
mode.toString().toLowerCase()) {
434 public void run(
int nOps) {
438 for (
int i = 0; i < nOps; i++) {
439 final IB0 o = session.
find(IB0.class, i);
441 verify(s.equals(o.getCvarchar_def()));
450 new ClusterjOp(
"clearVarchar" + l +
"_" +
mode.toString().toLowerCase()) {
451 public void run(
int nOps) {
455 for (
int i = 0; i < nOps; i++) {
460 o.setCvarchar_def(null);
474 new ClusterjOp(
"setB0->A_" +
mode.toString().toLowerCase()) {
475 public void run(
int nOps) {
479 for (
int i = 0; i < nOps; i++) {
484 final int aId = i % nOps;
498 new ClusterjOp(
"navB0->A") {
499 public void run(
int nOps) {
503 for (
int i = 0; i < nOps; i++) {
504 final IB0 b0 = session.
find(IB0.class, i);
506 int aid = b0.getAid();
507 final IA a = session.
find(IA.class, aid);
509 final int id = a.getId();
510 verify(
id == i % nOps);
511 final int j = checkFields(a);
521 new ClusterjOp(
"navA->B0") {
522 protected Query<IB0>
query;
528 public void close() {
533 public void run(
int nOps) {
538 final QueryBuilder builder
541 final QueryDomainType<IB0> dobj
544 dobj.where(dobj.get(
"aid").equal(dobj.param(
"aid")));
546 for (
int i = 0; i < nOps; i++) {
548 query.setParameter(
"aid", i);
550 Collection<IB0> b0s = query.getResultList();
554 verify(b0s.size() > 0);
557 final int id = b0.getId();
558 verify(
id % nOps == i);
559 final int j = checkFields(b0);
570 new ClusterjOp(
"nullB0->A") {
571 public void run(
int nOps) {
575 for (
int i = 0; i < nOps; i++) {
593 new ClusterjOp(
"delB0ByPK_" +
mode.toString().toLowerCase()) {
594 public void run(
int nOps) {
598 for (
int i = 0; i < nOps; i++) {
615 new ClusterjOp(
"delAByPK_" +
mode.toString().toLowerCase()) {
616 public void run(
int nOps) {
620 for (
int i = 0; i < nOps; i++) {
637 new ClusterjOp(
"insAattr_" +
mode.toString().toLowerCase()) {
638 public void run(
int nOps) {
642 for (
int i = 0; i < nOps; i++) {
647 o.setClong((
long)-i);
648 o.setCfloat((
float)-i);
649 o.setCdouble((
double)-i);
662 new ClusterjOp(
"insB0attr_" +
mode.toString().toLowerCase()) {
663 public void run(
int nOps) {
667 for (
int i = 0; i < nOps; i++) {
672 o.setClong((
long)-i);
673 o.setCfloat((
float)-i);
674 o.setCdouble((
double)-i);
675 o.setCvarbinary_def(null);
688 new ClusterjOp(
"delAllB0_" +
mode.toString().toLowerCase()) {
689 public void run(
int nOps) {
702 new ClusterjOp(
"delAllA_" +
mode.toString().toLowerCase()) {
703 public void run(
int nOps) {
717 for (Iterator<CrundDriver.Op> i = ops.iterator(); i.hasNext();) {
718 ((ClusterjOp)i.next()).init();
721 out.println(
" [ClusterjOp: " + ops.size() +
"]");
724 protected void closeOperations() {
725 out.print(
"closing operations ...");
729 for (Iterator<CrundDriver.Op> i = ops.iterator(); i.hasNext();) {
730 ((ClusterjOp)i.next()).close();
734 out.println(
" [ok]");
737 protected void beginTransaction() {
741 protected void commitTransaction() {
749 protected void initConnection() {
751 out.print(
"creating ClusterJ Session ...");
754 out.println(
" [Session: 1]");
757 protected void closeConnection() {
759 out.print(
"closing ClusterJ Session ...");
764 out.println(
" [ok]");
767 protected void clearPersistenceContext() {
771 protected void clearData() {
772 out.print(
"deleting all objects ...");
777 out.print(
" [B0: " + delB0);
780 out.print(
", A: " + delA);
789 static public void main(
String[] args) {
790 System.out.println(
"ClusterjLoad.main()");
792 new ClusterjLoad().run();
793 System.out.println();
794 System.out.println(
"ClusterjLoad.main(): done.");