2
Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
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.
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.
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
18
package testsuite.clusterj;
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;
26
import org.junit.Ignore;
28
import testsuite.clusterj.model.IdBase;
29
import testsuite.clusterj.model.TimestampAsUtilDateTypes;
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.
36
drop table if exists timestamptypes;
37
create table timestamptypes (
38
id int not null primary key,
40
timestamp_not_null_hash timestamp,
41
timestamp_not_null_btree timestamp,
42
timestamp_not_null_both timestamp,
43
timestamp_not_null_none timestamp
45
) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
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);
53
public class TimestampAsUtilDateTypesTest extends AbstractClusterJModelTest {
56
public void localSetUp() {
59
resetLocalSystemDefaultTimeZone(connection);
62
setAutoCommit(connection, false);
65
static int NUMBER_OF_INSTANCES = 10;
68
protected boolean getDebug() {
73
protected int getNumberOfInstances() {
74
return NUMBER_OF_INSTANCES;
78
protected String getTableName() {
79
return "timestamptypes";
82
/** Subclasses override this method to provide the model class for the test */
84
Class<? extends IdBase> getModelClass() {
85
return TimestampAsUtilDateTypes.class;
88
/** Subclasses override this method to provide values for rows (i) and columns (j) */
90
protected Object getColumnValue(int i, int j) {
91
return new Date(getMillisFor(1980, 0, 1, i, i, j));
94
public void testWriteJDBCReadNDB() {
99
public void testWriteNDBReadJDBC() {
104
public void testWriteJDBCReadJDBC() {
109
public void testWriteNDBReadNDB() {
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);
119
public Object getFieldValue(IdBase instance) {
120
return ((TimestampAsUtilDateTypes)instance).getTimestamp_not_null_hash();
122
public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
123
throws SQLException {
124
preparedStatement.setTimestamp(j, new Timestamp(((Date)value).getTime()));
126
public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
127
return rs.getTimestamp(j);
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);
136
public Object getFieldValue(IdBase instance) {
137
return ((TimestampAsUtilDateTypes)instance).getTimestamp_not_null_btree();
139
public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
140
throws SQLException {
141
preparedStatement.setTimestamp(j, new Timestamp(((Date)value).getTime()));
143
public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
144
return rs.getTimestamp(j);
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);
152
public Date getFieldValue(IdBase instance) {
153
return ((TimestampAsUtilDateTypes)instance).getTimestamp_not_null_both();
155
public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
156
throws SQLException {
157
preparedStatement.setTimestamp(j, new Timestamp(((Date)value).getTime()));
159
public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
160
return rs.getTimestamp(j);
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);
168
public Date getFieldValue(IdBase instance) {
169
return ((TimestampAsUtilDateTypes)instance).getTimestamp_not_null_none();
171
public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
172
throws SQLException {
173
preparedStatement.setTimestamp(j, new Timestamp(((Date)value).getTime()));
175
public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
176
return rs.getTimestamp(j);
180
protected static ColumnDescriptor[] columnDescriptors = new ColumnDescriptor[] {
188
protected ColumnDescriptor[] getColumnDescriptors() {
189
return columnDescriptors;