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