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.sql.PreparedStatement;
23 import java.sql.ResultSet;
24 import java.sql.SQLException;
26 import testsuite.clusterj.model.DecimalTypes;
27 import testsuite.clusterj.model.IdBase;
29 public class DecimalTypesTest extends AbstractClusterJModelTest {
31 /** Test all DecimalTypes columns.
32 drop table if exists decimaltypes;
33 create table decimaltypes (
34 id int not null primary key,
36 decimal_null_hash decimal(10,5),
37 decimal_null_btree decimal(10,5),
38 decimal_null_both decimal(10,5),
39 decimal_null_none decimal(10,5)
41 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
43 create unique index idx_decimal_null_hash using hash on decimaltypes(decimal_null_hash);
44 create index idx_decimal_null_btree on decimaltypes(decimal_null_btree);
45 create unique index idx_decimal_null_both on decimaltypes(decimal_null_both);
49 /** One of two main tests */
50 public void testWriteJDBCReadNDB() {
55 /** One of two main tests */
56 public void testWriteNDBReadJDBC() {
61 static int NUMBER_OF_INSTANCES = 10;
64 protected boolean getDebug() {
69 protected int getNumberOfInstances() {
70 return NUMBER_OF_INSTANCES;
74 protected String getTableName() {
75 return "decimaltypes";
78 /** Subclasses override this method to provide the model class for the test */
80 Class<? extends IdBase> getModelClass() {
81 return DecimalTypes.class;
84 /** Subclasses override this method to provide values for rows (i) and columns (j) */
86 protected Object getColumnValue(int i, int j) {
87 return BigDecimal.valueOf(i).add(BigDecimal.valueOf(j, 5));
90 static ColumnDescriptor decimal_null_hash = new ColumnDescriptor
91 ("decimal_null_hash", new InstanceHandler() {
92 public void setFieldValue(IdBase instance, Object value) {
93 ((DecimalTypes)instance).setDecimal_null_hash((BigDecimal)value);
95 public Object getFieldValue(IdBase instance) {
96 return ((DecimalTypes)instance).getDecimal_null_hash();
98 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
100 preparedStatement.setBigDecimal(j, (BigDecimal)value);
102 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
103 return rs.getBigDecimal(j);
107 static ColumnDescriptor decimal_null_btree = new ColumnDescriptor
108 ("decimal_null_btree", new InstanceHandler() {
109 public void setFieldValue(IdBase instance, Object value) {
110 ((DecimalTypes)instance).setDecimal_null_btree((BigDecimal)value);
112 public Object getFieldValue(IdBase instance) {
113 return ((DecimalTypes)instance).getDecimal_null_btree();
115 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
116 throws SQLException {
117 preparedStatement.setBigDecimal(j, (BigDecimal)value);
119 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
120 return rs.getBigDecimal(j);
123 static ColumnDescriptor decimal_null_both = new ColumnDescriptor
124 ("decimal_null_both", new InstanceHandler() {
125 public void setFieldValue(IdBase instance, Object value) {
126 ((DecimalTypes)instance).setDecimal_null_both((BigDecimal)value);
128 public BigDecimal getFieldValue(IdBase instance) {
129 return ((DecimalTypes)instance).getDecimal_null_both();
131 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
132 throws SQLException {
133 preparedStatement.setBigDecimal(j, (BigDecimal)value);
135 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
136 return rs.getBigDecimal(j);
139 static ColumnDescriptor decimal_null_none = new ColumnDescriptor
140 ("decimal_null_none", new InstanceHandler() {
141 public void setFieldValue(IdBase instance, Object value) {
142 ((DecimalTypes)instance).setDecimal_null_none((BigDecimal)value);
144 public BigDecimal getFieldValue(IdBase instance) {
145 return ((DecimalTypes)instance).getDecimal_null_none();
147 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
148 throws SQLException {
149 preparedStatement.setBigDecimal(j, (BigDecimal)value);
151 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
152 return rs.getBigDecimal(j);
156 protected static ColumnDescriptor[] columnDescriptors = new ColumnDescriptor[] {
164 protected ColumnDescriptor[] getColumnDescriptors() {
165 return columnDescriptors;