2 Copyright (c) 2010, 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;
25 import org.junit.Ignore;
27 import testsuite.clusterj.model.IdBase;
28 import testsuite.clusterj.model.TimestampAsSqlTimestampTypes;
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.
35 drop table if exists timestamptypes;
36 create table timestamptypes (
37 id int not null primary key,
39 timestamp_not_null_hash timestamp,
40 timestamp_not_null_btree timestamp,
41 timestamp_not_null_both timestamp,
42 timestamp_not_null_none timestamp
44 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
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);
52 public class TimestampAsSqlTimestampTypesTest extends AbstractClusterJModelTest {
55 public void localSetUp() {
57 resetLocalSystemDefaultTimeZone(connection);
60 setAutoCommit(connection, false);
63 static int NUMBER_OF_INSTANCES = 10;
66 protected boolean getDebug() {
71 protected int getNumberOfInstances() {
72 return NUMBER_OF_INSTANCES;
76 protected String getTableName() {
77 return "timestamptypes";
80 /** Subclasses override this method to provide the model class for the test */
82 Class<? extends IdBase> getModelClass() {
83 return TimestampAsSqlTimestampTypes.class;
86 /** Subclasses override this method to provide values for rows (i) and columns (j) */
88 protected Object getColumnValue(int i, int j) {
89 return new Timestamp(getMillisFor(1980, 0, 1, i, i, j));
92 public void testWriteJDBCReadNDB() {
97 public void testWriteNDBReadJDBC() {
102 public void testWriteJDBCReadJDBC() {
107 public void testWriteNDBReadNDB() {
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);
117 public Object getFieldValue(IdBase instance) {
118 return ((TimestampAsSqlTimestampTypes)instance).getTimestamp_not_null_hash();
120 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
121 throws SQLException {
122 preparedStatement.setTimestamp(j, (Timestamp)value);
124 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
125 return rs.getTimestamp(j);
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);
134 public Object getFieldValue(IdBase instance) {
135 return ((TimestampAsSqlTimestampTypes)instance).getTimestamp_not_null_btree();
137 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
138 throws SQLException {
139 preparedStatement.setTimestamp(j, (Timestamp)value);
141 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
142 return rs.getTimestamp(j);
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);
150 public Timestamp getFieldValue(IdBase instance) {
151 return ((TimestampAsSqlTimestampTypes)instance).getTimestamp_not_null_both();
153 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
154 throws SQLException {
155 preparedStatement.setTimestamp(j, (Timestamp)value);
157 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
158 return rs.getTimestamp(j);
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);
166 public Timestamp getFieldValue(IdBase instance) {
167 return ((TimestampAsSqlTimestampTypes)instance).getTimestamp_not_null_none();
169 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
170 throws SQLException {
171 preparedStatement.setTimestamp(j, (Timestamp)value);
173 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
174 return rs.getTimestamp(j);
178 protected static ColumnDescriptor[] columnDescriptors = new ColumnDescriptor[] {
186 protected ColumnDescriptor[] getColumnDescriptors() {
187 return columnDescriptors;