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.DatetimeAsSqlTimestampTypes;
22 import java.sql.Timestamp;
23 import testsuite.clusterj.model.IdBase;
25 public class QueryDatetimeAsSqlTimestampTypesTest extends AbstractQueryTest {
28 public Class<DatetimeAsSqlTimestampTypes> getInstanceType() {
29 return DatetimeAsSqlTimestampTypes.class;
33 void createInstances(int number) {
34 createAllDateTimeTypesInstances(number);
37 /** Test all single- and double-predicate queries using DateTimeTypes.
38 drop table if exists datetimetypes;
39 create table datetimetypes (
40 id int not null primary key,
42 datetime_null_hash datetime,
43 datetime_null_btree datetime,
44 datetime_null_both datetime,
45 datetime_null_none datetime,
47 datetime_not_null_hash datetime,
48 datetime_not_null_btree datetime,
49 datetime_not_null_both datetime,
50 datetime_not_null_none datetime
52 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
54 create unique index idx_datetime_null_hash using hash on datetimetypes(datetime_null_hash);
55 create index idx_datetime_null_btree on datetimetypes(datetime_null_btree);
56 create unique index idx_datetime_null_both on datetimetypes(datetime_null_both);
58 create unique index idx_datetime_not_null_hash using hash on datetimetypes(datetime_not_null_hash);
59 create index idx_datetime_not_null_btree on datetimetypes(datetime_not_null_btree);
60 create unique index idx_datetime_not_null_both on datetimetypes(datetime_not_null_both);
65 btreeIndexScanDateTime();
66 hashIndexScanDateTime();
67 bothIndexScanDateTime();
68 noneIndexScanDateTime();
72 public void btreeIndexScanDateTime() {
73 equalQuery("datetime_not_null_btree", "idx_datetime_not_null_btree", getDateTimeFor(8), 8);
74 greaterEqualQuery("datetime_not_null_btree", "idx_datetime_not_null_btree", getDateTimeFor(7), 7, 8, 9);
75 greaterThanQuery("datetime_not_null_btree", "idx_datetime_not_null_btree", getDateTimeFor(6), 7, 8, 9);
76 lessEqualQuery("datetime_not_null_btree", "idx_datetime_not_null_btree", getDateTimeFor(4), 4, 3, 2, 1, 0);
77 lessThanQuery("datetime_not_null_btree", "idx_datetime_not_null_btree", getDateTimeFor(4), 3, 2, 1, 0);
78 betweenQuery("datetime_not_null_btree", "idx_datetime_not_null_btree", getDateTimeFor(4), getDateTimeFor(6), 4, 5, 6);
79 greaterEqualAndLessEqualQuery("datetime_not_null_btree", "idx_datetime_not_null_btree", getDateTimeFor(4), getDateTimeFor(6), 4, 5, 6);
80 greaterThanAndLessEqualQuery("datetime_not_null_btree", "idx_datetime_not_null_btree", getDateTimeFor(4), getDateTimeFor(6), 5, 6);
81 greaterEqualAndLessThanQuery("datetime_not_null_btree", "idx_datetime_not_null_btree", getDateTimeFor(4), getDateTimeFor(6), 4, 5);
82 greaterThanAndLessThanQuery("datetime_not_null_btree", "idx_datetime_not_null_btree", getDateTimeFor(4), getDateTimeFor(6), 5);
85 public void hashIndexScanDateTime() {
86 equalQuery("datetime_not_null_hash", "idx_datetime_not_null_hash", getDateTimeFor(8), 8);
87 greaterEqualQuery("datetime_not_null_hash", "none", getDateTimeFor(7), 7, 8, 9);
88 greaterThanQuery("datetime_not_null_hash", "none", getDateTimeFor(6), 7, 8, 9);
89 lessEqualQuery("datetime_not_null_hash", "none", getDateTimeFor(4), 4, 3, 2, 1, 0);
90 lessThanQuery("datetime_not_null_hash", "none", getDateTimeFor(4), 3, 2, 1, 0);
91 betweenQuery("datetime_not_null_hash", "none", getDateTimeFor(4), getDateTimeFor(6), 4, 5, 6);
92 greaterEqualAndLessEqualQuery("datetime_not_null_hash", "none", getDateTimeFor(4), getDateTimeFor(6), 4, 5, 6);
93 greaterThanAndLessEqualQuery("datetime_not_null_hash", "none", getDateTimeFor(4), getDateTimeFor(6), 5, 6);
94 greaterEqualAndLessThanQuery("datetime_not_null_hash", "none", getDateTimeFor(4), getDateTimeFor(6), 4, 5);
95 greaterThanAndLessThanQuery("datetime_not_null_hash", "none", getDateTimeFor(4), getDateTimeFor(6), 5);
98 public void bothIndexScanDateTime() {
99 equalQuery("datetime_not_null_both", "idx_datetime_not_null_both", getDateTimeFor(8), 8);
100 greaterEqualQuery("datetime_not_null_both", "idx_datetime_not_null_both", getDateTimeFor(7), 7, 8, 9);
101 greaterThanQuery("datetime_not_null_both", "idx_datetime_not_null_both", getDateTimeFor(6), 7, 8, 9);
102 lessEqualQuery("datetime_not_null_both", "idx_datetime_not_null_both", getDateTimeFor(4), 4, 3, 2, 1, 0);
103 lessThanQuery("datetime_not_null_both", "idx_datetime_not_null_both", getDateTimeFor(4), 3, 2, 1, 0);
104 betweenQuery("datetime_not_null_both", "idx_datetime_not_null_both", getDateTimeFor(4), getDateTimeFor(6), 4, 5, 6);
105 greaterEqualAndLessEqualQuery("datetime_not_null_both", "idx_datetime_not_null_both", getDateTimeFor(4), getDateTimeFor(6), 4, 5, 6);
106 greaterThanAndLessEqualQuery("datetime_not_null_both", "idx_datetime_not_null_both", getDateTimeFor(4), getDateTimeFor(6), 5, 6);
107 greaterEqualAndLessThanQuery("datetime_not_null_both", "idx_datetime_not_null_both", getDateTimeFor(4), getDateTimeFor(6), 4, 5);
108 greaterThanAndLessThanQuery("datetime_not_null_both", "idx_datetime_not_null_both", getDateTimeFor(4), getDateTimeFor(6), 5);
111 public void noneIndexScanDateTime() {
112 equalQuery("datetime_not_null_none", "none", getDateTimeFor(8), 8);
113 greaterEqualQuery("datetime_not_null_none", "none", getDateTimeFor(7), 7, 8, 9);
114 greaterThanQuery("datetime_not_null_none", "none", getDateTimeFor(6), 7, 8, 9);
115 lessEqualQuery("datetime_not_null_none", "none", getDateTimeFor(4), 4, 3, 2, 1, 0);
116 lessThanQuery("datetime_not_null_none", "none", getDateTimeFor(4), 3, 2, 1, 0);
117 betweenQuery("datetime_not_null_none", "none", getDateTimeFor(4), getDateTimeFor(6), 4, 5, 6);
118 greaterEqualAndLessEqualQuery("datetime_not_null_none", "none", getDateTimeFor(4), getDateTimeFor(6), 4, 5, 6);
119 greaterThanAndLessEqualQuery("datetime_not_null_none", "none", getDateTimeFor(4), getDateTimeFor(6), 5, 6);
120 greaterEqualAndLessThanQuery("datetime_not_null_none", "none", getDateTimeFor(4), getDateTimeFor(6), 4, 5);
121 greaterThanAndLessThanQuery("datetime_not_null_none", "none", getDateTimeFor(4), getDateTimeFor(6), 5);
125 private void createAllDateTimeTypesInstances(int number) {
126 for (int i = 0; i < number; ++i) {
127 DatetimeAsSqlTimestampTypes instance = session.newInstance(DatetimeAsSqlTimestampTypes.class);
129 instance.setDatetime_not_null_hash(getDateTimeFor(i));
130 instance.setDatetime_not_null_btree(getDateTimeFor(i));
131 instance.setDatetime_not_null_both(getDateTimeFor(i));
132 instance.setDatetime_not_null_none(getDateTimeFor(i));
133 instances.add(instance);
137 protected Timestamp getDateTimeFor(int i) {
138 return new Timestamp(getMillisFor(1980, 0, 1, 0, 0, i));
141 public static String toString(IdBase instance) {
142 DatetimeAsSqlTimestampTypes timetype = (DatetimeAsSqlTimestampTypes)instance;
143 StringBuffer buffer = new StringBuffer("DateTimeTypes id: ");
144 buffer.append(timetype.getId());
145 buffer.append("; datetime_not_null_both: ");
146 buffer.append(timetype.getDatetime_not_null_both().toString());
147 buffer.append("; datetime_not_null_btree: ");
148 buffer.append(timetype.getDatetime_not_null_btree().toString());
149 buffer.append("; datetime_not_null_hash: ");
150 buffer.append(timetype.getDatetime_not_null_hash().toString());
151 buffer.append("; datetime_not_null_none: ");
152 buffer.append(timetype.getDatetime_not_null_none().toString());
153 return buffer.toString();