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