]> review.fuel-infra Code Review - packages/trusty/mysql-wsrep-5.6.git/blob
dd1c13b83b7558d4e1361ebf3743e103cd429949
[packages/trusty/mysql-wsrep-5.6.git] /
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 as published by
7    the Free Software Foundation; version 2 of the License.
8
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.
13
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
17 */
18
19 package com.mysql.clusterj.jpatest;
20
21 import java.math.BigDecimal;
22 import java.sql.PreparedStatement;
23 import java.sql.ResultSet;
24 import java.sql.SQLException;
25
26 import com.mysql.clusterj.jpatest.model.DecimalTypes;
27 import com.mysql.clusterj.jpatest.model.IdBase;
28
29
30 public class DecimalTypesTest extends AbstractJPABaseTest {
31
32     /** Test all DecimalTypes columns.
33 drop table if exists decimaltypes;
34 create table decimaltypes (
35  id int not null primary key,
36
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)
41
42 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
43
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);
47
48      */
49
50     public void testWriteJDBCReadJPA() {
51         writeJDBCreadJPA();
52         failOnError();
53     }
54
55     public void testWriteJPAReadJDBC() {
56         writeJPAreadJDBC();
57         failOnError();
58    }
59
60     public void testWriteJDBCReadJDBC() {
61         writeJDBCreadJDBC();
62         failOnError();
63     }
64
65     public void testWriteJPAReadJPA() {
66         writeJPAreadJPA();
67         failOnError();
68    }
69
70     static int NUMBER_OF_INSTANCES = 10;
71
72     @Override
73     protected boolean getDebug() {
74         return false;
75     }
76
77     @Override
78     protected int getNumberOfInstances() {
79         return NUMBER_OF_INSTANCES;
80     }
81
82     @Override
83     protected String getTableName() {
84         return "decimaltypes";
85     }
86
87     /** Subclasses override this method to provide the model class for the test */
88     @Override
89     protected Class<? extends IdBase> getModelClass() {
90         return DecimalTypes.class;
91     }
92
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();
96     }
97
98     /** Subclasses override this method to provide values for rows (i) and columns (j) */
99     @Override
100     protected Object getColumnValue(int i, int j) {
101         return BigDecimal.valueOf(i).add(BigDecimal.valueOf(j, 5));
102     }
103
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);
108         }
109         public Object getFieldValue(IdBase instance) {
110             return ((DecimalTypes)instance).getDecimal_null_hash();
111         }
112         public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
113                 throws SQLException {
114             preparedStatement.setBigDecimal(j, (BigDecimal)value);
115         }
116         public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
117             return rs.getBigDecimal(j);
118         }
119     });
120
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);
125         }
126         public Object getFieldValue(IdBase instance) {
127             return ((DecimalTypes)instance).getDecimal_null_btree();
128         }
129         public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
130                 throws SQLException {
131             preparedStatement.setBigDecimal(j, (BigDecimal)value);
132         }
133         public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
134             return rs.getBigDecimal(j);
135         }
136     });
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);
141         }
142         public BigDecimal getFieldValue(IdBase instance) {
143             return ((DecimalTypes)instance).getDecimal_null_both();
144         }
145         public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
146                 throws SQLException {
147             preparedStatement.setBigDecimal(j, (BigDecimal)value);
148         }
149         public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
150             return rs.getBigDecimal(j);
151         }
152     });
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);
157         }
158         public BigDecimal getFieldValue(IdBase instance) {
159             return ((DecimalTypes)instance).getDecimal_null_none();
160         }
161         public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
162                 throws SQLException {
163             preparedStatement.setBigDecimal(j, (BigDecimal)value);
164         }
165         public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
166             return rs.getBigDecimal(j);
167         }
168     });
169
170     protected static ColumnDescriptor[] columnDescriptors = new ColumnDescriptor[] {
171         decimal_null_hash,
172         decimal_null_btree,
173         decimal_null_both,
174         decimal_null_none
175         };
176
177     @Override
178     protected ColumnDescriptor[] getColumnDescriptors() {
179         return columnDescriptors;
180     }
181
182 }