MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QueryLikeByteArrayTypesTest.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.ByteArrayTypes;
21 import testsuite.clusterj.model.IdBase;
22 
26 
27  @Override
28  public Class<?> getInstanceType() {
29  return ByteArrayTypes.class;
30  }
31 
32  @Override
33  void createInstances(int number) {
34  createAllByteArrayTypesInstances(number);
35  }
36 
37  static byte[][] bytes = new byte[][] {
38  new byte[] {'a', 'a', 'a', 'a'},
39  new byte[] {'a', 'a', 'a', 'b'},
40  new byte[] {'a', 'a', 'b', 'a'},
41  new byte[] {'a', 'a', 'b', 'b'},
42  new byte[] {'a', 'b', 'a', 'a'},
43  new byte[] {'a', 'b', 'a', 'b'},
44  new byte[] {'a', 'b', 'b', 'a'},
45  new byte[] {'a', 'b', 'b', 'b'},
46  new byte[] {'b', 'a', 'a', 'a'},
47  new byte[] {'b', 'a', 'a', 'b'},
48  };
49 
67  public void test() {
68  btreeIndexScanString();
69  hashIndexScanString();
70  bothIndexScanString();
71  noneIndexScanString();
72  failOnError();
73  }
74 
75  public void btreeIndexScanString() {
76  likeQuery("bytes_null_btree", "none", new byte[] {(byte)'%'}, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
77  likeQuery("bytes_null_btree", "none", new byte[] {(byte)'_'});
78  likeQuery("bytes_null_btree", "none", new byte[] {(byte)'_', (byte)'_', (byte)'_', (byte)'_'}, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
79  likeQuery("bytes_null_btree", "none", new byte[] {(byte)'_', (byte)'a', (byte)'a', (byte)'a'}, 0, 8);
80  likeQuery("bytes_null_btree", "none", new byte[] {(byte)'a', (byte)'b', (byte)'a', (byte)'a'}, 4);
81  likeQuery("bytes_null_btree", "none", new byte[] {(byte)'a', (byte)'b', (byte)'a', (byte)'%'}, 4, 5);
82  likeQuery("bytes_null_btree", "none", new byte[] {(byte)'a', (byte)'b', (byte)'%'}, 4, 5, 6, 7);
83  greaterEqualAndLikeQuery("bytes_null_btree", "idx_bytes_null_btree", getBytes(4), new byte[] {(byte)'%'}, 4, 5, 6, 7, 8, 9);
84  greaterEqualAndLikeQuery("bytes_null_btree", "idx_bytes_null_btree", getBytes(4), new byte[] {(byte)'a', (byte)'%', (byte)'b'}, 5, 7);
85  greaterThanAndLikeQuery("bytes_null_btree", "idx_bytes_null_btree", getBytes(4), new byte[] {(byte)'%', (byte)'b', (byte)'b', (byte)'%'}, 6, 7);
86  }
87 
88  public void hashIndexScanString() {
89  greaterEqualAndLikeQuery("bytes_null_hash", "none", getBytes(3), new byte[] {(byte)'%', (byte)'b', (byte)'b', (byte)'%'}, 3, 6, 7);
90  greaterThanAndLikeQuery("bytes_null_hash", "none", getBytes(3), new byte[] {(byte)'%', (byte)'b', (byte)'b', (byte)'%'}, 6, 7);
91  }
92 
93  public void bothIndexScanString() {
94  greaterEqualAndLikeQuery("bytes_null_both", "idx_bytes_null_both", getBytes(3), new byte[] {(byte)'%', (byte)'b', (byte)'b', (byte)'%'}, 3, 6, 7);
95  greaterThanAndLikeQuery("bytes_null_both", "idx_bytes_null_both", getBytes(3), new byte[] {(byte)'%', (byte)'b', (byte)'b', (byte)'%'}, 6, 7);
96  }
97 
98  public void noneIndexScanString() {
99  greaterEqualAndLikeQuery("bytes_null_none", "none", getBytes(3), new byte[] {(byte)'%', (byte)'b', (byte)'b', (byte)'%'}, 3, 6, 7);
100  greaterThanAndLikeQuery("bytes_null_none", "none", getBytes(3), new byte[] {(byte)'%', (byte)'b', (byte)'b', (byte)'%'}, 6, 7);
101  }
102 
103  private void createAllByteArrayTypesInstances(int number) {
104  for (int i = 0; i < number; ++i) {
105  ByteArrayTypes instance = session.newInstance(ByteArrayTypes.class);
106  instance.setId(i);
107  instance.setBytes_null_hash(getBytes(i));
108  instance.setBytes_null_btree(getBytes(i));
109  instance.setBytes_null_both(getBytes(i));
110  instance.setBytes_null_none(getBytes(i));
111  instances.add(instance);
112  }
113  }
114 
115  protected byte[] getBytes(int number) {
116  return bytes[number];
117  }
118 
123  @Override
124  protected void printResultInstance(IdBase instance) {
125  if (instance instanceof ByteArrayTypes) {
126  @SuppressWarnings("unused")
127  ByteArrayTypes stringType = (ByteArrayTypes)instance;
128 // System.out.println(toString(stringType));
129  }
130  }
131 
132 }