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, version 2.0, 7 as published by the Free Software Foundation. 8 9 This program is also distributed with certain software (including 10 but not limited to OpenSSL) that is licensed under separate terms, 11 as designated in a particular file or component or in included license 12 documentation. The authors of MySQL hereby grant you an additional 13 permission to link the program and your derivative works with the 14 separately licensed software that they have included with MySQL. 15 16 This program is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License, version 2.0, for more details. 20 21 You should have received a copy of the GNU General Public License 22 along with this program; if not, write to the Free Software 23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 */ 25 26 package testsuite.clusterj; 27 28 import testsuite.clusterj.model.AllPrimitives; 29 30 import com.mysql.clusterj.ClusterJUserException; 31 32 /** Query for columns compared to null. Comparisons using greaterThan, 33 * greaterEqual, lessThan, and lessEqual throw ClusterJUserException. 34 * Predicates using equal null cannot use indexes, although indexes can 35 * be used for non-null comparisons. 36 * This test is based on QueryExtraConditionsTest. 37 */ 38 public class QueryNullTest extends AbstractQueryTest { 39 /* 40 drop table if exists allprimitives; 41 create table allprimitives ( 42 id int not null primary key, 43 44 int_not_null_hash int not null, 45 int_not_null_btree int not null, 46 int_not_null_both int not null, 47 int_not_null_none int not null, 48 int_null_hash int, 49 int_null_btree int, 50 int_null_both int, 51 int_null_none int, 52 53 byte_not_null_hash tinyint not null, 54 byte_not_null_btree tinyint not null, 55 byte_not_null_both tinyint not null, 56 byte_not_null_none tinyint not null, 57 byte_null_hash tinyint, 58 byte_null_btree tinyint, 59 byte_null_both tinyint, 60 byte_null_none tinyint, 61 62 short_not_null_hash smallint not null, 63 short_not_null_btree smallint not null, 64 short_not_null_both smallint not null, 65 short_not_null_none smallint not null, 66 short_null_hash smallint, 67 short_null_btree smallint, 68 short_null_both smallint, 69 short_null_none smallint, 70 71 long_not_null_hash bigint not null, 72 long_not_null_btree bigint not null, 73 long_not_null_both bigint not null, 74 long_not_null_none bigint not null, 75 long_null_hash bigint, 76 long_null_btree bigint, 77 long_null_both bigint, 78 long_null_none bigint 79 */ 80 81 @Override getInstanceType()82 public Class<?> getInstanceType() { 83 return AllPrimitives.class; 84 } 85 86 @Override createInstances(int number)87 void createInstances(int number) { 88 createAllPrimitivesInstances(10); 89 } 90 testExtraEqualNull()91 public void testExtraEqualNull() { 92 equalAnd1ExtraQuery("int_not_null_btree", 8, "int_null_none", extraEqualPredicateProvider, null, "idx_int_not_null_btree"); 93 equalAnd1ExtraQuery("int_not_null_hash", 8, "int_null_none", extraEqualPredicateProvider, null, "none"); 94 equalAnd1ExtraQuery("int_not_null_both", 8, "int_null_none", extraEqualPredicateProvider, null, "idx_int_not_null_both"); 95 equalAnd1ExtraQuery("int_not_null_none", 8, "int_null_none", extraEqualPredicateProvider, null, "none"); 96 failOnError(); 97 } 98 testBtreeEqualNull()99 public void testBtreeEqualNull() { 100 equalQuery("int_not_null_btree", "none", null); 101 equalQuery("int_null_btree", "none", null); 102 failOnError(); 103 } 104 testHashEqualNull()105 public void testHashEqualNull() { 106 equalQuery("int_not_null_hash", "none", null); 107 equalQuery("int_null_hash", "none", null); 108 failOnError(); 109 } 110 testBothEqualNull()111 public void testBothEqualNull() { 112 equalQuery("int_not_null_both", "none", null); 113 equalQuery("int_null_both", "none", null); 114 failOnError(); 115 } 116 testNoneEqualNull()117 public void testNoneEqualNull() { 118 equalQuery("int_not_null_none", "none", null); 119 equalQuery("int_null_none", "none", null); 120 failOnError(); 121 } 122 testGreaterThanNull()123 public void testGreaterThanNull() { 124 try { 125 greaterThanQuery("int_not_null_btree", "none", null); 126 error("Greater than query should throw ClusterJUserException with null parameter."); 127 } catch (ClusterJUserException ex) { 128 // good catch 129 } 130 } 131 testGreaterEqualNull()132 public void testGreaterEqualNull() { 133 try { 134 greaterEqualQuery("int_not_null_btree", "none", null); 135 error("Greater equal query should throw ClusterJUserException with null parameter."); 136 } catch (ClusterJUserException ex) { 137 // good catch 138 } 139 } 140 testLessThanNull()141 public void testLessThanNull() { 142 try { 143 lessThanQuery("int_not_null_btree", "none", null); 144 error("Less than query should throw ClusterJUserException with null parameter."); 145 } catch (ClusterJUserException ex) { 146 // good catch 147 } 148 } 149 testLessEqualNull()150 public void testLessEqualNull() { 151 try { 152 lessEqualQuery("int_not_null_btree", "none", null); 153 error("Less equal query should throw ClusterJUserException with null parameter."); 154 } catch (ClusterJUserException ex) { 155 // good catch 156 } 157 } 158 159 } 160