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 java.math.BigDecimal; 29 import java.math.BigInteger; 30 import java.sql.PreparedStatement; 31 import java.sql.ResultSet; 32 import java.sql.SQLException; 33 34 import testsuite.clusterj.model.BigIntegerTypes; 35 import testsuite.clusterj.model.IdBase; 36 37 public class BigIntegerTypesTest extends AbstractClusterJModelTest { 38 39 /** Test all BigIntegerTypes columns. 40 drop table if exists bigintegertypes; 41 create table bigintegertypes ( 42 id int not null primary key, 43 44 decimal_null_hash decimal(10), 45 decimal_null_btree decimal(10), 46 decimal_null_both decimal(10), 47 decimal_null_none decimal(10) 48 49 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1; 50 51 create unique index idx_decimal_null_hash using hash on bigintegertypes(decimal_null_hash); 52 create index idx_decimal_null_btree on bigintegertypes(decimal_null_btree); 53 create unique index idx_decimal_null_both on bigintegertypes(decimal_null_both); 54 55 */ 56 57 /** One of two main tests */ testWriteJDBCReadNDB()58 public void testWriteJDBCReadNDB() { 59 writeJDBCreadNDB(); 60 failOnError(); 61 } 62 63 /** One of two main tests */ testWriteNDBReadJDBC()64 public void testWriteNDBReadJDBC() { 65 writeNDBreadJDBC(); 66 failOnError(); 67 } 68 69 static int NUMBER_OF_INSTANCES = 10; 70 71 @Override getDebug()72 protected boolean getDebug() { 73 return false; 74 } 75 76 @Override getNumberOfInstances()77 protected int getNumberOfInstances() { 78 return NUMBER_OF_INSTANCES; 79 } 80 81 @Override getTableName()82 protected String getTableName() { 83 return "bigintegertypes"; 84 } 85 86 /** Subclasses override this method to provide the model class for the test */ 87 @Override getModelClass()88 Class<? extends IdBase> getModelClass() { 89 return BigIntegerTypes.class; 90 } 91 92 /** Subclasses override this method to provide values for rows (i) and columns (j) */ 93 @Override getColumnValue(int i, int j)94 protected Object getColumnValue(int i, int j) { 95 return BigInteger.valueOf(100000 * i + j); 96 } 97 98 static ColumnDescriptor decimal_null_hash = new ColumnDescriptor 99 ("decimal_null_hash", new InstanceHandler() { 100 public void setFieldValue(IdBase instance, Object value) { 101 ((BigIntegerTypes)instance).setDecimal_null_hash((BigInteger)value); 102 } 103 public Object getFieldValue(IdBase instance) { 104 return ((BigIntegerTypes)instance).getDecimal_null_hash(); 105 } 106 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value) 107 throws SQLException { 108 preparedStatement.setBigDecimal(j, new BigDecimal((BigInteger)value)); 109 } 110 public Object getResultSetValue(ResultSet rs, int j) throws SQLException { 111 return rs.getBigDecimal(j).toBigIntegerExact(); 112 } 113 }); 114 115 static ColumnDescriptor decimal_null_btree = new ColumnDescriptor 116 ("decimal_null_btree", new InstanceHandler() { 117 public void setFieldValue(IdBase instance, Object value) { 118 ((BigIntegerTypes)instance).setDecimal_null_btree((BigInteger)value); 119 } 120 public Object getFieldValue(IdBase instance) { 121 return ((BigIntegerTypes)instance).getDecimal_null_btree(); 122 } 123 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value) 124 throws SQLException { 125 preparedStatement.setBigDecimal(j, new BigDecimal((BigInteger)value)); 126 } 127 public Object getResultSetValue(ResultSet rs, int j) throws SQLException { 128 return rs.getBigDecimal(j).toBigIntegerExact(); 129 } 130 }); 131 static ColumnDescriptor decimal_null_both = new ColumnDescriptor 132 ("decimal_null_both", new InstanceHandler() { 133 public void setFieldValue(IdBase instance, Object value) { 134 ((BigIntegerTypes)instance).setDecimal_null_both((BigInteger)value); 135 } 136 public BigInteger getFieldValue(IdBase instance) { 137 return ((BigIntegerTypes)instance).getDecimal_null_both(); 138 } 139 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value) 140 throws SQLException { 141 preparedStatement.setBigDecimal(j, new BigDecimal((BigInteger)value)); 142 } 143 public Object getResultSetValue(ResultSet rs, int j) throws SQLException { 144 return rs.getBigDecimal(j).toBigIntegerExact(); 145 } 146 }); 147 static ColumnDescriptor decimal_null_none = new ColumnDescriptor 148 ("decimal_null_none", new InstanceHandler() { 149 public void setFieldValue(IdBase instance, Object value) { 150 ((BigIntegerTypes)instance).setDecimal_null_none((BigInteger)value); 151 } 152 public BigInteger getFieldValue(IdBase instance) { 153 return ((BigIntegerTypes)instance).getDecimal_null_none(); 154 } 155 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value) 156 throws SQLException { 157 preparedStatement.setBigDecimal(j, new BigDecimal((BigInteger)value)); 158 } 159 public Object getResultSetValue(ResultSet rs, int j) throws SQLException { 160 return rs.getBigDecimal(j).toBigIntegerExact(); 161 } 162 }); 163 164 protected static ColumnDescriptor[] columnDescriptors = new ColumnDescriptor[] { 165 decimal_null_hash, 166 decimal_null_btree, 167 decimal_null_both, 168 decimal_null_none 169 }; 170 171 @Override getColumnDescriptors()172 protected ColumnDescriptor[] getColumnDescriptors() { 173 return columnDescriptors; 174 } 175 176 } 177