MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QueryLikeTest.java
1 /*
2  Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 package testsuite.clusterj;
19 
20 import testsuite.clusterj.model.StringTypes;
21 import testsuite.clusterj.model.IdBase;
22 
25 public class QueryLikeTest extends AbstractQueryTest {
26 
27  @Override
28  public Class<?> getInstanceType() {
29  return StringTypes.class;
30  }
31 
32  @Override
33  void createInstances(int number) {
34  createAllStringTypesInstances(number);
35  }
36 
37  static String[] strings = new String[] {
38  "Alabama",
39  "Arkansas",
40  "Delaware",
41  "New Jersey",
42  "New York",
43  "Pennsylvania",
44  "Rhode Island",
45  "Texax",
46  "Virginia",
47  "Wyoming"
48  };
49 
76  public void test() {
77  btreeIndexScanString();
78  hashIndexScanString();
79  bothIndexScanString();
80  noneIndexScanString();
81  failOnError();
82  }
83 
84  public void btreeIndexScanString() {
85  likeQuery("string_not_null_btree", "none", "%", 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
86  likeQuery("string_not_null_btree", "none", "_");
87  likeQuery("string_not_null_btree", "none", "_____", 7);
88  likeQuery("string_not_null_btree", "none", "%York", 4);
89  likeQuery("string_not_null_btree", "none", "New York", 4);
90  likeQuery("string_not_null_btree", "none", "New Yor_", 4);
91  likeQuery("string_not_null_btree", "none", "New%", 3, 4);
92  greaterEqualAndLikeQuery("string_not_null_btree", "idx_string_not_null_btree", getString(4), "%", 4, 5, 6, 7, 8, 9);
93  greaterEqualAndLikeQuery("string_not_null_btree", "idx_string_not_null_btree", getString(4), "%enns%", 5);
94  greaterThanAndLikeQuery("string_not_null_btree", "idx_string_not_null_btree", getString(4), "%e%", 5, 6, 7);
95  }
96 
97  public void hashIndexScanString() {
98  greaterEqualAndLikeQuery("string_not_null_hash", "none", getString(4), "%enns%", 5);
99  greaterThanAndLikeQuery("string_not_null_hash", "none", getString(4), "%e%", 5, 6, 7);
100  }
101 
102  public void bothIndexScanString() {
103  greaterEqualAndLikeQuery("string_not_null_both", "idx_string_not_null_both", getString(4), "%enns%", 5);
104  greaterThanAndLikeQuery("string_not_null_both", "idx_string_not_null_both", getString(4), "%e%", 5, 6, 7);
105  }
106 
107  public void noneIndexScanString() {
108  greaterEqualAndLikeQuery("string_not_null_none", "none", getString(4), "%enns%", 5);
109  greaterThanAndLikeQuery("string_not_null_none", "none", getString(4), "%e%", 5, 6, 7);
110  }
111 
112  private void createAllStringTypesInstances(int number) {
113  for (int i = 0; i < number; ++i) {
114  StringTypes instance = session.newInstance(StringTypes.class);
115  instance.setId(i);
116  instance.setString_not_null_hash(getString(i));
117  instance.setString_not_null_btree(getString(i));
118  instance.setString_not_null_both(getString(i));
119  instance.setString_not_null_none(getString(i));
120  instance.setString_null_hash(getString(i));
121  instance.setString_null_btree(getString(i));
122  instance.setString_null_both(getString(i));
123  instance.setString_null_none(getString(i));
124  instances.add(instance);
125  }
126  }
127 
128  protected String getString(int number) {
129  return strings[number];
130  }
131 
136  @Override
137  protected void printResultInstance(IdBase instance) {
138  if (instance instanceof StringTypes) {
139  @SuppressWarnings("unused")
140  StringTypes stringType = (StringTypes)instance;
141 // System.out.println(toString(stringType));
142  }
143  }
144 
145  public static String toString(IdBase idBase) {
146  StringTypes instance = (StringTypes)idBase;
147  StringBuffer buffer = new StringBuffer("StringTypes id: ");
148  buffer.append(instance.getId());
149  buffer.append("; string_not_null_both: ");
150  buffer.append(instance.getString_not_null_both());
151  buffer.append("; string_not_null_btree: ");
152  buffer.append(instance.getString_not_null_btree());
153  buffer.append("; string_not_null_hash: ");
154  buffer.append(instance.getString_not_null_hash());
155  buffer.append("; string_not_null_none: ");
156  buffer.append(instance.getString_not_null_none());
157  buffer.append("; string_null_both: ");
158  buffer.append(instance.getString_null_both().toString());
159  buffer.append("; string_null_btree: ");
160  buffer.append(instance.getString_null_btree().toString());
161  buffer.append("; string_null_hash: ");
162  buffer.append(instance.getString_null_hash().toString());
163  buffer.append("; string_null_none: ");
164  buffer.append(instance.getString_null_none().toString());
165  return buffer.toString();
166  }
167 }