]> review.fuel-infra Code Review - packages/trusty/mysql-wsrep-5.6.git/blob
472f7947af624402c3fba95003cd9a3c6b39eea7
[packages/trusty/mysql-wsrep-5.6.git] /
1 /*
2    Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; version 2 of the License.
7
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12
13    You should have received a copy of the GNU General Public License
14    along with this program; if not, write to the Free Software
15    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
16 */
17
18 package testsuite.clusterj;
19
20 import java.sql.PreparedStatement;
21 import java.sql.ResultSet;
22 import java.sql.SQLException;
23 import java.sql.Timestamp;
24 import java.util.Date;
25
26 import org.junit.Ignore;
27
28 import testsuite.clusterj.model.IdBase;
29 import testsuite.clusterj.model.TimestampAsUtilDateTypes;
30
31 /** Test that Timestamps can be read and written. 
32  * case 1: Write using JDBC, read using NDB.
33  * case 2: Write using NDB, read using JDBC.
34  * Schema
35  *
36 drop table if exists timestamptypes;
37 create table timestamptypes (
38  id int not null primary key,
39
40  timestamp_not_null_hash timestamp,
41  timestamp_not_null_btree timestamp,
42  timestamp_not_null_both timestamp,
43  timestamp_not_null_none timestamp
44
45 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
46
47 create unique index idx_timestamp_not_null_hash using hash on timestamptypes(timestamp_not_null_hash);
48 create index idx_timestamp_not_null_btree on timestamptypes(timestamp_not_null_btree);
49 create unique index idx_timestamp_not_null_both on timestamptypes(timestamp_not_null_both);
50
51  */
52 @Ignore
53 public class TimestampAsUtilDateTypesTest extends AbstractClusterJModelTest {
54
55     @Override
56     public void localSetUp() {
57         super.localSetUp();
58         getConnection();
59         resetLocalSystemDefaultTimeZone(connection);
60         connection = null;
61         getConnection();
62         setAutoCommit(connection, false);
63     }
64
65     static int NUMBER_OF_INSTANCES = 10;
66
67     @Override
68     protected boolean getDebug() {
69         return false;
70     }
71
72     @Override
73     protected int getNumberOfInstances() {
74         return NUMBER_OF_INSTANCES;
75     }
76
77     @Override
78     protected String getTableName() {
79         return "timestamptypes";
80     }
81
82     /** Subclasses override this method to provide the model class for the test */
83     @Override
84     Class<? extends IdBase> getModelClass() {
85         return TimestampAsUtilDateTypes.class;
86     }
87
88     /** Subclasses override this method to provide values for rows (i) and columns (j) */
89     @Override
90     protected Object getColumnValue(int i, int j) {
91         return new Date(getMillisFor(1980, 0, 1, i, i, j));
92     }
93
94     public void testWriteJDBCReadNDB() {
95         writeJDBCreadNDB();
96         failOnError();
97     }
98
99     public void testWriteNDBReadJDBC() {
100         writeNDBreadJDBC();
101         failOnError();
102    }
103
104     public void testWriteJDBCReadJDBC() {
105         writeJDBCreadJDBC();
106         failOnError();
107     }
108
109     public void testWriteNDBReadNDB() {
110         writeNDBreadNDB();
111         failOnError();
112    }
113
114    static ColumnDescriptor not_null_hash = new ColumnDescriptor
115             ("timestamp_not_null_hash", new InstanceHandler() {
116         public void setFieldValue(IdBase instance, Object value) {
117             ((TimestampAsUtilDateTypes)instance).setTimestamp_not_null_hash((Date)value);
118         }
119         public Object getFieldValue(IdBase instance) {
120             return ((TimestampAsUtilDateTypes)instance).getTimestamp_not_null_hash();
121         }
122         public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
123                 throws SQLException {
124             preparedStatement.setTimestamp(j, new Timestamp(((Date)value).getTime()));
125         }
126         public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
127             return rs.getTimestamp(j);
128         }
129     });
130
131     static ColumnDescriptor not_null_btree = new ColumnDescriptor
132             ("timestamp_not_null_btree", new InstanceHandler() {
133         public void setFieldValue(IdBase instance, Object value) {
134             ((TimestampAsUtilDateTypes)instance).setTimestamp_not_null_btree((Date)value);
135         }
136         public Object getFieldValue(IdBase instance) {
137             return ((TimestampAsUtilDateTypes)instance).getTimestamp_not_null_btree();
138         }
139         public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
140                 throws SQLException {
141             preparedStatement.setTimestamp(j, new Timestamp(((Date)value).getTime()));
142         }
143         public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
144             return rs.getTimestamp(j);
145         }
146     });
147     static ColumnDescriptor not_null_both = new ColumnDescriptor
148             ("timestamp_not_null_both", new InstanceHandler() {
149         public void setFieldValue(IdBase instance, Object value) {
150             ((TimestampAsUtilDateTypes)instance).setTimestamp_not_null_both((Date)value);
151         }
152         public Date getFieldValue(IdBase instance) {
153             return ((TimestampAsUtilDateTypes)instance).getTimestamp_not_null_both();
154         }
155         public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
156                 throws SQLException {
157             preparedStatement.setTimestamp(j, new Timestamp(((Date)value).getTime()));
158         }
159         public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
160             return rs.getTimestamp(j);
161         }
162     });
163     static ColumnDescriptor not_null_none = new ColumnDescriptor
164             ("timestamp_not_null_none", new InstanceHandler() {
165         public void setFieldValue(IdBase instance, Object value) {
166             ((TimestampAsUtilDateTypes)instance).setTimestamp_not_null_none((Date)value);
167         }
168         public Date getFieldValue(IdBase instance) {
169             return ((TimestampAsUtilDateTypes)instance).getTimestamp_not_null_none();
170         }
171         public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
172                 throws SQLException {
173             preparedStatement.setTimestamp(j, new Timestamp(((Date)value).getTime()));
174         }
175         public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
176             return rs.getTimestamp(j);
177         }
178     });
179
180     protected static ColumnDescriptor[] columnDescriptors = new ColumnDescriptor[] {
181             not_null_hash,
182             not_null_btree,
183             not_null_both,
184             not_null_none
185         };
186
187     @Override
188     protected ColumnDescriptor[] getColumnDescriptors() {
189         return columnDescriptors;
190     }
191
192 }