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