MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QueryDecimalTypesTest.java
1 /*
2  Copyright 2010 Sun Microsystems, Inc.
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 package testsuite.clusterj;
20 
21 import java.math.BigDecimal;
22 import testsuite.clusterj.model.DecimalTypes;
23 import testsuite.clusterj.model.IdBase;
24 
26 
27  @Override
28  public Class getInstanceType() {
29  return DecimalTypes.class;
30  }
31 
32  @Override
33  void createInstances(int number) {
34  createAllDecimalTypesInstances(number);
35  }
36 
59  public void test() {
60  btreeIndexScanDecimal();
61  hashIndexScanDecimal();
62  bothIndexScanDecimal();
63  noneIndexScanDecimal();
64  failOnError();
65  }
66 
67  public void btreeIndexScanDecimal() {
68  equalQuery("decimal_null_btree", "idx_decimal_null_btree", getDecimal(8), 8);
69  greaterEqualQuery("decimal_null_btree", "idx_decimal_null_btree", getDecimal(7), 7, 8, 9);
70  greaterThanQuery("decimal_null_btree", "idx_decimal_null_btree", getDecimal(6), 7, 8, 9);
71  lessEqualQuery("decimal_null_btree", "idx_decimal_null_btree", getDecimal(4), 4, 3, 2, 1, 0);
72  lessThanQuery("decimal_null_btree", "idx_decimal_null_btree", getDecimal(4), 3, 2, 1, 0);
73  betweenQuery("decimal_null_btree", "idx_decimal_null_btree", getDecimal(4), getDecimal(6), 4, 5, 6);
74  greaterEqualAndLessEqualQuery("decimal_null_btree", "idx_decimal_null_btree", getDecimal(4), getDecimal(6), 4, 5, 6);
75  greaterThanAndLessEqualQuery("decimal_null_btree", "idx_decimal_null_btree", getDecimal(4), getDecimal(6), 5, 6);
76  greaterEqualAndLessThanQuery("decimal_null_btree", "idx_decimal_null_btree", getDecimal(4), getDecimal(6), 4, 5);
77  greaterThanAndLessThanQuery("decimal_null_btree", "idx_decimal_null_btree", getDecimal(4), getDecimal(6), 5);
78  }
79 
80  public void hashIndexScanDecimal() {
81  equalQuery("decimal_null_hash", "idx_decimal_null_hash", getDecimal(8), 8);
82  greaterEqualQuery("decimal_null_hash", "none", getDecimal(7), 7, 8, 9);
83  greaterThanQuery("decimal_null_hash", "none", getDecimal(6), 7, 8, 9);
84  lessEqualQuery("decimal_null_hash", "none", getDecimal(4), 4, 3, 2, 1, 0);
85  lessThanQuery("decimal_null_hash", "none", getDecimal(4), 3, 2, 1, 0);
86  betweenQuery("decimal_null_hash", "none", getDecimal(4), getDecimal(6), 4, 5, 6);
87  greaterEqualAndLessEqualQuery("decimal_null_hash", "none", getDecimal(4), getDecimal(6), 4, 5, 6);
88  greaterThanAndLessEqualQuery("decimal_null_hash", "none", getDecimal(4), getDecimal(6), 5, 6);
89  greaterEqualAndLessThanQuery("decimal_null_hash", "none", getDecimal(4), getDecimal(6), 4, 5);
90  greaterThanAndLessThanQuery("decimal_null_hash", "none", getDecimal(4), getDecimal(6), 5);
91  }
92 
93  public void bothIndexScanDecimal() {
94  equalQuery("decimal_null_both", "idx_decimal_null_both", getDecimal(8), 8);
95  greaterEqualQuery("decimal_null_both", "idx_decimal_null_both", getDecimal(7), 7, 8, 9);
96  greaterThanQuery("decimal_null_both", "idx_decimal_null_both", getDecimal(6), 7, 8, 9);
97  lessEqualQuery("decimal_null_both", "idx_decimal_null_both", getDecimal(4), 4, 3, 2, 1, 0);
98  lessThanQuery("decimal_null_both", "idx_decimal_null_both", getDecimal(4), 3, 2, 1, 0);
99  betweenQuery("decimal_null_both", "idx_decimal_null_both", getDecimal(4), getDecimal(6), 4, 5, 6);
100  greaterEqualAndLessEqualQuery("decimal_null_both", "idx_decimal_null_both", getDecimal(4), getDecimal(6), 4, 5, 6);
101  greaterThanAndLessEqualQuery("decimal_null_both", "idx_decimal_null_both", getDecimal(4), getDecimal(6), 5, 6);
102  greaterEqualAndLessThanQuery("decimal_null_both", "idx_decimal_null_both", getDecimal(4), getDecimal(6), 4, 5);
103  greaterThanAndLessThanQuery("decimal_null_both", "idx_decimal_null_both", getDecimal(4), getDecimal(6), 5);
104  }
105 
106  public void noneIndexScanDecimal() {
107  equalQuery("decimal_null_none", "none", getDecimal(8), 8);
108  greaterEqualQuery("decimal_null_none", "none", getDecimal(7), 7, 8, 9);
109  greaterThanQuery("decimal_null_none", "none", getDecimal(6), 7, 8, 9);
110  lessEqualQuery("decimal_null_none", "none", getDecimal(4), 4, 3, 2, 1, 0);
111  lessThanQuery("decimal_null_none", "none", getDecimal(4), 3, 2, 1, 0);
112  betweenQuery("decimal_null_none", "none", getDecimal(4), getDecimal(6), 4, 5, 6);
113  greaterEqualAndLessEqualQuery("decimal_null_none", "none", getDecimal(4), getDecimal(6), 4, 5, 6);
114  greaterThanAndLessEqualQuery("decimal_null_none", "none", getDecimal(4), getDecimal(6), 5, 6);
115  greaterEqualAndLessThanQuery("decimal_null_none", "none", getDecimal(4), getDecimal(6), 4, 5);
116  greaterThanAndLessThanQuery("decimal_null_none", "none", getDecimal(4), getDecimal(6), 5);
117  }
118 
119 
120  private void createAllDecimalTypesInstances(int number) {
121  for (int i = 0; i < number; ++i) {
122  DecimalTypes instance = session.newInstance(DecimalTypes.class);
123  instance.setId(i);
124  instance.setDecimal_null_hash(getDecimal(i));
125  instance.setDecimal_null_btree(getDecimal(i));
126  instance.setDecimal_null_both(getDecimal(i));
127  instance.setDecimal_null_none(getDecimal(i));
128  instances.add(instance);
129  }
130  }
131 
137  protected BigDecimal getDecimal(int number) {
138  return BigDecimal.valueOf(number, 5);
139  }
140 
145  @Override
146  protected void printResultInstance(IdBase instance) {
147  if (instance instanceof DecimalTypes) {
148  DecimalTypes decimalType = (DecimalTypes)instance;
149 // System.out.println(toString(decimalType));
150  }
151  }
152 
153  public static String toString(IdBase idBase) {
154  DecimalTypes instance = (DecimalTypes)idBase;
155  StringBuffer buffer = new StringBuffer("DecimalTypes id: ");
156  buffer.append(instance.getId());
157  buffer.append("; decimal_null_both: ");
158  buffer.append(instance.getDecimal_null_both().toString());
159  buffer.append("; decimal_null_btree: ");
160  buffer.append(instance.getDecimal_null_btree().toString());
161  buffer.append("; decimal_null_hash: ");
162  buffer.append(instance.getDecimal_null_hash().toString());
163  buffer.append("; decimal_null_none: ");
164  buffer.append(instance.getDecimal_null_none().toString());
165  return buffer.toString();
166  }
167 }