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 com.mysql.clusterj.jpatest;
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 com.mysql.clusterj.jpatest.model.BigIntegerTypes;
28 import com.mysql.clusterj.jpatest.model.IdBase;
31 public class BigIntegerTypesTest extends AbstractJPABaseTest {
33 /** Test all BigIntegerTypes columns.
34 drop table if exists bigintegertypes;
35 create table bigintegertypes (
36 id int not null primary key,
38 decimal_null_hash decimal(10),
39 decimal_null_btree decimal(10),
40 decimal_null_both decimal(10),
41 decimal_null_none decimal(10)
43 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
45 create unique index idx_decimal_null_hash using hash on bigintegertypes(decimal_null_hash);
46 create index idx_decimal_null_btree on bigintegertypes(decimal_null_btree);
47 create unique index idx_decimal_null_both on bigintegertypes(decimal_null_both);
51 public void testWriteJDBCReadJPA() {
56 public void testWriteJPAReadJDBC() {
61 public void testWriteJDBCReadJDBC() {
66 public void testWriteJPAReadJPA() {
71 static int NUMBER_OF_INSTANCES = 10;
74 protected boolean getDebug() {
79 protected int getNumberOfInstances() {
80 return NUMBER_OF_INSTANCES;
84 protected String getTableName() {
85 return "bigintegertypes";
88 /** Subclasses override this method to provide the model class for the test */
90 protected Class<? extends IdBase> getModelClass() {
91 return BigIntegerTypes.class;
94 /** Subclasses must override this method to implement the model factory for the test */
95 protected IdBase getNewInstance(Class<? extends IdBase> modelClass) {
96 return new BigIntegerTypes();
99 /** Subclasses override this method to provide values for rows (i) and columns (j) */
101 protected Object getColumnValue(int i, int j) {
102 return BigInteger.valueOf(i * 10000 + j);
105 static ColumnDescriptor decimal_null_hash = new ColumnDescriptor
106 ("decimal_null_hash", new InstanceHandler() {
107 public void setFieldValue(IdBase instance, Object value) {
108 ((BigIntegerTypes)instance).setDecimal_null_hash((BigInteger)value);
110 public Object getFieldValue(IdBase instance) {
111 return ((BigIntegerTypes)instance).getDecimal_null_hash();
113 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
114 throws SQLException {
115 preparedStatement.setBigDecimal(j, new BigDecimal((BigInteger)value));
117 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
118 return rs.getBigDecimal(j).toBigIntegerExact();
122 static ColumnDescriptor decimal_null_btree = new ColumnDescriptor
123 ("decimal_null_btree", new InstanceHandler() {
124 public void setFieldValue(IdBase instance, Object value) {
125 ((BigIntegerTypes)instance).setDecimal_null_btree((BigInteger)value);
127 public Object getFieldValue(IdBase instance) {
128 return ((BigIntegerTypes)instance).getDecimal_null_btree();
130 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
131 throws SQLException {
132 preparedStatement.setBigDecimal(j, new BigDecimal((BigInteger)value));
134 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
135 return rs.getBigDecimal(j).toBigIntegerExact();
138 static ColumnDescriptor decimal_null_both = new ColumnDescriptor
139 ("decimal_null_both", new InstanceHandler() {
140 public void setFieldValue(IdBase instance, Object value) {
141 ((BigIntegerTypes)instance).setDecimal_null_both((BigInteger)value);
143 public BigInteger getFieldValue(IdBase instance) {
144 return ((BigIntegerTypes)instance).getDecimal_null_both();
146 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
147 throws SQLException {
148 preparedStatement.setBigDecimal(j, new BigDecimal((BigInteger)value));
150 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
151 return rs.getBigDecimal(j).toBigIntegerExact();
154 static ColumnDescriptor decimal_null_none = new ColumnDescriptor
155 ("decimal_null_none", new InstanceHandler() {
156 public void setFieldValue(IdBase instance, Object value) {
157 ((BigIntegerTypes)instance).setDecimal_null_none((BigInteger)value);
159 public BigInteger getFieldValue(IdBase instance) {
160 return ((BigIntegerTypes)instance).getDecimal_null_none();
162 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
163 throws SQLException {
164 preparedStatement.setBigDecimal(j, new BigDecimal((BigInteger)value));
166 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
167 return rs.getBigDecimal(j).toBigIntegerExact();
171 protected static ColumnDescriptor[] columnDescriptors = new ColumnDescriptor[] {
179 protected ColumnDescriptor[] getColumnDescriptors() {
180 return columnDescriptors;