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.sql.PreparedStatement;
23 import java.sql.ResultSet;
24 import java.sql.SQLException;
26 import com.mysql.clusterj.jpatest.model.DecimalTypes;
27 import com.mysql.clusterj.jpatest.model.IdBase;
30 public class DecimalTypesTest extends AbstractJPABaseTest {
32 /** Test all DecimalTypes columns.
33 drop table if exists decimaltypes;
34 create table decimaltypes (
35 id int not null primary key,
37 decimal_null_hash decimal(10,5),
38 decimal_null_btree decimal(10,5),
39 decimal_null_both decimal(10,5),
40 decimal_null_none decimal(10,5)
42 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
44 create unique index idx_decimal_null_hash using hash on decimaltypes(decimal_null_hash);
45 create index idx_decimal_null_btree on decimaltypes(decimal_null_btree);
46 create unique index idx_decimal_null_both on decimaltypes(decimal_null_both);
50 public void testWriteJDBCReadJPA() {
55 public void testWriteJPAReadJDBC() {
60 public void testWriteJDBCReadJDBC() {
65 public void testWriteJPAReadJPA() {
70 static int NUMBER_OF_INSTANCES = 10;
73 protected boolean getDebug() {
78 protected int getNumberOfInstances() {
79 return NUMBER_OF_INSTANCES;
83 protected String getTableName() {
84 return "decimaltypes";
87 /** Subclasses override this method to provide the model class for the test */
89 protected Class<? extends IdBase> getModelClass() {
90 return DecimalTypes.class;
93 /** Subclasses must override this method to implement the model factory for the test */
94 protected IdBase getNewInstance(Class<? extends IdBase> modelClass) {
95 return new DecimalTypes();
98 /** Subclasses override this method to provide values for rows (i) and columns (j) */
100 protected Object getColumnValue(int i, int j) {
101 return BigDecimal.valueOf(i).add(BigDecimal.valueOf(j, 5));
104 static ColumnDescriptor decimal_null_hash = new ColumnDescriptor
105 ("decimal_null_hash", new InstanceHandler() {
106 public void setFieldValue(IdBase instance, Object value) {
107 ((DecimalTypes)instance).setDecimal_null_hash((BigDecimal)value);
109 public Object getFieldValue(IdBase instance) {
110 return ((DecimalTypes)instance).getDecimal_null_hash();
112 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
113 throws SQLException {
114 preparedStatement.setBigDecimal(j, (BigDecimal)value);
116 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
117 return rs.getBigDecimal(j);
121 static ColumnDescriptor decimal_null_btree = new ColumnDescriptor
122 ("decimal_null_btree", new InstanceHandler() {
123 public void setFieldValue(IdBase instance, Object value) {
124 ((DecimalTypes)instance).setDecimal_null_btree((BigDecimal)value);
126 public Object getFieldValue(IdBase instance) {
127 return ((DecimalTypes)instance).getDecimal_null_btree();
129 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
130 throws SQLException {
131 preparedStatement.setBigDecimal(j, (BigDecimal)value);
133 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
134 return rs.getBigDecimal(j);
137 static ColumnDescriptor decimal_null_both = new ColumnDescriptor
138 ("decimal_null_both", new InstanceHandler() {
139 public void setFieldValue(IdBase instance, Object value) {
140 ((DecimalTypes)instance).setDecimal_null_both((BigDecimal)value);
142 public BigDecimal getFieldValue(IdBase instance) {
143 return ((DecimalTypes)instance).getDecimal_null_both();
145 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
146 throws SQLException {
147 preparedStatement.setBigDecimal(j, (BigDecimal)value);
149 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
150 return rs.getBigDecimal(j);
153 static ColumnDescriptor decimal_null_none = new ColumnDescriptor
154 ("decimal_null_none", new InstanceHandler() {
155 public void setFieldValue(IdBase instance, Object value) {
156 ((DecimalTypes)instance).setDecimal_null_none((BigDecimal)value);
158 public BigDecimal getFieldValue(IdBase instance) {
159 return ((DecimalTypes)instance).getDecimal_null_none();
161 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
162 throws SQLException {
163 preparedStatement.setBigDecimal(j, (BigDecimal)value);
165 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
166 return rs.getBigDecimal(j);
170 protected static ColumnDescriptor[] columnDescriptors = new ColumnDescriptor[] {
178 protected ColumnDescriptor[] getColumnDescriptors() {
179 return columnDescriptors;