2 Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
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.
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.
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
18 package testsuite.clusterj;
20 import java.util.Arrays;
21 import java.util.HashSet;
23 import com.mysql.clusterj.ClusterJUserException;
25 import testsuite.clusterj.model.AllPrimitives;
27 /** Query for columns compared via IN.
28 * Predicates using IN cannot use indexes, although indexes can
29 * be used for AND predicates where some of the predicates are IN
31 * This test is based on AbstractQueryTest.
33 public class QueryInTest extends AbstractQueryTest {
35 drop table if exists allprimitives;
36 create table allprimitives (
37 id int not null primary key,
39 int_not_null_hash int not null,
40 int_not_null_btree int not null,
41 int_not_null_both int not null,
42 int_not_null_none int not null,
48 byte_not_null_hash tinyint not null,
49 byte_not_null_btree tinyint not null,
50 byte_not_null_both tinyint not null,
51 byte_not_null_none tinyint not null,
52 byte_null_hash tinyint,
53 byte_null_btree tinyint,
54 byte_null_both tinyint,
55 byte_null_none tinyint,
57 short_not_null_hash smallint not null,
58 short_not_null_btree smallint not null,
59 short_not_null_both smallint not null,
60 short_not_null_none smallint not null,
61 short_null_hash smallint,
62 short_null_btree smallint,
63 short_null_both smallint,
64 short_null_none smallint,
66 long_not_null_hash bigint not null,
67 long_not_null_btree bigint not null,
68 long_not_null_both bigint not null,
69 long_not_null_none bigint not null,
70 long_null_hash bigint,
71 long_null_btree bigint,
72 long_null_both bigint,
77 public Class<?> getInstanceType() {
78 return AllPrimitives.class;
82 void createInstances(int number) {
83 createAllPrimitivesInstances(10);
86 public void testBtreeEqualOrIn() {
87 equalOrInQuery("int_not_null_btree", 4, "int_null_none", new Object[] {}, "none", 4);
88 equalOrInQuery("int_not_null_btree", 4, "int_null_none", new Object[] {6, 9}, "none", 4, 6, 9);
89 equalOrInQuery("int_null_btree", 4, "int_null_none", new Object[] {4, 6, 9}, "none", 4, 6, 9);
90 equalOrInQuery("int_null_btree", 4, "int_null_none", new Object[] {6, 6, 6, 9}, "none", 4, 6, 9);
92 equalOrInQuery("int_not_null_btree", 4, "int_null_none", Arrays.asList(new Object[] {}), "none", 4);
93 equalOrInQuery("int_not_null_btree", 4, "int_null_none", Arrays.asList(new Integer[] {6, 9}), "none", 4, 6, 9);
94 equalOrInQuery("int_null_btree", 4, "int_null_none", new HashSet<Integer>(Arrays.asList(new Integer[] {4, 6, 9})), "none", 4, 6, 9);
95 equalOrInQuery("int_null_btree", 4, "int_null_none", new HashSet<Integer>(Arrays.asList(new Integer[] {6, 6, 6, 9})), "none", 4, 6, 9);
99 public void testIn() {
100 inQuery("int_not_null_none", new Object[] {4, 6, 9}, "none", 4, 6, 9);
101 inQuery("int_not_null_hash", Arrays.asList(new Object[] {4, 6, 9}), "none", 4, 6, 9);
102 inQuery("int_not_null_both", new Object[] {4, 6, 9}, "idx_int_not_null_both", 4, 6, 9);
103 inQuery("int_not_null_btree", new Object[] {4, 6, 9}, "idx_int_not_null_btree", 4, 6, 9);
107 public void testInAndIn() {
108 inAndInQuery("int_not_null_none", new Object[] {4, 6, 9}, "id", new Object[] {4, 9}, "PRIMARY", 4, 9);
109 inAndInQuery("int_not_null_hash", new Object[] {4, 9}, "int_not_null_both", new Object[] {6, 9}, "idx_int_not_null_both", 9);
110 inAndInQuery("int_not_null_hash", new Object[] {4, 9}, "int_not_null_btree", new Object[] {6, 9}, "idx_int_not_null_btree", 9);
111 inAndInQuery("int_not_null_both", new Object[] {4, 9}, "int_not_null_hash", new Object[] {6, 9}, "idx_int_not_null_both", 9);
112 inAndInQuery("int_not_null_btree", new Object[] {4, 9}, "int_not_null_hash", new Object[] {6, 9}, "idx_int_not_null_btree", 9);
116 public void testHashEqualOrIn() {
117 equalOrInQuery("int_not_null_hash", 4, "int_null_both", new Object[] {6, 9}, "none", 4, 6, 9);
118 equalOrInQuery("int_null_hash", 4, "int_null_both", new Object[] {6, 9}, "none", 4, 6, 9);
122 public void testBothEqualOrIn() {
123 equalOrInQuery("int_not_null_both", 4, "int_null_hash", new Object[] {6, 9}, "none", 4, 6, 9);
124 equalOrInQuery("int_null_both", 4, "int_null_hash", new Object[] {6, 9}, "none", 4, 6, 9);
128 public void testNoneEqualOrIn() {
129 equalOrInQuery("int_not_null_none", 4, "int_null_btree", new Object[] {6, 9}, "none", 4, 6, 9);
130 equalOrInQuery("int_null_none", 4, "int_null_btree", new Object[] {6, 9}, "none", 4, 6, 9);
134 public void testNullParameterForIn() {
136 equalOrInQuery("int_not_null_btree", 4, "int_null_none", null, "none", 4);
137 fail("testNullParameterForIn should throw ClusterJUserException.");
138 } catch (ClusterJUserException ex) {