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;
25 import java.util.Date;
27 import testsuite.clusterj.model.IdBase;
28 import testsuite.clusterj.model.TimeAsUtilDateTypes;
30 /** Test that Times 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 timetypes;
36 create table timetypes (
37 id int not null primary key,
44 time_not_null_hash time,
45 time_not_null_btree time,
46 time_not_null_both time,
47 time_not_null_none time
49 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
51 create unique index idx_time_null_hash using hash on timetypes(time_null_hash);
52 create index idx_time_null_btree on timetypes(time_null_btree);
53 create unique index idx_time_null_both on timetypes(time_null_both);
55 create unique index idx_time_not_null_hash using hash on timetypes(time_not_null_hash);
56 create index idx_time_not_null_btree on timetypes(time_not_null_btree);
57 create unique index idx_time_not_null_both on timetypes(time_not_null_both);
59 public class TimeAsUtilDateTypesTest extends AbstractClusterJModelTest {
61 static int NUMBER_OF_INSTANCES = 10;
64 protected boolean getDebug() {
69 protected int getNumberOfInstances() {
70 return NUMBER_OF_INSTANCES;
74 protected String getTableName() {
78 /** Subclasses override this method to provide the model class for the test */
80 Class<? extends IdBase> getModelClass() {
81 return TimeAsUtilDateTypes.class;
84 /** Subclasses override this method to provide values for rows (i) and columns (j) */
86 protected Object getColumnValue(int i, int j) {
87 return new Date(getMillisFor(0, i, i, j));
90 public void testWriteJDBCReadNDB() {
95 public void testWriteNDBReadNDB() {
100 public void testWriteJDBCReadJDBC() {
105 public void testWriteNDBReadJDBC() {
110 static ColumnDescriptor not_null_hash = new ColumnDescriptor
111 ("time_not_null_hash", new InstanceHandler() {
112 public void setFieldValue(IdBase instance, Object value) {
113 ((TimeAsUtilDateTypes)instance).setTime_not_null_hash((Date)value);
115 public Object getFieldValue(IdBase instance) {
116 return ((TimeAsUtilDateTypes)instance).getTime_not_null_hash();
118 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
119 throws SQLException {
120 preparedStatement.setTime(j, new Time(((Date)value).getTime()));
122 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
123 return rs.getTime(j);
127 static ColumnDescriptor not_null_btree = new ColumnDescriptor
128 ("time_not_null_btree", new InstanceHandler() {
129 public void setFieldValue(IdBase instance, Object value) {
130 ((TimeAsUtilDateTypes)instance).setTime_not_null_btree((Date)value);
132 public Object getFieldValue(IdBase instance) {
133 return ((TimeAsUtilDateTypes)instance).getTime_not_null_btree();
135 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
136 throws SQLException {
137 preparedStatement.setTime(j, new Time(((Date)value).getTime()));
139 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
140 return rs.getTime(j);
144 static ColumnDescriptor not_null_both = new ColumnDescriptor
145 ("time_not_null_both", new InstanceHandler() {
146 public void setFieldValue(IdBase instance, Object value) {
147 ((TimeAsUtilDateTypes)instance).setTime_not_null_both((Date)value);
149 public Date getFieldValue(IdBase instance) {
150 return ((TimeAsUtilDateTypes)instance).getTime_not_null_both();
152 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
153 throws SQLException {
154 preparedStatement.setTime(j, new Time(((Date)value).getTime()));
156 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
157 return rs.getTime(j);
161 static ColumnDescriptor not_null_none = new ColumnDescriptor
162 ("time_not_null_none", new InstanceHandler() {
163 public void setFieldValue(IdBase instance, Object value) {
164 ((TimeAsUtilDateTypes)instance).setTime_not_null_none((Date)value);
166 public Date getFieldValue(IdBase instance) {
167 return ((TimeAsUtilDateTypes)instance).getTime_not_null_none();
169 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
170 throws SQLException {
171 preparedStatement.setTime(j, new Time(((Date)value).getTime()));
173 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
174 return rs.getTime(j);
178 protected static ColumnDescriptor[] columnDescriptors = new ColumnDescriptor[] {
186 protected ColumnDescriptor[] getColumnDescriptors() {
187 return columnDescriptors;