MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TimestampAsSqlTimestampTest.java
1 /*
2  Copyright 2010 Sun Microsystems, Inc.
3  All rights reserved. Use is subject to license terms.
4 
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.
8 
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.
13 
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
17 */
18 
19 package com.mysql.clusterj.jpatest;
20 
21 import java.sql.PreparedStatement;
22 import java.sql.ResultSet;
23 import java.sql.SQLException;
24 import java.sql.Timestamp;
25 
26 import com.mysql.clusterj.jpatest.model.TimestampAsSqlTimestampTypes;
27 import com.mysql.clusterj.jpatest.model.IdBase;
28 
51 
52  @Override
53  public void setUp() {
54  super.setUp();
55  getConnection();
57  connection = null;
58  getConnection();
59  setAutoCommit(connection, false);
60  }
61 
62  static int NUMBER_OF_INSTANCES = 10;
63 
64  @Override
65  protected boolean getDebug() {
66  return false;
67  }
68 
69  @Override
70  protected int getNumberOfInstances() {
71  return NUMBER_OF_INSTANCES;
72  }
73 
74  @Override
75  protected String getTableName() {
76  return "timestamptypes";
77  }
78 
80  @Override
81  protected Class<? extends IdBase> getModelClass() {
82  return TimestampAsSqlTimestampTypes.class;
83  }
84 
86  @Override
87  protected Object getColumnValue(int i, int j) {
88  return new Timestamp(getMillisFor(1980, 0, i + 1, 0, 0, j));
89  }
90 
91  @Override
93  protected IdBase getNewInstance(Class<? extends IdBase> modelClass) {
94  return new TimestampAsSqlTimestampTypes();
95  }
96 
97  public void testWriteJDBCReadJPA() {
99  failOnError();
100  }
101 
102  public void testWriteJPAReadJDBC() {
104  failOnError();
105  }
106 
107  public void testWriteJDBCReadJDBC() {
109  failOnError();
110  }
111 
112  public void testWriteJPAReadJPA() {
113  writeJPAreadJPA();
114  failOnError();
115  }
116 
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);
121  }
122  public Object getFieldValue(IdBase instance) {
123  return ((TimestampAsSqlTimestampTypes)instance).getTimestamp_not_null_hash();
124  }
125  public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
126  throws SQLException {
127  preparedStatement.setTimestamp(j, (Timestamp)value);
128  }
129  public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
130  return rs.getTimestamp(j);
131  }
132  });
133 
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);
138  }
139  public Object getFieldValue(IdBase instance) {
140  return ((TimestampAsSqlTimestampTypes)instance).getTimestamp_not_null_btree();
141  }
142  public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
143  throws SQLException {
144  preparedStatement.setTimestamp(j, (Timestamp)value);
145  }
146  public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
147  return rs.getTimestamp(j);
148  }
149  });
150 
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);
155  }
156  public Timestamp getFieldValue(IdBase instance) {
157  return ((TimestampAsSqlTimestampTypes)instance).getTimestamp_not_null_both();
158  }
159  public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
160  throws SQLException {
161  preparedStatement.setTimestamp(j, (Timestamp)value);
162  }
163  public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
164  return rs.getTimestamp(j);
165  }
166  });
167 
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);
172  }
173  public Timestamp getFieldValue(IdBase instance) {
174  return ((TimestampAsSqlTimestampTypes)instance).getTimestamp_not_null_none();
175  }
176  public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
177  throws SQLException {
178  preparedStatement.setTimestamp(j, (Timestamp)value);
179  }
180  public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
181  return rs.getTimestamp(j);
182  }
183  });
184 
185  protected static ColumnDescriptor[] columnDescriptors = new ColumnDescriptor[] {
186  not_null_hash,
187  not_null_btree,
188  not_null_both,
189  not_null_none
190  };
191 
192  @Override
193  protected ColumnDescriptor[] getColumnDescriptors() {
194  return columnDescriptors;
195  }
196 
197 }