]> review.fuel-infra Code Review - packages/trusty/mysql-wsrep-5.6.git/blob
6114eb9e6e9ad765fe3e8c730cfa89ba294fbf71
[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.sql.PreparedStatement;
22 import java.sql.ResultSet;
23 import java.sql.SQLException;
24 import java.sql.Time;
25 import testsuite.clusterj.model.IdBase;
26 import testsuite.clusterj.model.TimeAsSqlTimeTypes;
27
28 /** Test that Times can be read and written. 
29  * case 1: Write using JDBC, read using NDB.
30  * case 2: Write using NDB, read using JDBC.
31  * Schema
32  *
33 drop table if exists timetypes;
34 create table timetypes (
35  id int not null primary key,
36
37  time_null_hash time,
38  time_null_btree time,
39  time_null_both time,
40  time_null_none time,
41
42  time_not_null_hash time,
43  time_not_null_btree time,
44  time_not_null_both time,
45  time_not_null_none time
46
47 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
48
49 create unique index idx_time_null_hash using hash on timetypes(time_null_hash);
50 create index idx_time_null_btree on timetypes(time_null_btree);
51 create unique index idx_time_null_both on timetypes(time_null_both);
52
53 create unique index idx_time_not_null_hash using hash on timetypes(time_not_null_hash);
54 create index idx_time_not_null_btree on timetypes(time_not_null_btree);
55 create unique index idx_time_not_null_both on timetypes(time_not_null_both);
56  */
57 public class TimeAsSqlTimeTypesTest extends AbstractClusterJModelTest {
58
59     static int NUMBER_OF_INSTANCES = 10;
60
61     @Override
62     protected boolean getDebug() {
63         return false;
64     }
65
66     @Override
67     protected int getNumberOfInstances() {
68         return NUMBER_OF_INSTANCES;
69     }
70
71     @Override
72     protected String getTableName() {
73         return "timetypes";
74     }
75
76     /** Subclasses override this method to provide the model class for the test */
77     @Override
78     Class<? extends IdBase> getModelClass() {
79         return TimeAsSqlTimeTypes.class;
80     }
81
82     /** Subclasses override this method to provide values for rows (i) and columns (j) */
83     @Override
84     protected Object getColumnValue(int i, int j) {
85         return new Time(getMillisFor(0, i, i, j));
86     }
87
88     public void testWriteJDBCReadNDB() {
89         writeJDBCreadNDB();
90         failOnError();
91     }
92
93     public void testWriteNDBReadNDB() {
94         writeNDBreadNDB();
95         failOnError();
96     }
97
98     public void testWriteJDBCReadJDBC() {
99         writeJDBCreadJDBC();
100         failOnError();
101    }
102
103     public void testWriteNDBReadJDBC() {
104         writeNDBreadJDBC();
105         failOnError();
106    }
107
108    static ColumnDescriptor not_null_hash = new ColumnDescriptor
109             ("time_not_null_hash", new InstanceHandler() {
110         public void setFieldValue(IdBase instance, Object value) {
111             ((TimeAsSqlTimeTypes)instance).setTime_not_null_hash((Time)value);
112         }
113         public Object getFieldValue(IdBase instance) {
114             return ((TimeAsSqlTimeTypes)instance).getTime_not_null_hash();
115         }
116         public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
117                 throws SQLException {
118             preparedStatement.setTime(j, (Time)value);
119         }
120         public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
121             return rs.getTime(j);
122         }
123     });
124
125     static ColumnDescriptor not_null_btree = new ColumnDescriptor
126             ("time_not_null_btree", new InstanceHandler() {
127         public void setFieldValue(IdBase instance, Object value) {
128             ((TimeAsSqlTimeTypes)instance).setTime_not_null_btree((Time)value);
129         }
130         public Object getFieldValue(IdBase instance) {
131             return ((TimeAsSqlTimeTypes)instance).getTime_not_null_btree();
132         }
133         public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
134                 throws SQLException {
135             preparedStatement.setTime(j, (Time)value);
136         }
137         public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
138             return rs.getTime(j);
139         }
140     });
141
142     static ColumnDescriptor not_null_both = new ColumnDescriptor
143             ("time_not_null_both", new InstanceHandler() {
144         public void setFieldValue(IdBase instance, Object value) {
145             ((TimeAsSqlTimeTypes)instance).setTime_not_null_both((Time)value);
146         }
147         public Time getFieldValue(IdBase instance) {
148             return ((TimeAsSqlTimeTypes)instance).getTime_not_null_both();
149         }
150         public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
151                 throws SQLException {
152             preparedStatement.setTime(j, (Time)value);
153         }
154         public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
155             return rs.getTime(j);
156         }
157     });
158
159     static ColumnDescriptor not_null_none = new ColumnDescriptor
160             ("time_not_null_none", new InstanceHandler() {
161         public void setFieldValue(IdBase instance, Object value) {
162             ((TimeAsSqlTimeTypes)instance).setTime_not_null_none((Time)value);
163         }
164         public Time getFieldValue(IdBase instance) {
165             return ((TimeAsSqlTimeTypes)instance).getTime_not_null_none();
166         }
167         public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
168                 throws SQLException {
169             preparedStatement.setTime(j, (Time)value);
170         }
171         public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
172             return rs.getTime(j);
173         }
174     });
175
176     protected static ColumnDescriptor[] columnDescriptors = new ColumnDescriptor[] {
177             not_null_hash,
178             not_null_btree,
179             not_null_both,
180             not_null_none
181         };
182
183     @Override
184     protected ColumnDescriptor[] getColumnDescriptors() {
185         return columnDescriptors;
186     }
187
188 }