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 testsuite.clusterj;
21 import java.sql.PreparedStatement;
22 import java.sql.ResultSet;
23 import java.sql.SQLException;
24 import java.sql.Timestamp;
26 import testsuite.clusterj.model.DatetimeAsSqlTimestampTypes;
27 import testsuite.clusterj.model.IdBase;
29 /** Test that Datetimes 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 datetimetypes;
35 create table datetimetypes (
36 id int not null primary key,
38 datetime_null_hash datetime,
39 datetime_null_btree datetime,
40 datetime_null_both datetime,
41 datetime_null_none datetime,
43 datetime_not_null_hash datetime,
44 datetime_not_null_btree datetime,
45 datetime_not_null_both datetime,
46 datetime_not_null_none datetime
48 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
50 create unique index idx_datetime_null_hash using hash on datetimetypes(datetime_null_hash);
51 create index idx_datetime_null_btree on datetimetypes(datetime_null_btree);
52 create unique index idx_datetime_null_both on datetimetypes(datetime_null_both);
54 create unique index idx_datetime_not_null_hash using hash on datetimetypes(datetime_not_null_hash);
55 create index idx_datetime_not_null_btree on datetimetypes(datetime_not_null_btree);
56 create unique index idx_datetime_not_null_both on datetimetypes(datetime_not_null_both);
58 public class DatetimeAsSqlTimestampTypesTest extends AbstractClusterJModelTest {
60 static int NUMBER_OF_INSTANCES = 10;
63 protected boolean getDebug() {
68 protected int getNumberOfInstances() {
69 return NUMBER_OF_INSTANCES;
73 protected String getTableName() {
74 return "datetimetypes";
77 /** Subclasses override this method to provide the model class for the test */
79 Class<? extends IdBase> getModelClass() {
80 return DatetimeAsSqlTimestampTypes.class;
83 /** Subclasses override this method to provide values for rows (i) and columns (j) */
85 protected Object getColumnValue(int i, int j) {
86 return new Timestamp(getMillisFor(1980, 0, i + 1, 0, 0, j));
89 public void testWriteJDBCReadNDB() {
94 public void testWriteNDBReadNDB() {
99 public void testWriteJDBCReadJDBC() {
104 public void testWriteNDBReadJDBC() {
109 static ColumnDescriptor not_null_hash = new ColumnDescriptor
110 ("datetime_not_null_hash", new InstanceHandler() {
111 public void setFieldValue(IdBase instance, Object value) {
112 ((DatetimeAsSqlTimestampTypes)instance).setDatetime_not_null_hash((Timestamp)value);
114 public Object getFieldValue(IdBase instance) {
115 return ((DatetimeAsSqlTimestampTypes)instance).getDatetime_not_null_hash();
117 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
118 throws SQLException {
119 preparedStatement.setTimestamp(j, (Timestamp)value);
121 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
122 return rs.getTimestamp(j);
126 static ColumnDescriptor not_null_btree = new ColumnDescriptor
127 ("datetime_not_null_btree", new InstanceHandler() {
128 public void setFieldValue(IdBase instance, Object value) {
129 ((DatetimeAsSqlTimestampTypes)instance).setDatetime_not_null_btree((Timestamp)value);
131 public Object getFieldValue(IdBase instance) {
132 return ((DatetimeAsSqlTimestampTypes)instance).getDatetime_not_null_btree();
134 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
135 throws SQLException {
136 preparedStatement.setTimestamp(j, (Timestamp)value);
138 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
139 return rs.getTimestamp(j);
143 static ColumnDescriptor not_null_both = new ColumnDescriptor
144 ("datetime_not_null_both", new InstanceHandler() {
145 public void setFieldValue(IdBase instance, Object value) {
146 ((DatetimeAsSqlTimestampTypes)instance).setDatetime_not_null_both((Timestamp)value);
148 public Timestamp getFieldValue(IdBase instance) {
149 return ((DatetimeAsSqlTimestampTypes)instance).getDatetime_not_null_both();
151 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
152 throws SQLException {
153 preparedStatement.setTimestamp(j, (Timestamp)value);
155 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
156 return rs.getTimestamp(j);
160 static ColumnDescriptor not_null_none = new ColumnDescriptor
161 ("datetime_not_null_none", new InstanceHandler() {
162 public void setFieldValue(IdBase instance, Object value) {
163 ((DatetimeAsSqlTimestampTypes)instance).setDatetime_not_null_none((Timestamp)value);
165 public Timestamp getFieldValue(IdBase instance) {
166 return ((DatetimeAsSqlTimestampTypes)instance).getDatetime_not_null_none();
168 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
169 throws SQLException {
170 preparedStatement.setTimestamp(j, (Timestamp)value);
172 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
173 return rs.getTimestamp(j);
177 protected static ColumnDescriptor[] columnDescriptors = new ColumnDescriptor[] {
185 protected ColumnDescriptor[] getColumnDescriptors() {
186 return columnDescriptors;