MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QueryDatetimeAsSqlTimestampTypesTest.java
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.DatetimeAsSqlTimestampTypes;
22 import java.sql.Timestamp;
23 import testsuite.clusterj.model.IdBase;
24 
26 
27  @Override
28  public Class<DatetimeAsSqlTimestampTypes> getInstanceType() {
29  return DatetimeAsSqlTimestampTypes.class;
30  }
31 
32  @Override
33  void createInstances(int number) {
34  createAllDateTimeTypesInstances(number);
35  }
36 
64  public void test() {
65  btreeIndexScanDateTime();
66  hashIndexScanDateTime();
67  bothIndexScanDateTime();
68  noneIndexScanDateTime();
69  failOnError();
70  }
71 
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);
83  }
84 
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);
96  }
97 
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);
109  }
110 
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);
122  }
123 
124 
125  private void createAllDateTimeTypesInstances(int number) {
126  for (int i = 0; i < number; ++i) {
127  DatetimeAsSqlTimestampTypes instance = session.newInstance(DatetimeAsSqlTimestampTypes.class);
128  instance.setId(i);
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);
134  }
135  }
136 
137  protected Timestamp getDateTimeFor(int i) {
138  return new Timestamp(getMillisFor(1980, 0, 1, 0, 0, i));
139  }
140 
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();
154  }
155 }