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.DateAsUtilDateTypes;
23 import java.util.Date;
24 import testsuite.clusterj.model.IdBase;
26 public class QueryDateAsUtilDateTypesTest extends AbstractQueryTest {
29 public Class<DateAsUtilDateTypes> getInstanceType() {
30 return DateAsUtilDateTypes.class;
34 void createInstances(int number) {
35 createAllDateTypesInstances(number);
38 /** Test all single- and double-predicate queries using DateTypes.
39 drop table if exists datetypes;
40 create table datetypes (
41 id int not null primary key,
48 date_not_null_hash date,
49 date_not_null_btree date,
50 date_not_null_both date,
51 date_not_null_none date
53 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
55 create unique index idx_date_null_hash using hash on datetypes(date_null_hash);
56 create index idx_date_null_btree on datetypes(date_null_btree);
57 create unique index idx_date_null_both on datetypes(date_null_both);
59 create unique index idx_date_not_null_hash using hash on datetypes(date_not_null_hash);
60 create index idx_date_not_null_btree on datetypes(date_not_null_btree);
61 create unique index idx_date_not_null_both on datetypes(date_not_null_both);
73 public void btreeIndexScanDate() {
74 equalQuery("date_not_null_btree", "idx_date_not_null_btree", getDateFor(8), 8);
75 greaterEqualQuery("date_not_null_btree", "idx_date_not_null_btree", getDateFor(7), 7, 8, 9);
76 greaterThanQuery("date_not_null_btree", "idx_date_not_null_btree", getDateFor(6), 7, 8, 9);
77 lessEqualQuery("date_not_null_btree", "idx_date_not_null_btree", getDateFor(4), 4, 3, 2, 1, 0);
78 lessThanQuery("date_not_null_btree", "idx_date_not_null_btree", getDateFor(4), 3, 2, 1, 0);
79 betweenQuery("date_not_null_btree", "idx_date_not_null_btree", getDateFor(4), getDateFor(6), 4, 5, 6);
80 greaterEqualAndLessEqualQuery("date_not_null_btree", "idx_date_not_null_btree", getDateFor(4), getDateFor(6), 4, 5, 6);
81 greaterThanAndLessEqualQuery("date_not_null_btree", "idx_date_not_null_btree", getDateFor(4), getDateFor(6), 5, 6);
82 greaterEqualAndLessThanQuery("date_not_null_btree", "idx_date_not_null_btree", getDateFor(4), getDateFor(6), 4, 5);
83 greaterThanAndLessThanQuery("date_not_null_btree", "idx_date_not_null_btree", getDateFor(4), getDateFor(6), 5);
86 public void hashIndexScanDate() {
87 equalQuery("date_not_null_hash", "idx_date_not_null_hash", getDateFor(8), 8);
88 greaterEqualQuery("date_not_null_hash", "none", getDateFor(7), 7, 8, 9);
89 greaterThanQuery("date_not_null_hash", "none", getDateFor(6), 7, 8, 9);
90 lessEqualQuery("date_not_null_hash", "none", getDateFor(4), 4, 3, 2, 1, 0);
91 lessThanQuery("date_not_null_hash", "none", getDateFor(4), 3, 2, 1, 0);
92 betweenQuery("date_not_null_hash", "none", getDateFor(4), getDateFor(6), 4, 5, 6);
93 greaterEqualAndLessEqualQuery("date_not_null_hash", "none", getDateFor(4), getDateFor(6), 4, 5, 6);
94 greaterThanAndLessEqualQuery("date_not_null_hash", "none", getDateFor(4), getDateFor(6), 5, 6);
95 greaterEqualAndLessThanQuery("date_not_null_hash", "none", getDateFor(4), getDateFor(6), 4, 5);
96 greaterThanAndLessThanQuery("date_not_null_hash", "none", getDateFor(4), getDateFor(6), 5);
99 public void bothIndexScanDate() {
100 equalQuery("date_not_null_both", "idx_date_not_null_both", getDateFor(8), 8);
101 greaterEqualQuery("date_not_null_both", "idx_date_not_null_both", getDateFor(7), 7, 8, 9);
102 greaterThanQuery("date_not_null_both", "idx_date_not_null_both", getDateFor(6), 7, 8, 9);
103 lessEqualQuery("date_not_null_both", "idx_date_not_null_both", getDateFor(4), 4, 3, 2, 1, 0);
104 lessThanQuery("date_not_null_both", "idx_date_not_null_both", getDateFor(4), 3, 2, 1, 0);
105 betweenQuery("date_not_null_both", "idx_date_not_null_both", getDateFor(4), getDateFor(6), 4, 5, 6);
106 greaterEqualAndLessEqualQuery("date_not_null_both", "idx_date_not_null_both", getDateFor(4), getDateFor(6), 4, 5, 6);
107 greaterThanAndLessEqualQuery("date_not_null_both", "idx_date_not_null_both", getDateFor(4), getDateFor(6), 5, 6);
108 greaterEqualAndLessThanQuery("date_not_null_both", "idx_date_not_null_both", getDateFor(4), getDateFor(6), 4, 5);
109 greaterThanAndLessThanQuery("date_not_null_both", "idx_date_not_null_both", getDateFor(4), getDateFor(6), 5);
112 public void noneIndexScanDate() {
113 equalQuery("date_not_null_none", "none", getDateFor(8), 8);
114 greaterEqualQuery("date_not_null_none", "none", getDateFor(7), 7, 8, 9);
115 greaterThanQuery("date_not_null_none", "none", getDateFor(6), 7, 8, 9);
116 lessEqualQuery("date_not_null_none", "none", getDateFor(4), 4, 3, 2, 1, 0);
117 lessThanQuery("date_not_null_none", "none", getDateFor(4), 3, 2, 1, 0);
118 betweenQuery("date_not_null_none", "none", getDateFor(4), getDateFor(6), 4, 5, 6);
119 greaterEqualAndLessEqualQuery("date_not_null_none", "none", getDateFor(4), getDateFor(6), 4, 5, 6);
120 greaterThanAndLessEqualQuery("date_not_null_none", "none", getDateFor(4), getDateFor(6), 5, 6);
121 greaterEqualAndLessThanQuery("date_not_null_none", "none", getDateFor(4), getDateFor(6), 4, 5);
122 greaterThanAndLessThanQuery("date_not_null_none", "none", getDateFor(4), getDateFor(6), 5);
125 private void createAllDateTypesInstances(int number) {
126 for (int i = 0; i < number; ++i) {
127 DateAsUtilDateTypes instance = session.newInstance(DateAsUtilDateTypes.class);
129 instance.setDate_not_null_hash(getDateFor(i));
130 instance.setDate_not_null_btree(getDateFor(i));
131 instance.setDate_not_null_both(getDateFor(i));
132 instance.setDate_not_null_none(getDateFor(i));
133 instances.add(instance);
137 protected Date getDateFor(int i) {
138 return new Date(getMillisFor(1980, 0, i + 1));
141 public static String toString(IdBase instance) {
142 DateAsUtilDateTypes datetype = (DateAsUtilDateTypes)instance;
143 StringBuffer buffer = new StringBuffer("DateTypes id: ");
144 buffer.append(datetype.getId());
145 buffer.append("; date_not_null_both: ");
146 buffer.append(datetype.getDate_not_null_both().toString());
147 buffer.append("; date_not_null_btree: ");
148 buffer.append(datetype.getDate_not_null_btree().toString());
149 buffer.append("; date_not_null_hash: ");
150 buffer.append(datetype.getDate_not_null_hash().toString());
151 buffer.append("; date_not_null_none: ");
152 buffer.append(datetype.getDate_not_null_none().toString());
153 return buffer.toString();