MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QueryTimestampAsSqlTimestampTypesTest.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 testsuite.clusterj.model.TimestampAsSqlTimestampTypes;
22 import java.sql.Timestamp;
23 import testsuite.clusterj.model.IdBase;
24 
26 
27  @Override
28  public Class<TimestampAsSqlTimestampTypes> getInstanceType() {
29  return TimestampAsSqlTimestampTypes.class;
30  }
31 
32  @Override
33  void createInstances(int number) {
34  createAllTimestampAsSqlTimestampTypesInstances(number);
35  }
36 
55  public void test() {
56  btreeIndexScanTimestamp();
57  hashIndexScanTimestamp();
58  bothIndexScanTimestamp();
59  noneIndexScanTimestamp();
60  failOnError();
61  }
62 
63  public void btreeIndexScanTimestamp() {
64  equalQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getTimestampFor(8), 8);
65  greaterEqualQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getTimestampFor(7), 7, 8, 9);
66  greaterThanQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getTimestampFor(6), 7, 8, 9);
67  lessEqualQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getTimestampFor(4), 4, 3, 2, 1, 0);
68  lessThanQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getTimestampFor(4), 3, 2, 1, 0);
69  betweenQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getTimestampFor(4), getTimestampFor(6), 4, 5, 6);
70  greaterEqualAndLessEqualQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getTimestampFor(4), getTimestampFor(6), 4, 5, 6);
71  greaterThanAndLessEqualQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getTimestampFor(4), getTimestampFor(6), 5, 6);
72  greaterEqualAndLessThanQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getTimestampFor(4), getTimestampFor(6), 4, 5);
73  greaterThanAndLessThanQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getTimestampFor(4), getTimestampFor(6), 5);
74  }
75 
76  public void hashIndexScanTimestamp() {
77  equalQuery("timestamp_not_null_hash", "idx_timestamp_not_null_hash", getTimestampFor(8), 8);
78  greaterEqualQuery("timestamp_not_null_hash", "none", getTimestampFor(7), 7, 8, 9);
79  greaterThanQuery("timestamp_not_null_hash", "none", getTimestampFor(6), 7, 8, 9);
80  lessEqualQuery("timestamp_not_null_hash", "none", getTimestampFor(4), 4, 3, 2, 1, 0);
81  lessThanQuery("timestamp_not_null_hash", "none", getTimestampFor(4), 3, 2, 1, 0);
82  betweenQuery("timestamp_not_null_hash", "none", getTimestampFor(4), getTimestampFor(6), 4, 5, 6);
83  greaterEqualAndLessEqualQuery("timestamp_not_null_hash", "none", getTimestampFor(4), getTimestampFor(6), 4, 5, 6);
84  greaterThanAndLessEqualQuery("timestamp_not_null_hash", "none", getTimestampFor(4), getTimestampFor(6), 5, 6);
85  greaterEqualAndLessThanQuery("timestamp_not_null_hash", "none", getTimestampFor(4), getTimestampFor(6), 4, 5);
86  greaterThanAndLessThanQuery("timestamp_not_null_hash", "none", getTimestampFor(4), getTimestampFor(6), 5);
87  }
88 
89  public void bothIndexScanTimestamp() {
90  equalQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getTimestampFor(8), 8);
91  greaterEqualQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getTimestampFor(7), 7, 8, 9);
92  greaterThanQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getTimestampFor(6), 7, 8, 9);
93  lessEqualQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getTimestampFor(4), 4, 3, 2, 1, 0);
94  lessThanQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getTimestampFor(4), 3, 2, 1, 0);
95  betweenQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getTimestampFor(4), getTimestampFor(6), 4, 5, 6);
96  greaterEqualAndLessEqualQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getTimestampFor(4), getTimestampFor(6), 4, 5, 6);
97  greaterThanAndLessEqualQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getTimestampFor(4), getTimestampFor(6), 5, 6);
98  greaterEqualAndLessThanQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getTimestampFor(4), getTimestampFor(6), 4, 5);
99  greaterThanAndLessThanQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getTimestampFor(4), getTimestampFor(6), 5);
100  }
101 
102  public void noneIndexScanTimestamp() {
103  equalQuery("timestamp_not_null_none", "none", getTimestampFor(8), 8);
104  greaterEqualQuery("timestamp_not_null_none", "none", getTimestampFor(7), 7, 8, 9);
105  greaterThanQuery("timestamp_not_null_none", "none", getTimestampFor(6), 7, 8, 9);
106  lessEqualQuery("timestamp_not_null_none", "none", getTimestampFor(4), 4, 3, 2, 1, 0);
107  lessThanQuery("timestamp_not_null_none", "none", getTimestampFor(4), 3, 2, 1, 0);
108  betweenQuery("timestamp_not_null_none", "none", getTimestampFor(4), getTimestampFor(6), 4, 5, 6);
109  greaterEqualAndLessEqualQuery("timestamp_not_null_none", "none", getTimestampFor(4), getTimestampFor(6), 4, 5, 6);
110  greaterThanAndLessEqualQuery("timestamp_not_null_none", "none", getTimestampFor(4), getTimestampFor(6), 5, 6);
111  greaterEqualAndLessThanQuery("timestamp_not_null_none", "none", getTimestampFor(4), getTimestampFor(6), 4, 5);
112  greaterThanAndLessThanQuery("timestamp_not_null_none", "none", getTimestampFor(4), getTimestampFor(6), 5);
113  }
114 
115  private void createAllTimestampAsSqlTimestampTypesInstances(int number) {
116  for (int i = 0; i < number; ++i) {
117  TimestampAsSqlTimestampTypes instance = session.newInstance(TimestampAsSqlTimestampTypes.class);
118  instance.setId(i);
119  instance.setTimestamp_not_null_hash(getTimestampFor(i));
120  instance.setTimestamp_not_null_btree(getTimestampFor(i));
121  instance.setTimestamp_not_null_both(getTimestampFor(i));
122  instance.setTimestamp_not_null_none(getTimestampFor(i));
123  instances.add(instance);
124 // if (i%3 == 0) System.out.println(toString(instance));
125  }
126  }
127 
128  private Timestamp getTimestampFor(int i) {
129  return new Timestamp(getMillisFor(1980, 0, 1, 0, 0, i));
130  }
131 
132  public static String toString(IdBase instance) {
133  TimestampAsSqlTimestampTypes timetype = (TimestampAsSqlTimestampTypes)instance;
134  StringBuffer buffer = new StringBuffer("TimestampTypes id: ");
135  buffer.append(timetype.getId());
136  buffer.append("; timestamp_not_null_both: ");
137  buffer.append(timetype.getTimestamp_not_null_both().toString());
138  buffer.append("; timestamp_not_null_btree: ");
139  buffer.append(timetype.getTimestamp_not_null_btree().toString());
140  buffer.append("; timestamp_not_null_hash: ");
141  buffer.append(timetype.getTimestamp_not_null_hash().toString());
142  buffer.append("; timestamp_not_null_none: ");
143  buffer.append(timetype.getTimestamp_not_null_none().toString());
144  return buffer.toString();
145  }
146 }