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