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.TimestampAsUtilDateTypes;
22 import java.util.Date;
24 import testsuite.clusterj.model.IdBase;
26 public class QueryTimestampAsUtilDateTypesTest extends AbstractQueryTest {
29 public Class<TimestampAsUtilDateTypes> getInstanceType() {
30 return TimestampAsUtilDateTypes.class;
34 void createInstances(int number) {
35 createAllTimestampAsUtilDateTypesInstances(number);
38 /** Test all single- and double-predicate queries using TimestampTypes.
39 drop table if exists timestamptypes;
40 create table timestamptypes (
41 id int not null primary key,
43 timestamp_not_null_hash timestamp,
44 timestamp_not_null_btree timestamp,
45 timestamp_not_null_both timestamp,
46 timestamp_not_null_none timestamp
48 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
50 create unique index idx_timestamp_not_null_hash using hash on timestamptypes(timestamp_not_null_hash);
51 create index idx_timestamp_not_null_btree on timestamptypes(timestamp_not_null_btree);
52 create unique index idx_timestamp_not_null_both on timestamptypes(timestamp_not_null_both);
57 btreeIndexScanTimestamp();
58 hashIndexScanTimestamp();
59 bothIndexScanTimestamp();
60 noneIndexScanTimestamp();
64 public void btreeIndexScanTimestamp() {
65 equalQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getUtilDateFor(8), 8);
66 greaterEqualQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getUtilDateFor(7), 7, 8, 9);
67 greaterThanQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getUtilDateFor(6), 7, 8, 9);
68 lessEqualQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getUtilDateFor(4), 4, 3, 2, 1, 0);
69 lessThanQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getUtilDateFor(4), 3, 2, 1, 0);
70 betweenQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getUtilDateFor(4), getUtilDateFor(6), 4, 5, 6);
71 greaterEqualAndLessEqualQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getUtilDateFor(4), getUtilDateFor(6), 4, 5, 6);
72 greaterThanAndLessEqualQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getUtilDateFor(4), getUtilDateFor(6), 5, 6);
73 greaterEqualAndLessThanQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getUtilDateFor(4), getUtilDateFor(6), 4, 5);
74 greaterThanAndLessThanQuery("timestamp_not_null_btree", "idx_timestamp_not_null_btree", getUtilDateFor(4), getUtilDateFor(6), 5);
77 public void hashIndexScanTimestamp() {
78 equalQuery("timestamp_not_null_hash", "idx_timestamp_not_null_hash", getUtilDateFor(8), 8);
79 greaterEqualQuery("timestamp_not_null_hash", "none", getUtilDateFor(7), 7, 8, 9);
80 greaterThanQuery("timestamp_not_null_hash", "none", getUtilDateFor(6), 7, 8, 9);
81 lessEqualQuery("timestamp_not_null_hash", "none", getUtilDateFor(4), 4, 3, 2, 1, 0);
82 lessThanQuery("timestamp_not_null_hash", "none", getUtilDateFor(4), 3, 2, 1, 0);
83 betweenQuery("timestamp_not_null_hash", "none", getUtilDateFor(4), getUtilDateFor(6), 4, 5, 6);
84 greaterEqualAndLessEqualQuery("timestamp_not_null_hash", "none", getUtilDateFor(4), getUtilDateFor(6), 4, 5, 6);
85 greaterThanAndLessEqualQuery("timestamp_not_null_hash", "none", getUtilDateFor(4), getUtilDateFor(6), 5, 6);
86 greaterEqualAndLessThanQuery("timestamp_not_null_hash", "none", getUtilDateFor(4), getUtilDateFor(6), 4, 5);
87 greaterThanAndLessThanQuery("timestamp_not_null_hash", "none", getUtilDateFor(4), getUtilDateFor(6), 5);
90 public void bothIndexScanTimestamp() {
91 equalQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getUtilDateFor(8), 8);
92 greaterEqualQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getUtilDateFor(7), 7, 8, 9);
93 greaterThanQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getUtilDateFor(6), 7, 8, 9);
94 lessEqualQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getUtilDateFor(4), 4, 3, 2, 1, 0);
95 lessThanQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getUtilDateFor(4), 3, 2, 1, 0);
96 betweenQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getUtilDateFor(4), getUtilDateFor(6), 4, 5, 6);
97 greaterEqualAndLessEqualQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getUtilDateFor(4), getUtilDateFor(6), 4, 5, 6);
98 greaterThanAndLessEqualQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getUtilDateFor(4), getUtilDateFor(6), 5, 6);
99 greaterEqualAndLessThanQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getUtilDateFor(4), getUtilDateFor(6), 4, 5);
100 greaterThanAndLessThanQuery("timestamp_not_null_both", "idx_timestamp_not_null_both", getUtilDateFor(4), getUtilDateFor(6), 5);
103 public void noneIndexScanTimestamp() {
104 equalQuery("timestamp_not_null_none", "none", getUtilDateFor(8), 8);
105 greaterEqualQuery("timestamp_not_null_none", "none", getUtilDateFor(7), 7, 8, 9);
106 greaterThanQuery("timestamp_not_null_none", "none", getUtilDateFor(6), 7, 8, 9);
107 lessEqualQuery("timestamp_not_null_none", "none", getUtilDateFor(4), 4, 3, 2, 1, 0);
108 lessThanQuery("timestamp_not_null_none", "none", getUtilDateFor(4), 3, 2, 1, 0);
109 betweenQuery("timestamp_not_null_none", "none", getUtilDateFor(4), getUtilDateFor(6), 4, 5, 6);
110 greaterEqualAndLessEqualQuery("timestamp_not_null_none", "none", getUtilDateFor(4), getUtilDateFor(6), 4, 5, 6);
111 greaterThanAndLessEqualQuery("timestamp_not_null_none", "none", getUtilDateFor(4), getUtilDateFor(6), 5, 6);
112 greaterEqualAndLessThanQuery("timestamp_not_null_none", "none", getUtilDateFor(4), getUtilDateFor(6), 4, 5);
113 greaterThanAndLessThanQuery("timestamp_not_null_none", "none", getUtilDateFor(4), getUtilDateFor(6), 5);
116 private void createAllTimestampAsUtilDateTypesInstances(int number) {
117 for (int i = 0; i < number; ++i) {
118 TimestampAsUtilDateTypes instance = session.newInstance(TimestampAsUtilDateTypes.class);
120 instance.setTimestamp_not_null_hash(getUtilDateFor(i));
121 instance.setTimestamp_not_null_btree(getUtilDateFor(i));
122 instance.setTimestamp_not_null_both(getUtilDateFor(i));
123 instance.setTimestamp_not_null_none(getUtilDateFor(i));
124 instances.add(instance);
125 // if (i%3 == 0) System.out.println(toString(instance));
129 private Date getUtilDateFor(int i) {
130 return new Date(getMillisFor(1980, 0, 1, 0, 0, i));
133 public static String toString(IdBase instance) {
134 TimestampAsUtilDateTypes timetype = (TimestampAsUtilDateTypes)instance;
135 StringBuffer buffer = new StringBuffer("TimestampTypes id: ");
136 buffer.append(timetype.getId());
137 buffer.append("; timestamp_not_null_both: ");
138 buffer.append(timetype.getTimestamp_not_null_both().toString());
139 buffer.append("; timestamp_not_null_btree: ");
140 buffer.append(timetype.getTimestamp_not_null_btree().toString());
141 buffer.append("; timestamp_not_null_hash: ");
142 buffer.append(timetype.getTimestamp_not_null_hash().toString());
143 buffer.append("; timestamp_not_null_none: ");
144 buffer.append(timetype.getTimestamp_not_null_none().toString());
145 return buffer.toString();