2 Copyright 2010 Sun Microsystems, Inc.
3 All rights reserved. Use is subject to license terms.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; version 2 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 package com.mysql.clusterj.jpatest;
21 import java.sql.PreparedStatement;
22 import java.sql.ResultSet;
23 import java.sql.SQLException;
24 import java.sql.Timestamp;
26 import com.mysql.clusterj.jpatest.model.TimestampAsSqlTimestampTypes;
27 import com.mysql.clusterj.jpatest.model.IdBase;
29 /** Test that Timestamps can be read and written.
30 * case 1: Write using JDBC, read using NDB.
31 * case 2: Write using NDB, read using JDBC.
34 drop table if exists timestamptypes;
35 create table timestamptypes (
36 id int not null primary key,
38 timestamp_not_null_hash timestamp,
39 timestamp_not_null_btree timestamp,
40 timestamp_not_null_both timestamp,
41 timestamp_not_null_none timestamp
43 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
45 create unique index idx_timestamp_not_null_hash using hash on timestamptypes(timestamp_not_null_hash);
46 create index idx_timestamp_not_null_btree on timestamptypes(timestamp_not_null_btree);
47 create unique index idx_timestamp_not_null_both on timestamptypes(timestamp_not_null_both);
50 public class TimestampAsSqlTimestampTest extends AbstractJPABaseTest {
56 resetLocalSystemDefaultTimeZone(connection);
59 setAutoCommit(connection, false);
62 static int NUMBER_OF_INSTANCES = 10;
65 protected boolean getDebug() {
70 protected int getNumberOfInstances() {
71 return NUMBER_OF_INSTANCES;
75 protected String getTableName() {
76 return "timestamptypes";
79 /** Subclasses override this method to provide the model class for the test */
81 protected Class<? extends IdBase> getModelClass() {
82 return TimestampAsSqlTimestampTypes.class;
85 /** Subclasses override this method to provide values for rows (i) and columns (j) */
87 protected Object getColumnValue(int i, int j) {
88 return new Timestamp(getMillisFor(1980, 0, i + 1, 0, 0, j));
92 /** Subclasses must override this method to implement the model factory for the test */
93 protected IdBase getNewInstance(Class<? extends IdBase> modelClass) {
94 return new TimestampAsSqlTimestampTypes();
97 public void testWriteJDBCReadJPA() {
102 public void testWriteJPAReadJDBC() {
107 public void testWriteJDBCReadJDBC() {
112 public void testWriteJPAReadJPA() {
117 static ColumnDescriptor not_null_hash = new ColumnDescriptor
118 ("timestamp_not_null_hash", new InstanceHandler() {
119 public void setFieldValue(IdBase instance, Object value) {
120 ((TimestampAsSqlTimestampTypes)instance).setTimestamp_not_null_hash((Timestamp)value);
122 public Object getFieldValue(IdBase instance) {
123 return ((TimestampAsSqlTimestampTypes)instance).getTimestamp_not_null_hash();
125 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
126 throws SQLException {
127 preparedStatement.setTimestamp(j, (Timestamp)value);
129 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
130 return rs.getTimestamp(j);
134 static ColumnDescriptor not_null_btree = new ColumnDescriptor
135 ("timestamp_not_null_btree", new InstanceHandler() {
136 public void setFieldValue(IdBase instance, Object value) {
137 ((TimestampAsSqlTimestampTypes)instance).setTimestamp_not_null_btree((Timestamp)value);
139 public Object getFieldValue(IdBase instance) {
140 return ((TimestampAsSqlTimestampTypes)instance).getTimestamp_not_null_btree();
142 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
143 throws SQLException {
144 preparedStatement.setTimestamp(j, (Timestamp)value);
146 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
147 return rs.getTimestamp(j);
151 static ColumnDescriptor not_null_both = new ColumnDescriptor
152 ("timestamp_not_null_both", new InstanceHandler() {
153 public void setFieldValue(IdBase instance, Object value) {
154 ((TimestampAsSqlTimestampTypes)instance).setTimestamp_not_null_both((Timestamp)value);
156 public Timestamp getFieldValue(IdBase instance) {
157 return ((TimestampAsSqlTimestampTypes)instance).getTimestamp_not_null_both();
159 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
160 throws SQLException {
161 preparedStatement.setTimestamp(j, (Timestamp)value);
163 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
164 return rs.getTimestamp(j);
168 static ColumnDescriptor not_null_none = new ColumnDescriptor
169 ("timestamp_not_null_none", new InstanceHandler() {
170 public void setFieldValue(IdBase instance, Object value) {
171 ((TimestampAsSqlTimestampTypes)instance).setTimestamp_not_null_none((Timestamp)value);
173 public Timestamp getFieldValue(IdBase instance) {
174 return ((TimestampAsSqlTimestampTypes)instance).getTimestamp_not_null_none();
176 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
177 throws SQLException {
178 preparedStatement.setTimestamp(j, (Timestamp)value);
180 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
181 return rs.getTimestamp(j);
185 protected static ColumnDescriptor[] columnDescriptors = new ColumnDescriptor[] {
193 protected ColumnDescriptor[] getColumnDescriptors() {
194 return columnDescriptors;