MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QueryInTest.java
1 /*
2 Copyright (c) 2010, 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 java.util.Arrays;
21 import java.util.HashSet;
22 
23 import com.mysql.clusterj.ClusterJUserException;
24 
25 import testsuite.clusterj.model.AllPrimitives;
26 
33 public class QueryInTest extends AbstractQueryTest {
34  /*
35  drop table if exists allprimitives;
36  create table allprimitives (
37  id int not null primary key,
38 
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,
43  int_null_hash int,
44  int_null_btree int,
45  int_null_both int,
46  int_null_none int,
47 
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,
56 
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,
65 
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,
73  long_null_none bigint
74  */
75 
76  @Override
77  public Class<?> getInstanceType() {
78  return AllPrimitives.class;
79  }
80 
81  @Override
82  void createInstances(int number) {
83  createAllPrimitivesInstances(10);
84  }
85 
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);
91 
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);
96  failOnError();
97  }
98 
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);
104  failOnError();
105  }
106 
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);
113  failOnError();
114  }
115 
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);
119  failOnError();
120  }
121 
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);
125  failOnError();
126  }
127 
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);
131  failOnError();
132  }
133 
134  public void testNullParameterForIn() {
135  try {
136  equalOrInQuery("int_not_null_btree", 4, "int_null_none", null, "none", 4);
137  fail("testNullParameterForIn should throw ClusterJUserException.");
138  } catch (ClusterJUserException ex) {
139  // good catch
140  }
141  }
142 }