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;
26 import com.mysql.clusterj.jpatest.model.TimeAsSqlTimeTypes;
27 import com.mysql.clusterj.jpatest.model.IdBase;
29 /** Test that Times can be read and written.
30 * case 1: Write using JDBC, read using JPA.
31 * case 2: Write using JPA, read using JDBC.
32 * case 3: Write using JDBC, read using JDBC.
33 * case 4: Write using JPA, read using JPA.
36 drop table if exists timetypes;
37 create table timetypes (
38 id int not null primary key,
40 time_not_null_hash time,
41 time_not_null_btree time,
42 time_not_null_both time,
43 time_not_null_none time
45 ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
47 create unique index idx_time_not_null_hash using hash on timetypes(time_not_null_hash);
48 create index idx_time_not_null_btree on timetypes(time_not_null_btree);
49 create unique index idx_time_not_null_both on timetypes(time_not_null_both);
52 public class TimeAsSqlTimeTest extends AbstractJPABaseTest {
54 static int NUMBER_OF_INSTANCES = 10;
57 protected boolean getDebug() {
62 protected int getNumberOfInstances() {
63 return NUMBER_OF_INSTANCES;
67 protected String getTableName() {
71 /** Subclasses override this method to provide the model class for the test */
73 protected Class<? extends IdBase> getModelClass() {
74 return TimeAsSqlTimeTypes.class;
77 /** Subclasses override this method to provide values for rows (i) and columns (j) */
79 protected Object getColumnValue(int i, int j) {
80 return new Time(getMillisFor(0, i, i, j));
84 /** Subclasses must override this method to implement the model factory for the test */
85 protected IdBase getNewInstance(Class<? extends IdBase> modelClass) {
86 return new TimeAsSqlTimeTypes();
89 public void testWriteJDBCReadJPA() {
94 public void testWriteJPAReadJDBC() {
99 public void testWriteJDBCReadJDBC() {
104 public void testWriteJPAReadJPA() {
109 static ColumnDescriptor not_null_hash = new ColumnDescriptor
110 ("time_not_null_hash", new InstanceHandler() {
111 public void setFieldValue(IdBase instance, Object value) {
112 ((TimeAsSqlTimeTypes)instance).setTime_not_null_hash((Time)value);
114 public Object getFieldValue(IdBase instance) {
115 return ((TimeAsSqlTimeTypes)instance).getTime_not_null_hash();
117 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
118 throws SQLException {
119 preparedStatement.setTime(j, (Time)value);
121 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
122 return rs.getTime(j);
126 static ColumnDescriptor not_null_btree = new ColumnDescriptor
127 ("time_not_null_btree", new InstanceHandler() {
128 public void setFieldValue(IdBase instance, Object value) {
129 ((TimeAsSqlTimeTypes)instance).setTime_not_null_btree((Time)value);
131 public Object getFieldValue(IdBase instance) {
132 return ((TimeAsSqlTimeTypes)instance).getTime_not_null_btree();
134 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
135 throws SQLException {
136 preparedStatement.setTime(j, (Time)value);
138 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
139 return rs.getTime(j);
142 static ColumnDescriptor not_null_both = new ColumnDescriptor
143 ("time_not_null_both", new InstanceHandler() {
144 public void setFieldValue(IdBase instance, Object value) {
145 ((TimeAsSqlTimeTypes)instance).setTime_not_null_both((Time)value);
147 public Time getFieldValue(IdBase instance) {
148 return ((TimeAsSqlTimeTypes)instance).getTime_not_null_both();
150 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
151 throws SQLException {
152 preparedStatement.setTime(j, (Time)value);
154 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
155 return rs.getTime(j);
158 static ColumnDescriptor not_null_none = new ColumnDescriptor
159 ("time_not_null_none", new InstanceHandler() {
160 public void setFieldValue(IdBase instance, Object value) {
161 ((TimeAsSqlTimeTypes)instance).setTime_not_null_none((Time)value);
163 public Time getFieldValue(IdBase instance) {
164 return ((TimeAsSqlTimeTypes)instance).getTime_not_null_none();
166 public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
167 throws SQLException {
168 preparedStatement.setTime(j, (Time)value);
170 public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
171 return rs.getTime(j);
175 protected static ColumnDescriptor[] columnDescriptors = new ColumnDescriptor[] {
183 protected ColumnDescriptor[] getColumnDescriptors() {
184 return columnDescriptors;