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