2 Copyright 2010 Sun Microsystems, Inc.
3 All rights reserved. Use is subject to license terms.
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.
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.
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
19 package testsuite.clusterj;
21 import testsuite.clusterj.model.TimestampAsSqlTimestampTypes;
22 import java.sql.Timestamp;
23 import testsuite.clusterj.model.IdBase;
25 public class QueryTimestampAsSqlTimestampTypesTest extends AbstractQueryTest {
28 public Class<TimestampAsSqlTimestampTypes> getInstanceType() {
29 return TimestampAsSqlTimestampTypes.class;
33 void createInstances(int number) {
34 createAllTimestampAsSqlTimestampTypesInstances(number);
37 /** Test all single- and double-predicate queries using TimestampTypes.
38 drop table if exists timestamptypes;
39 create table timestamptypes (
40 id int not null primary key,
42 timestamp_not_null_hash timestamp,
43 timestamp_not_null_btree timestamp,
44 timestamp_not_null_both timestamp,
45 timestamp_not_null_none timestamp
47 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
49 create unique index idx_timestamp_not_null_hash using hash on timestamptypes(timestamp_not_null_hash);
50 create index idx_timestamp_not_null_btree on timestamptypes(timestamp_not_null_btree);
51 create unique index idx_timestamp_not_null_both on timestamptypes(timestamp_not_null_both);
56 btreeIndexScanTimestamp();
57 hashIndexScanTimestamp();
58 bothIndexScanTimestamp();
59 noneIndexScanTimestamp();
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);
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);
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);
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);
115 private void createAllTimestampAsSqlTimestampTypesInstances(int number) {
116 for (int i = 0; i < number; ++i) {
117 TimestampAsSqlTimestampTypes instance = session.newInstance(TimestampAsSqlTimestampTypes.class);
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));
128 private Timestamp getTimestampFor(int i) {
129 return new Timestamp(getMillisFor(1980, 0, 1, 0, 0, i));
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();