MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BinaryTypesTest.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 testsuite.clusterj;
20 
21 import java.sql.PreparedStatement;
22 import java.sql.ResultSet;
23 import java.sql.SQLException;
24 import java.util.List;
25 
26 import testsuite.clusterj.model.IdBase;
27 import testsuite.clusterj.model.BinaryTypes;
28 
51 
52  static int NUMBER_OF_INSTANCES = 10;
53 
54  @Override
55  protected boolean getDebug() {
56  return false;
57  }
58 
59  @Override
60  protected int getNumberOfInstances() {
61  return NUMBER_OF_INSTANCES;
62  }
63 
64  @Override
65  protected String getTableName() {
66  return "binarytypes";
67  }
68 
70  @Override
71  Class<? extends IdBase> getModelClass() {
72  return BinaryTypes.class;
73  }
74 
76  @Override
77  protected Object getColumnValue(int i, int j) {
78  // first calculate the length of the data
79  int length = (int)Math.pow(2, j);
80  byte[] data = new byte[length];
81  // fill in the data, increasing by one for each row, column, and byte in the byte[]
82  for (int d = 0; d < length; ++d) {
83  data[d] = (byte)(i + j + d);
84  }
85  return data;
86  }
87 
94  @Override
95  protected void verify(String where, List<Object[]> expecteds, List<Object[]> actuals) {
96  for (int i = 0; i < expecteds.size(); ++i) {
97  Object[] expected = expecteds.get(i);
98  Object[] actual = actuals.get(i);
99  errorIfNotEqual(where + " got failure on id for row " + i, i, actual[0]);
100  for (int j = 1; j < expected.length; ++j) {
101  // verify each object in the array
102  byte[] expectedColumn = (byte[])(expected)[j];
103  byte[] actualColumn = (byte[])(actual)[j];
104  errorIfNotEqual(where + " got failure on length of data for row " + i,
105  expectedColumn.length, actualColumn.length);
106  if (expectedColumn.length == actualColumn.length) {
107  // now compare byte by byte
108  for (j = 0; j < expectedColumn.length; ++j)
109  errorIfNotEqual(where + " got failure on comparison of data for row "
110  + i + " column " + j,
111  expectedColumn[j], actualColumn[j]);
112  }
113  }
114  }
115  }
116 
117  public void testWriteJDBCReadNDB() {
119  failOnError();
120  }
121 
122  public void testWriteNDBReadJDBC() {
124  failOnError();
125  }
126 
127  static ColumnDescriptor binary1 = new ColumnDescriptor
128  ("binary1", new InstanceHandler() {
129  public void setFieldValue(IdBase instance, Object value) {
130  ((BinaryTypes)instance).setBinary1((byte[])value);
131  }
132  public Object getFieldValue(IdBase instance) {
133  return ((BinaryTypes)instance).getBinary1();
134  }
135  public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
136  throws SQLException {
137  preparedStatement.setBytes(j, (byte[])value);
138  }
139  public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
140  return rs.getBytes(j);
141  }
142  });
143 
144  static ColumnDescriptor binary2 = new ColumnDescriptor
145  ("binary2", new InstanceHandler() {
146  public void setFieldValue(IdBase instance, Object value) {
147  ((BinaryTypes)instance).setBinary2((byte[])value);
148  }
149  public Object getFieldValue(IdBase instance) {
150  return ((BinaryTypes)instance).getBinary2();
151  }
152  public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
153  throws SQLException {
154  preparedStatement.setBytes(j, (byte[])value);
155  }
156  public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
157  return rs.getBytes(j);
158  }
159  });
160 
161  static ColumnDescriptor binary4 = new ColumnDescriptor
162  ("binary4", new InstanceHandler() {
163  public void setFieldValue(IdBase instance, Object value) {
164  ((BinaryTypes)instance).setBinary4((byte[])value);
165  }
166  public Object getFieldValue(IdBase instance) {
167  return ((BinaryTypes)instance).getBinary4();
168  }
169  public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
170  throws SQLException {
171  preparedStatement.setBytes(j, (byte[])value);
172  }
173  public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
174  return rs.getBytes(j);
175  }
176  });
177 
178  static ColumnDescriptor binary8 = new ColumnDescriptor
179  ("binary8", new InstanceHandler() {
180  public void setFieldValue(IdBase instance, Object value) {
181  ((BinaryTypes)instance).setBinary8((byte[])value);
182  }
183  public Object getFieldValue(IdBase instance) {
184  return ((BinaryTypes)instance).getBinary8();
185  }
186  public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
187  throws SQLException {
188  preparedStatement.setBytes(j, (byte[])value);
189  }
190  public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
191  return rs.getBytes(j);
192  }
193  });
194 
195  static ColumnDescriptor binary16 = new ColumnDescriptor
196  ("binary16", new InstanceHandler() {
197  public void setFieldValue(IdBase instance, Object value) {
198  ((BinaryTypes)instance).setBinary16((byte[])value);
199  }
200  public Object getFieldValue(IdBase instance) {
201  return ((BinaryTypes)instance).getBinary16();
202  }
203  public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
204  throws SQLException {
205  preparedStatement.setBytes(j, (byte[])value);
206  }
207  public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
208  return rs.getBytes(j);
209  }
210  });
211 
212  static ColumnDescriptor binary32 = new ColumnDescriptor
213  ("binary32", new InstanceHandler() {
214  public void setFieldValue(IdBase instance, Object value) {
215  ((BinaryTypes)instance).setBinary32((byte[])value);
216  }
217  public Object getFieldValue(IdBase instance) {
218  return ((BinaryTypes)instance).getBinary32();
219  }
220  public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
221  throws SQLException {
222  preparedStatement.setBytes(j, (byte[])value);
223  }
224  public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
225  return rs.getBytes(j);
226  }
227  });
228 
229  static ColumnDescriptor binary64 = new ColumnDescriptor
230  ("binary64", new InstanceHandler() {
231  public void setFieldValue(IdBase instance, Object value) {
232  ((BinaryTypes)instance).setBinary64((byte[])value);
233  }
234  public Object getFieldValue(IdBase instance) {
235  return ((BinaryTypes)instance).getBinary64();
236  }
237  public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
238  throws SQLException {
239  preparedStatement.setBytes(j, (byte[])value);
240  }
241  public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
242  return rs.getBytes(j);
243  }
244  });
245 
246  static ColumnDescriptor binary128 = new ColumnDescriptor
247  ("binary128", new InstanceHandler() {
248  public void setFieldValue(IdBase instance, Object value) {
249  ((BinaryTypes)instance).setBinary128((byte[])value);
250  }
251  public Object getFieldValue(IdBase instance) {
252  return ((BinaryTypes)instance).getBinary128();
253  }
254  public void setPreparedStatementValue(PreparedStatement preparedStatement, int j, Object value)
255  throws SQLException {
256  preparedStatement.setBytes(j, (byte[])value);
257  }
258  public Object getResultSetValue(ResultSet rs, int j) throws SQLException {
259  return rs.getBytes(j);
260  }
261  });
262 
263  protected static ColumnDescriptor[] columnDescriptors = new ColumnDescriptor[] {
264  binary1,
265  binary2,
266  binary4,
267  binary8,
268  binary16,
269  binary32,
270  binary64,
271  binary128
272  };
273 
274  @Override
275  protected ColumnDescriptor[] getColumnDescriptors() {
276  return columnDescriptors;
277  }
278 
279 }