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