]> review.fuel-infra Code Review - packages/trusty/mysql-wsrep-5.6.git/blob
2ca1c7a4cf6f03eda84b916e407a920615974a04
[packages/trusty/mysql-wsrep-5.6.git] /
1 /*
2    Copyright 2010 Sun Microsystems, Inc.
3    All rights reserved. Use is subject to license terms.
4
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.
8
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.
13
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
17 */
18
19 package testsuite.clusterj;
20
21 import testsuite.clusterj.model.DateAsSqlDateTypes;
22
23 import java.sql.Date;
24 import testsuite.clusterj.model.IdBase;
25
26 public class QueryDateAsSqlDateTypesTest extends AbstractQueryTest {
27
28     @Override
29     public Class<DateAsSqlDateTypes> getInstanceType() {
30         return DateAsSqlDateTypes.class;
31     }
32
33     @Override
34     void createInstances(int number) {
35         createAllDateTypesInstances(number);
36     }
37
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,
42
43  date_null_hash date,
44  date_null_btree date,
45  date_null_both date,
46  date_null_none date,
47
48  date_not_null_hash date,
49  date_not_null_btree date,
50  date_not_null_both date,
51  date_not_null_none date
52
53 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
54
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);
58
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);
62
63      */
64
65     public void test() {
66         btreeIndexScanDate();
67         hashIndexScanDate();
68         bothIndexScanDate();
69         noneIndexScanDate();
70         failOnError();
71     }
72
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);
84     }
85
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);
97     }
98
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);
110     }
111
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);
123     }
124
125     private void createAllDateTypesInstances(int number) {
126         for (int i = 0; i < number; ++i) {
127             DateAsSqlDateTypes instance = session.newInstance(DateAsSqlDateTypes.class);
128             instance.setId(i);
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);
134         }
135     }
136
137     protected Date getDateFor(int i) {
138         return new Date(getMillisFor(1980, 0, i + 1));
139     }
140
141     public static String toString(IdBase instance) {
142         DateAsSqlDateTypes datetype = (DateAsSqlDateTypes)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();
154     }
155 }