]> review.fuel-infra Code Review - packages/trusty/mysql-wsrep-5.6.git/blob
4138566a60ebce54323de56dfe50e07c0a3bfd21
[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 testsuite.clusterj;
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 testsuite.clusterj.model.BigIntegerTypes;
28 import testsuite.clusterj.model.IdBase;
29
30 public class BigIntegerTypesTest extends AbstractClusterJModelTest {
31
32     /** Test all BigIntegerTypes columns.
33 drop table if exists bigintegertypes;
34 create table bigintegertypes (
35  id int not null primary key,
36
37  decimal_null_hash decimal(10),
38  decimal_null_btree decimal(10),
39  decimal_null_both decimal(10),
40  decimal_null_none decimal(10)
41
42 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
43
44 create unique index idx_decimal_null_hash using hash on bigintegertypes(decimal_null_hash);
45 create index idx_decimal_null_btree on bigintegertypes(decimal_null_btree);
46 create unique index idx_decimal_null_both on bigintegertypes(decimal_null_both);
47
48      */
49
50     /** One of two main tests */
51     public void testWriteJDBCReadNDB() {
52         writeJDBCreadNDB();
53         failOnError();
54     }
55
56     /** One of two main tests */
57     public void testWriteNDBReadJDBC() {
58         writeNDBreadJDBC();
59         failOnError();
60    }
61
62     static int NUMBER_OF_INSTANCES = 10;
63
64     @Override
65     protected boolean getDebug() {
66         return false;
67     }
68
69     @Override
70     protected int getNumberOfInstances() {
71         return NUMBER_OF_INSTANCES;
72     }
73
74     @Override
75     protected String getTableName() {
76         return "bigintegertypes";
77     }
78
79     /** Subclasses override this method to provide the model class for the test */
80     @Override
81     Class<? extends IdBase> getModelClass() {
82         return BigIntegerTypes.class;
83     }
84
85     /** Subclasses override this method to provide values for rows (i) and columns (j) */
86     @Override
87     protected Object getColumnValue(int i, int j) {
88         return BigInteger.valueOf(100000  * i + j);
89     }
90
91    static ColumnDescriptor decimal_null_hash = new ColumnDescriptor
92             ("decimal_null_hash", new InstanceHandler() {
93         public void setFieldValue(IdBase instance, Object value) {
94             ((BigIntegerTypes)instance).setDecimal_null_hash((BigInteger)value);
95         }
96         public Object getFieldValue(IdBase instance) {
97             return ((BigIntegerTypes)instance).getDecimal_null_hash();
98         }
99         public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
100                 throws SQLException {
101             preparedStatement.setBigDecimal(j, new BigDecimal((BigInteger)value));
102         }
103         public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
104             return rs.getBigDecimal(j).toBigIntegerExact();
105         }
106     });
107
108     static ColumnDescriptor decimal_null_btree = new ColumnDescriptor
109             ("decimal_null_btree", new InstanceHandler() {
110         public void setFieldValue(IdBase instance, Object value) {
111             ((BigIntegerTypes)instance).setDecimal_null_btree((BigInteger)value);
112         }
113         public Object getFieldValue(IdBase instance) {
114             return ((BigIntegerTypes)instance).getDecimal_null_btree();
115         }
116         public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
117                 throws SQLException {
118             preparedStatement.setBigDecimal(j, new BigDecimal((BigInteger)value));
119         }
120         public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
121             return rs.getBigDecimal(j).toBigIntegerExact();
122         }
123     });
124     static ColumnDescriptor decimal_null_both = new ColumnDescriptor
125             ("decimal_null_both", new InstanceHandler() {
126         public void setFieldValue(IdBase instance, Object value) {
127             ((BigIntegerTypes)instance).setDecimal_null_both((BigInteger)value);
128         }
129         public BigInteger getFieldValue(IdBase instance) {
130             return ((BigIntegerTypes)instance).getDecimal_null_both();
131         }
132         public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
133                 throws SQLException {
134             preparedStatement.setBigDecimal(j, new BigDecimal((BigInteger)value));
135         }
136         public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
137             return rs.getBigDecimal(j).toBigIntegerExact();
138         }
139     });
140     static ColumnDescriptor decimal_null_none = new ColumnDescriptor
141             ("decimal_null_none", new InstanceHandler() {
142         public void setFieldValue(IdBase instance, Object value) {
143             ((BigIntegerTypes)instance).setDecimal_null_none((BigInteger)value);
144         }
145         public BigInteger getFieldValue(IdBase instance) {
146             return ((BigIntegerTypes)instance).getDecimal_null_none();
147         }
148         public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
149                 throws SQLException {
150             preparedStatement.setBigDecimal(j, new BigDecimal((BigInteger)value));
151         }
152         public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
153             return rs.getBigDecimal(j).toBigIntegerExact();
154         }
155     });
156
157     protected static ColumnDescriptor[] columnDescriptors = new ColumnDescriptor[] {
158         decimal_null_hash,
159         decimal_null_btree,
160         decimal_null_both,
161         decimal_null_none
162         };
163
164     @Override
165     protected ColumnDescriptor[] getColumnDescriptors() {
166         return columnDescriptors;
167     }
168
169 }