2 Copyright 2010 Sun Microsystems, Inc.
3 All rights reserved. Use is subject to license terms.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; version 2 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 package testsuite.clusterj;
21 import java.math.BigDecimal;
22 import java.math.BigInteger;
23 import java.sql.PreparedStatement;
24 import java.sql.ResultSet;
25 import java.sql.SQLException;
27 import testsuite.clusterj.model.BigIntegerTypes;
28 import testsuite.clusterj.model.IdBase;
30 public class BigIntegerTypesTest extends AbstractClusterJModelTest {
32 /** Test all BigIntegerTypes columns.
33 drop table if exists bigintegertypes;
34 create table bigintegertypes (
35 id int not null primary key,
37 decimal_null_hash decimal(10),
38 decimal_null_btree decimal(10),
39 decimal_null_both decimal(10),
40 decimal_null_none decimal(10)
42 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
44 create unique index idx_decimal_null_hash using hash on bigintegertypes(decimal_null_hash);
45 create index idx_decimal_null_btree on bigintegertypes(decimal_null_btree);
46 create unique index idx_decimal_null_both on bigintegertypes(decimal_null_both);
50 /** One of two main tests */
51 public void testWriteJDBCReadNDB() {
56 /** One of two main tests */
57 public void testWriteNDBReadJDBC() {
62 static int NUMBER_OF_INSTANCES = 10;
65 protected boolean getDebug() {
70 protected int getNumberOfInstances() {
71 return NUMBER_OF_INSTANCES;
75 protected String getTableName() {
76 return "bigintegertypes";
79 /** Subclasses override this method to provide the model class for the test */
81 Class<? extends IdBase> getModelClass() {
82 return BigIntegerTypes.class;
85 /** Subclasses override this method to provide values for rows (i) and columns (j) */
87 protected Object getColumnValue(int i, int j) {
88 return BigInteger.valueOf(100000 * i + j);
91 static ColumnDescriptor decimal_null_hash = new ColumnDescriptor
92 ("decimal_null_hash", new InstanceHandler() {
93 public void setFieldValue(IdBase instance, Object value) {
94 ((BigIntegerTypes)instance).setDecimal_null_hash((BigInteger)value);
96 public Object getFieldValue(IdBase instance) {
97 return ((BigIntegerTypes)instance).getDecimal_null_hash();
99 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
100 throws SQLException {
101 preparedStatement.setBigDecimal(j, new BigDecimal((BigInteger)value));
103 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
104 return rs.getBigDecimal(j).toBigIntegerExact();
108 static ColumnDescriptor decimal_null_btree = new ColumnDescriptor
109 ("decimal_null_btree", new InstanceHandler() {
110 public void setFieldValue(IdBase instance, Object value) {
111 ((BigIntegerTypes)instance).setDecimal_null_btree((BigInteger)value);
113 public Object getFieldValue(IdBase instance) {
114 return ((BigIntegerTypes)instance).getDecimal_null_btree();
116 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
117 throws SQLException {
118 preparedStatement.setBigDecimal(j, new BigDecimal((BigInteger)value));
120 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
121 return rs.getBigDecimal(j).toBigIntegerExact();
124 static ColumnDescriptor decimal_null_both = new ColumnDescriptor
125 ("decimal_null_both", new InstanceHandler() {
126 public void setFieldValue(IdBase instance, Object value) {
127 ((BigIntegerTypes)instance).setDecimal_null_both((BigInteger)value);
129 public BigInteger getFieldValue(IdBase instance) {
130 return ((BigIntegerTypes)instance).getDecimal_null_both();
132 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
133 throws SQLException {
134 preparedStatement.setBigDecimal(j, new BigDecimal((BigInteger)value));
136 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
137 return rs.getBigDecimal(j).toBigIntegerExact();
140 static ColumnDescriptor decimal_null_none = new ColumnDescriptor
141 ("decimal_null_none", new InstanceHandler() {
142 public void setFieldValue(IdBase instance, Object value) {
143 ((BigIntegerTypes)instance).setDecimal_null_none((BigInteger)value);
145 public BigInteger getFieldValue(IdBase instance) {
146 return ((BigIntegerTypes)instance).getDecimal_null_none();
148 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
149 throws SQLException {
150 preparedStatement.setBigDecimal(j, new BigDecimal((BigInteger)value));
152 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
153 return rs.getBigDecimal(j).toBigIntegerExact();
157 protected static ColumnDescriptor[] columnDescriptors = new ColumnDescriptor[] {
165 protected ColumnDescriptor[] getColumnDescriptors() {
166 return columnDescriptors;