KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > tests > jdbc4 > UnsupportedVetter


1  /**
2  * Derby - org.apache.derbyTesting.functionTests.tests.jdbc4.UnsupportedVetter
3  *
4    Licensed to the Apache Software Foundation (ASF) under one or more
5    contributor license agreements. See the NOTICE file distributed with
6    this work for additional information regarding copyright ownership.
7    The ASF licenses this file to You under the Apache License, Version 2.0
8    (the "License"); you may not use this file except in compliance with
9    the License. You may obtain a copy of the License at
10
11       http://www.apache.org/licenses/LICENSE-2.0
12
13    Unless required by applicable law or agreed to in writing, software
14    distributed under the License is distributed on an "AS IS" BASIS,
15    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16    See the License for the specific language governing permissions and
17    limitations under the License.
18  *
19  */

20
21 package org.apache.derbyTesting.functionTests.tests.jdbc4;
22
23 import java.io.*;
24 import java.sql.*;
25 import javax.sql.*;
26
27 import java.lang.reflect.*;
28 import java.util.*;
29 import junit.framework.*;
30
31 import java.net.URL JavaDoc;
32
33 import org.apache.derbyTesting.functionTests.util.TestUtil;
34 import org.apache.derbyTesting.functionTests.util.TestDataSourceFactory;
35 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
36
37 /**
38  * JUnit test which checks that only expected methods throw
39  * SQLFeatureNotSupporteException. As currently compiled, this class
40  * does not object to a handful of mandatory LOB-supporting methods which Derby
41  * does not implement. You can expose these methods by setting
42  * the STRICT_ENFORCEMENT constant to true.
43  *
44  */

45 public class UnsupportedVetter extends BaseJDBCTestCase
46 {
47     /////////////////////////////////////////////////////////////
48
//
49
// CONSTANTS
50
//
51
/////////////////////////////////////////////////////////////
52

53     public static final String JavaDoc SQL_PACKAGE_NAME = "java.sql";
54
55     private static final boolean STRICT_ENFORCEMENT = false;
56     
57     /////////////////////////////////////////////////////////////
58
//
59
// STATE
60
//
61
/////////////////////////////////////////////////////////////
62

63     //
64
// Table of methods which are allowed to raise
65
// SQLFeatureNotSupportedException. Derived from the 1.6 Javadoc.
66
//
67
private static Exclusions[] rawExcludables = new Exclusions[]
68         {
69             new Exclusions
70             (
71                 java.sql.Connection JavaDoc.class,
72                 new MD[]
73                 {
74                         new MD( "createArrayOf", new Class JavaDoc[] { String JavaDoc.class, Object JavaDoc[].class } ),
75                         new MD( "createNClob", new Class JavaDoc[] { } ),
76                         new MD( "createSQLXML", new Class JavaDoc[] { } ),
77                         new MD( "createStruct", new Class JavaDoc[] { String JavaDoc.class, Object JavaDoc[].class } ),
78                         new MD( "getTypeMap", new Class JavaDoc[] { } ),
79                         new MD( "prepareStatement", new Class JavaDoc[] { String JavaDoc.class, int[].class } ),
80                         new MD( "prepareStatement", new Class JavaDoc[] { String JavaDoc.class, String JavaDoc[].class } ),
81                         new MD( "setTypeMap", new Class JavaDoc[] { Map.class } ),
82                         } ),
83             new Exclusions
84             (
85                 java.sql.Statement JavaDoc.class,
86                 new MD[]
87                 {
88                         new MD( "cancel", new Class JavaDoc[] { } ),
89                     new MD( "execute", new Class JavaDoc[] { String JavaDoc.class, int[].class } ),
90                         new MD( "execute", new Class JavaDoc[] { String JavaDoc.class, String JavaDoc[].class } ),
91                         new MD( "executeUpdate", new Class JavaDoc[] { String JavaDoc.class, int[].class } ),
92                         new MD( "executeUpdate", new Class JavaDoc[] { String JavaDoc.class, String JavaDoc[].class } )
93                         } )
94             ,
95
96             new Exclusions
97             (
98                 java.sql.PreparedStatement JavaDoc.class,
99                 new MD[]
100                 {
101                     new MD( "setArray", new Class JavaDoc[] { int.class, java.sql.Array JavaDoc.class } ),
102                         new MD( "setNCharacterStream", new Class JavaDoc[] { int.class, java.io.Reader JavaDoc.class } ),
103                         new MD( "setNCharacterStream", new Class JavaDoc[] { int.class, java.io.Reader JavaDoc.class, long.class } ),
104                         new MD( "setNClob", new Class JavaDoc[] { int.class, NClob.class } ),
105                         new MD( "setNClob", new Class JavaDoc[] { int.class, java.io.Reader JavaDoc.class } ),
106                         new MD( "setNClob", new Class JavaDoc[] { int.class, java.io.Reader JavaDoc.class, long.class } ),
107                         new MD( "setNString", new Class JavaDoc[] { int.class, String JavaDoc.class } ),
108                         new MD( "setRef", new Class JavaDoc[] { int.class, Ref.class } ),
109                         new MD( "setRowId", new Class JavaDoc[] { int.class, RowId.class } ),
110                         new MD( "setSQLXML", new Class JavaDoc[] { int.class, SQLXML.class } ),
111                         new MD( "setURL", new Class JavaDoc[] { int.class, URL JavaDoc.class } ),
112                         new MD( "setNull", new Class JavaDoc[] { int.class, int.class, String JavaDoc.class } ),
113                         new MD( "setUnicodeStream", new Class JavaDoc[] { int.class, InputStream.class, int.class } ),
114                         } ),
115             new Exclusions
116             (
117                 java.sql.CallableStatement JavaDoc.class,
118                 new MD[]
119                 {
120                     //
121
// THE FOLLOWING METHODS ARE MANDATORY ACCORDING TO THE
122
// JDBC SPEC. HOWEVER, DERBY DOES NOT IMPLEMENT THEM IN ONE
123
// OR THE OTHER OF OUR CLIENTS.
124
//
125
new FD( "getBlob", new Class JavaDoc[] { int.class } ),
126                     new FD( "getClob", new Class JavaDoc[] { int.class } ),
127                     
128
129                     //
130
// According to the JDBC4 spec and javadoc, the following
131
// methods are optional and do not have to be implemented.
132
//
133

134                     new MD( "getArray", new Class JavaDoc[] { int.class } ),
135                     new MD( "getArray", new Class JavaDoc[] { String JavaDoc.class } ),
136                     new MD( "getBigDecimal", new Class JavaDoc[] { String JavaDoc.class } ),
137                     new MD( "getBoolean", new Class JavaDoc[] { String JavaDoc.class } ),
138                     new MD( "getBlob", new Class JavaDoc[] { String JavaDoc.class } ),
139                     new MD( "getBoolean", new Class JavaDoc[] { String JavaDoc.class } ),
140                     new MD( "getByte", new Class JavaDoc[] { String JavaDoc.class } ),
141                     new MD( "getBytes", new Class JavaDoc[] { String JavaDoc.class } ),
142                     new MD( "getCharacterStream", new Class JavaDoc[] { String JavaDoc.class } ),
143                     new MD( "getClob", new Class JavaDoc[] { String JavaDoc.class } ),
144                     new MD( "getDate", new Class JavaDoc[] { String JavaDoc.class } ),
145                     new MD( "getDate", new Class JavaDoc[] { String JavaDoc.class, Calendar.class } ),
146                     new MD( "getDouble", new Class JavaDoc[] { String JavaDoc.class } ),
147                     new MD( "getFloat", new Class JavaDoc[] { String JavaDoc.class } ),
148                     new MD( "getInt", new Class JavaDoc[] { String JavaDoc.class } ),
149                     new MD( "getLong", new Class JavaDoc[] { String JavaDoc.class } ),
150                     new MD( "getNCharacterStream", new Class JavaDoc[] { int.class } ),
151                     new MD( "getNCharacterStream", new Class JavaDoc[] { String JavaDoc.class } ),
152                     new MD( "getNClob", new Class JavaDoc[] { int.class } ),
153                     new MD( "getNClob", new Class JavaDoc[] { String JavaDoc.class } ),
154                     new MD( "getNString", new Class JavaDoc[] { int.class } ),
155                     new MD( "getNString", new Class JavaDoc[] { String JavaDoc.class } ),
156                     new MD( "getObject", new Class JavaDoc[] { String JavaDoc.class } ),
157                     new MD( "getRef", new Class JavaDoc[] { int.class } ),
158                     new MD( "getRef", new Class JavaDoc[] { String JavaDoc.class } ),
159                     new MD( "getRowId", new Class JavaDoc[] { int.class } ),
160                     new MD( "getRowId", new Class JavaDoc[] { String JavaDoc.class } ),
161                     new MD( "getShort", new Class JavaDoc[] { String JavaDoc.class } ),
162                     new MD( "getSQLXML", new Class JavaDoc[] { int.class } ),
163                     new MD( "getSQLXML", new Class JavaDoc[] { String JavaDoc.class } ),
164                     new MD( "getString", new Class JavaDoc[] { String JavaDoc.class } ),
165                     new MD( "getTime", new Class JavaDoc[] { String JavaDoc.class } ),
166                     new MD( "getTime", new Class JavaDoc[] { String JavaDoc.class, java.util.Calendar JavaDoc.class } ),
167                     new MD( "getTimestamp", new Class JavaDoc[] { String JavaDoc.class } ),
168                     new MD( "getTimestamp", new Class JavaDoc[] { String JavaDoc.class, java.util.Calendar JavaDoc.class } ),
169                     new MD( "getURL", new Class JavaDoc[] { int.class } ),
170                     new MD( "getURL", new Class JavaDoc[] { String JavaDoc.class } ),
171                         new MD( "registerOutParameter", new Class JavaDoc[] { String JavaDoc.class, int.class } ),
172                         new MD( "registerOutParameter", new Class JavaDoc[] { String JavaDoc.class, int.class, int.class } ),
173                         new MD( "registerOutParameter", new Class JavaDoc[] { String JavaDoc.class, int.class, String JavaDoc.class } ),
174                         new MD( "registerOutParameter", new Class JavaDoc[] { int.class, int.class, String JavaDoc.class } ),
175                         new MD( "setArray", new Class JavaDoc[] { int.class, java.sql.Array JavaDoc.class } ),
176                         new MD( "setAsciiStream", new Class JavaDoc[] { String JavaDoc.class, java.io.InputStream JavaDoc.class } ),
177                         new MD( "setAsciiStream", new Class JavaDoc[] { String JavaDoc.class, java.io.InputStream JavaDoc.class, int.class } ),
178                                                 new MD( "setAsciiStream", new Class JavaDoc[] { String JavaDoc.class, java.io.InputStream JavaDoc.class, long.class } ),
179                         new MD( "setBigDecimal", new Class JavaDoc[] { String JavaDoc.class, java.math.BigDecimal JavaDoc.class } ),
180                         new MD( "setBinaryStream", new Class JavaDoc[] { String JavaDoc.class, java.io.InputStream JavaDoc.class } ),
181                         new MD( "setBinaryStream", new Class JavaDoc[] { String JavaDoc.class, java.io.InputStream JavaDoc.class, int.class } ),
182                                                 new MD( "setBinaryStream", new Class JavaDoc[] { String JavaDoc.class, java.io.InputStream JavaDoc.class, long.class } ),
183                         new MD( "setBlob", new Class JavaDoc[] { String JavaDoc.class, java.io.InputStream JavaDoc.class } ),
184                         new MD( "setBlob", new Class JavaDoc[] { String JavaDoc.class, java.io.InputStream JavaDoc.class, long.class } ),
185                         new MD( "setBlob", new Class JavaDoc[] { String JavaDoc.class, Blob.class } ),
186                         new MD( "setBoolean", new Class JavaDoc[] { String JavaDoc.class, boolean.class } ),
187                         new MD( "setByte", new Class JavaDoc[] { String JavaDoc.class, byte.class } ),
188                         new MD( "setBytes", new Class JavaDoc[] { String JavaDoc.class, byte[].class } ),
189                         new MD( "setCharacterStream", new Class JavaDoc[] { String JavaDoc.class, java.io.Reader JavaDoc.class } ),
190                         new MD( "setCharacterStream", new Class JavaDoc[] { String JavaDoc.class, java.io.Reader JavaDoc.class, int.class } ),
191                                                 new MD( "setCharacterStream", new Class JavaDoc[] { String JavaDoc.class, java.io.Reader JavaDoc.class, long.class } ),
192                         new MD( "setClob", new Class JavaDoc[] { String JavaDoc.class, java.io.Reader JavaDoc.class } ),
193                         new MD( "setClob", new Class JavaDoc[] { String JavaDoc.class, java.io.Reader JavaDoc.class, long.class } ),
194                         new MD( "setClob", new Class JavaDoc[] { String JavaDoc.class, Clob.class } ),
195                         new MD( "setDate", new Class JavaDoc[] { String JavaDoc.class, java.sql.Date JavaDoc.class } ),
196                         new MD( "setDate", new Class JavaDoc[] { String JavaDoc.class, java.sql.Date JavaDoc.class, Calendar.class } ),
197                         new MD( "setDouble", new Class JavaDoc[] { String JavaDoc.class, double.class} ),
198                         new MD( "setFloat", new Class JavaDoc[] { String JavaDoc.class, float.class } ),
199                         new MD( "setInt", new Class JavaDoc[] { String JavaDoc.class, int.class } ),
200                         new MD( "setLong", new Class JavaDoc[] { String JavaDoc.class, long.class } ),
201                         new MD( "setNCharacterStream", new Class JavaDoc[] { int.class, java.io.Reader JavaDoc.class, long.class } ),
202                         new MD( "setNCharacterStream", new Class JavaDoc[] { String JavaDoc.class, java.io.Reader JavaDoc.class } ),
203                         new MD( "setNCharacterStream", new Class JavaDoc[] { String JavaDoc.class, java.io.Reader JavaDoc.class, long.class } ),
204                         new MD( "setNClob", new Class JavaDoc[] { int.class, java.io.Reader JavaDoc.class, long.class } ),
205                         new MD( "setNClob", new Class JavaDoc[] { int.class, NClob.class } ),
206                         new MD( "setNClob", new Class JavaDoc[] { String JavaDoc.class, java.io.Reader JavaDoc.class } ),
207                         new MD( "setNClob", new Class JavaDoc[] { String JavaDoc.class, java.io.Reader JavaDoc.class, long.class } ),
208                         new MD( "setNClob", new Class JavaDoc[] { String JavaDoc.class, NClob.class } ),
209                         new MD( "setNString", new Class JavaDoc[] { int.class, String JavaDoc.class } ),
210                         new MD( "setNString", new Class JavaDoc[] { String JavaDoc.class, String JavaDoc.class } ),
211                         new MD( "setNull", new Class JavaDoc[] { String JavaDoc.class, int.class } ),
212                         new MD( "setNull", new Class JavaDoc[] { String JavaDoc.class, int.class, String JavaDoc.class } ),
213                         new MD( "setObject", new Class JavaDoc[] { String JavaDoc.class, Object JavaDoc.class } ),
214                         new MD( "setObject", new Class JavaDoc[] { String JavaDoc.class, Object JavaDoc.class, int.class } ),
215                         new MD( "setObject", new Class JavaDoc[] { String JavaDoc.class, Object JavaDoc.class, int.class, int.class } ),
216                         new MD( "setRef", new Class JavaDoc[] { int.class, Ref.class } ),
217                         new MD( "setRowId", new Class JavaDoc[] { int.class, RowId.class } ),
218                         new MD( "setRowId", new Class JavaDoc[] { String JavaDoc.class, RowId.class } ),
219                         new MD( "setSQLXML", new Class JavaDoc[] { int.class, SQLXML.class } ),
220                         new MD( "setSQLXML", new Class JavaDoc[] { String JavaDoc.class, SQLXML.class } ),
221                         new MD( "setShort", new Class JavaDoc[] { String JavaDoc.class, short.class } ),
222                         new MD( "setString", new Class JavaDoc[] { String JavaDoc.class, String JavaDoc.class } ),
223                         new MD( "setTime", new Class JavaDoc[] { String JavaDoc.class, Time.class } ),
224                         new MD( "setTime", new Class JavaDoc[] { String JavaDoc.class, Time.class, Calendar.class } ),
225                         new MD( "setTimestamp", new Class JavaDoc[] { String JavaDoc.class, Timestamp.class } ),
226                         new MD( "setTimestamp", new Class JavaDoc[] { String JavaDoc.class, Timestamp.class, Calendar.class } ),
227                         new MD( "setURL", new Class JavaDoc[] { int.class, URL JavaDoc.class } ),
228                         new MD( "setURL", new Class JavaDoc[] { String JavaDoc.class, URL JavaDoc.class } )
229                 }
230             ),
231             new Exclusions
232             (
233                 java.sql.ResultSet JavaDoc.class,
234                 new MD[]
235                 {
236                     //
237
// THE FOLLOWING METHODS ARE MANDATORY ACCORDING TO THE
238
// JDBC SPEC. HOWEVER, DERBY DOES NOT IMPLEMENT THEM IN ONE
239
// OR THE OTHER OF OUR CLIENTS.
240
//
241
new FD( "updateBlob", new Class JavaDoc[] { int.class, Blob.class } ),
242                     new FD( "updateBlob", new Class JavaDoc[] { String JavaDoc.class, Blob.class } ),
243                                         new FD( "updateBlob", new Class JavaDoc[] { int.class, InputStream.class ,long.class } ),
244                                         new FD( "updateBlob", new Class JavaDoc[] { String JavaDoc.class, InputStream.class ,long.class } ),
245                     new FD( "updateClob", new Class JavaDoc[] { int.class, Clob.class } ),
246                     new FD( "updateClob", new Class JavaDoc[] { String JavaDoc.class, Clob.class } ),
247                                         new FD( "updateClob", new Class JavaDoc[] { int.class, Reader.class ,long.class } ),
248                                         new FD( "updateClob", new Class JavaDoc[] { String JavaDoc.class, Reader.class ,long.class } ),
249                                         new FD( "updateNClob",new Class JavaDoc[] { int.class,Reader.class,long.class}),
250                                         new FD( "updateNClob",new Class JavaDoc[] { String JavaDoc.class,Reader.class,long.class}),
251                     
252
253                     //
254
// According to the JDBC4 spec and javadoc, the following
255
// methods are optional and do not have to be implemented.
256
//
257

258                     new MD( "getNCharacterStream", new Class JavaDoc[] { int.class } ),
259                         new MD( "getNCharacterStream", new Class JavaDoc[] { String JavaDoc.class } ),
260                         new MD( "getNString", new Class JavaDoc[] { int.class } ),
261                         new MD( "getNString", new Class JavaDoc[] { String JavaDoc.class } ),
262                         new MD( "getURL", new Class JavaDoc[] { int.class } ),
263                         new MD( "getURL", new Class JavaDoc[] { String JavaDoc.class } ),
264                         new MD( "getArray", new Class JavaDoc[] { int.class } ),
265                         new MD( "getArray", new Class JavaDoc[] { String JavaDoc.class } ),
266                         new MD( "getNClob", new Class JavaDoc[] { int.class } ),
267                         new MD( "getNClob", new Class JavaDoc[] { String JavaDoc.class } ),
268                         new MD( "getRef", new Class JavaDoc[] { int.class } ),
269                         new MD( "getRef", new Class JavaDoc[] { String JavaDoc.class } ),
270                         new MD( "getRowId", new Class JavaDoc[] { int.class } ),
271                         new MD( "getRowId", new Class JavaDoc[] { String JavaDoc.class } ),
272                         new MD( "getSQLXML", new Class JavaDoc[] { int.class } ),
273                         new MD( "getSQLXML", new Class JavaDoc[] { String JavaDoc.class } ),
274                         new MD( "getUnicodeStream", new Class JavaDoc[] { int.class } ),
275                         new MD( "getUnicodeStream", new Class JavaDoc[] { String JavaDoc.class } ),
276                         new MD( "refreshRow", new Class JavaDoc[] { } ),
277                         new MD( "updateArray", new Class JavaDoc[] { int.class, java.sql.Array JavaDoc.class } ),
278                         new MD( "updateArray", new Class JavaDoc[] { String JavaDoc.class, java.sql.Array JavaDoc.class } ),
279                         new MD( "updateNCharacterStream", new Class JavaDoc[] { int.class, java.io.Reader JavaDoc.class } ),
280                         new MD( "updateNCharacterStream", new Class JavaDoc[] { int.class, java.io.Reader JavaDoc.class, long.class } ),
281                         new MD( "updateNCharacterStream", new Class JavaDoc[] { String JavaDoc.class, java.io.Reader JavaDoc.class } ),
282                         new MD( "updateNCharacterStream", new Class JavaDoc[] { String JavaDoc.class, java.io.Reader JavaDoc.class, long.class } ),
283                         new MD( "updateNClob", new Class JavaDoc[] { int.class, NClob.class } ),
284                         new MD( "updateNClob", new Class JavaDoc[] { int.class, Reader.class } ),
285                         new MD( "updateNClob", new Class JavaDoc[] { String JavaDoc.class, NClob.class } ),
286                         new MD( "updateNClob", new Class JavaDoc[] { String JavaDoc.class, Reader.class } ),
287                         new MD( "updateNString", new Class JavaDoc[] { int.class, String JavaDoc.class } ),
288                         new MD( "updateNString", new Class JavaDoc[] { String JavaDoc.class, String JavaDoc.class } ),
289                         new MD( "updateRef", new Class JavaDoc[] { int.class, Ref.class } ),
290                         new MD( "updateRef", new Class JavaDoc[] { String JavaDoc.class, Ref.class } ),
291                         new MD( "updateRowId", new Class JavaDoc[] { int.class, RowId.class } ),
292                         new MD( "updateRowId", new Class JavaDoc[] { String JavaDoc.class, RowId.class } ),
293                         new MD( "updateSQLXML", new Class JavaDoc[] { int.class, SQLXML.class } ),
294                         new MD( "updateSQLXML", new Class JavaDoc[] { String JavaDoc.class, SQLXML.class } )
295                         } ),
296             //
297
// Lance Andersen, spec lead for JDBC4, says:
298
// If you support a datatype, then you have to implement
299
// all of its methods.
300
//
301

302             new Exclusions
303             (
304              //
305
// THE FOLLOWING METHODS ARE MANDATORY ACCORDING TO THE
306
// JDBC SPEC. HOWEVER, DERBY DOES NOT IMPLEMENT THEM IN ONE
307
// OR THE OTHER OF OUR CLIENTS.
308
//
309
java.sql.Blob JavaDoc.class,
310                 new MD[]
311                 {
312                     new FD( "getBinaryStream", new Class JavaDoc[] { long.class, long.class } ),
313                     new FD( "setBinaryStream", new Class JavaDoc[] { long.class } ),
314                     new FD( "setBytes", new Class JavaDoc[] { long.class, byte[].class } ),
315                     new FD( "setBytes", new Class JavaDoc[] { long.class, byte[].class, int.class, int.class } ),
316                     new FD( "truncate", new Class JavaDoc[] { long.class } )
317                 } ),
318             new Exclusions
319             (
320              //
321
// THE FOLLOWING METHODS ARE MANDATORY ACCORDING TO THE
322
// JDBC SPEC. HOWEVER, DERBY DOES NOT IMPLEMENT THEM IN ONE
323
// OR THE OTHER OF OUR CLIENTS.
324
//
325
java.sql.Clob JavaDoc.class,
326                 new MD[]
327                 {
328                     new FD( "getCharacterStream", new Class JavaDoc[] { long.class, long.class } ),
329                     new FD( "setAsciiStream", new Class JavaDoc[] { long.class } ),
330                     new FD( "setCharacterStream", new Class JavaDoc[] { long.class } ),
331                     new FD( "setString", new Class JavaDoc[] { long.class, String JavaDoc.class } ),
332                     new FD( "setString", new Class JavaDoc[] { long.class, String JavaDoc.class, int.class, int.class } ),
333                     new FD( "truncate", new Class JavaDoc[] { long.class } )
334                 } )
335         };
336
337     //
338
// This is the Hashtable where we keep the exclusions.
339
//
340
private static Hashtable< Class JavaDoc, HashSet<Method> > excludableMap;
341     
342     /////////////////////////////////////////////////////////////
343
//
344
// CONSTRUCTOR
345
//
346
/////////////////////////////////////////////////////////////
347

348     /**
349      * Creates a new instance.
350      */

351     public UnsupportedVetter() { super("UnsupportedVetter"); }
352
353     /////////////////////////////////////////////////////////////
354
//
355
// ENTRY POINTS
356
//
357
/////////////////////////////////////////////////////////////
358

359     /**
360      * <p>
361      * Find all methods in this framework which raise SQLFeatureNotSupportedException.
362      * </p>
363      */

364     public void testSupportedMethods()
365         throws Exception JavaDoc
366     {
367         getTestConfiguration().setVerbosity( true );
368
369         HashSet<String JavaDoc> vanishedMethodList = new HashSet<String JavaDoc>();
370         HashSet<String JavaDoc> unsupportedList = new HashSet<String JavaDoc>();
371         HashSet<String JavaDoc> notUnderstoodList = new HashSet<String JavaDoc>();
372
373         // Build map of interfaces to their methods which may raise SQLFeatureNotSupportedException.
374
initializeExcludableMap( vanishedMethodList );
375
376         vetDataSource( unsupportedList, notUnderstoodList );
377         vetConnectionPooledDataSource( unsupportedList, notUnderstoodList );
378         vetXADataSource( unsupportedList, notUnderstoodList );
379
380         //
381
// Print methods which behave unexpectedly.
382
//
383
printVanishedMethodList( vanishedMethodList );
384         printUnsupportedList( unsupportedList );
385         printNotUnderstoodList( notUnderstoodList );
386
387         int actualErrorCount =
388             vanishedMethodList.size() +
389             unsupportedList.size() +
390             notUnderstoodList.size();
391
392         assertEquals
393             ( "Unexpected discrepancies.",
394               0, actualErrorCount );
395     }
396
397     //
398
// Find all the objects inside the DataSource and vet them.
399
//
400
private void vetDataSource
401         ( HashSet<String JavaDoc> unsupportedList, HashSet<String JavaDoc> notUnderstoodList )
402         throws Exception JavaDoc
403     {
404         DataSource ds = TestDataSourceFactory.getDataSource();
405         Connection conn = ds.getConnection();
406
407         vetObject( ds, unsupportedList, notUnderstoodList );
408
409         connectionWorkhorse( conn, unsupportedList, notUnderstoodList );
410     }
411
412     //
413
// Find all the objects inside the ConnectionPooledDataSource and vet them.
414
//
415
private void vetConnectionPooledDataSource
416         ( HashSet<String JavaDoc> unsupportedList, HashSet<String JavaDoc> notUnderstoodList )
417         throws Exception JavaDoc
418     {
419         ConnectionPoolDataSource ds = TestDataSourceFactory.getConnectionPoolDataSource();
420         PooledConnection pc = ds.getPooledConnection
421             (getTestConfiguration().getUserName(),
422                     getTestConfiguration().getUserPassword());
423         Connection conn = pc.getConnection();
424
425         vetObject( ds, unsupportedList, notUnderstoodList );
426         vetObject( pc, unsupportedList, notUnderstoodList );
427
428         connectionWorkhorse( conn, unsupportedList, notUnderstoodList );
429     }
430
431     //
432
// Find all the objects inside the XADataSource and vet them.
433
//
434
private void vetXADataSource
435         ( HashSet<String JavaDoc> unsupportedList, HashSet<String JavaDoc> notUnderstoodList )
436         throws Exception JavaDoc
437     {
438         XADataSource ds = TestDataSourceFactory.getXADataSource();
439         XAConnection xaconn = ds.getXAConnection
440             (getTestConfiguration().getUserName(),
441                     getTestConfiguration().getUserPassword());
442         Connection conn = xaconn.getConnection();
443
444         vetObject( ds, unsupportedList, notUnderstoodList );
445         vetObject( xaconn, unsupportedList, notUnderstoodList );
446
447         connectionWorkhorse( conn, unsupportedList, notUnderstoodList );
448     }
449
450     //
451
// Find all the methods for java.sql objects in the Connection which raise
452
// SQLFeatureNotSupportedException.
453
//
454
private void connectionWorkhorse
455         ( Connection conn, HashSet<String JavaDoc> unsupportedList, HashSet<String JavaDoc> notUnderstoodList )
456         throws Exception JavaDoc
457     {
458         vetSavepoint( conn, unsupportedList, notUnderstoodList );
459         vetLargeObjects( conn, unsupportedList, notUnderstoodList );
460         
461         DatabaseMetaData dbmd = conn.getMetaData();
462         PreparedStatement ps = conn.prepareStatement
463             ( "select * from sys.systables where tablename = ?" );
464
465         ps.setString( 1, "foo" );
466
467         ParameterMetaData parameterMetaData = ps.getParameterMetaData();
468         ResultSet rs = ps.executeQuery();
469         ResultSetMetaData rsmd = rs.getMetaData();
470         Statement stmt = conn.createStatement();
471
472         CallableStatement cs =
473             conn.prepareCall("CALL SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(0)");
474         ParameterMetaData csmd = cs.getParameterMetaData();
475
476         //
477
// The vetObject() method calls all of the methods in these objects
478
// in a deterministic order, calling the close() method last.
479
// Inspect these objects in an order which respects the fact that
480
// the objects are closed as a result of calling vetObject().
481
//
482
vetObject( dbmd, unsupportedList, notUnderstoodList );
483         vetObject( stmt, unsupportedList, notUnderstoodList );
484         vetObject( csmd, unsupportedList, notUnderstoodList );
485         vetObject( cs, unsupportedList, notUnderstoodList );
486         vetObject( rsmd, unsupportedList, notUnderstoodList );
487         vetObject( rs, unsupportedList, notUnderstoodList );
488         vetObject( parameterMetaData, unsupportedList, notUnderstoodList );
489         vetObject( ps, unsupportedList, notUnderstoodList );
490         vetObject( conn, unsupportedList, notUnderstoodList );
491
492         // No need to close the objects. They were closed by vetObject().
493
}
494     
495     //
496
// Examine Savepoints.
497
//
498
private void vetSavepoint
499         ( Connection conn, HashSet<String JavaDoc> unsupportedList, HashSet<String JavaDoc> notUnderstoodList )
500         throws Exception JavaDoc
501     {
502         conn.setAutoCommit( false );
503
504         Savepoint sp = conn.setSavepoint();
505         
506         vetObject( sp, unsupportedList, notUnderstoodList );
507         
508         conn.releaseSavepoint(sp);
509     }
510
511     //
512
// Examine BLOBs and CLOBs.
513
//
514
private void vetLargeObjects
515         ( Connection conn, HashSet<String JavaDoc> unsupportedList, HashSet<String JavaDoc> notUnderstoodList )
516         throws Exception JavaDoc
517     {
518         Statement stmt = conn.createStatement();
519
520         stmt.execute("CREATE TABLE t (id INT PRIMARY KEY, " +
521                      "b BLOB(10), c CLOB(10))");
522         stmt.execute("INSERT INTO t (id, b, c) VALUES (1, "+
523                      "CAST (" + TestUtil.stringToHexLiteral("101010001101") +
524                      "AS BLOB(10)), CAST ('hello' AS CLOB(10)))");
525
526         ResultSet rs = stmt.executeQuery("SELECT id, b, c FROM t");
527
528         rs.next();
529
530         Blob blob = rs.getBlob(2);
531         Clob clob = rs.getClob(3);
532
533         vetObject( blob, unsupportedList, notUnderstoodList );
534         vetObject( clob, unsupportedList, notUnderstoodList );
535
536         stmt.close();
537         conn.rollback();
538     }
539
540
541     /////////////////////////////////////////////////////////////
542
//
543
// MINIONS
544
//
545
/////////////////////////////////////////////////////////////
546

547     //
548
// Initialize the hashtable of methods which are allowed to raise
549
// SQLFeatureNotSupportedException.
550
//
551
private void initializeExcludableMap( HashSet<String JavaDoc> vanishedMethodList )
552         throws Exception JavaDoc
553     {
554         excludableMap = new Hashtable< Class JavaDoc, HashSet<Method> >();
555         
556         int count = rawExcludables.length;
557
558         for ( int i = 0; i < count; i++ )
559         {
560             Exclusions exclusions = rawExcludables[ i ];
561             Class JavaDoc iface = exclusions.getInterface();
562             MD[] mds = exclusions.getExcludedMethods();
563             int exclusionCount = mds.length;
564             HashSet<Method> excludedMethodSet = new HashSet<Method>();
565
566             for ( int j = 0; j < exclusionCount; j++ )
567             {
568                 MD md = mds[ j ];
569
570                 //
571
// If we are strictly enforcing the JDBC standard,
572
// then expose the mandatory methods which we know Derby
573
// doesn't implement.
574
//
575
if ( STRICT_ENFORCEMENT && !md.isOptional() ) { continue; }
576
577                 Method method = null;
578
579                 try {
580                     method = iface.getMethod( md.getMethodName(), md.getArgTypes() );
581                 } catch (NoSuchMethodException JavaDoc e) {}
582
583                 if ( method == null )
584                 {
585                     vanishedMethodList.add
586                         ( "Method has vanished from SQL interface: " + iface.getName() + "." + md );
587                 }
588
589                 excludedMethodSet.add( method );
590             }
591
592             excludableMap.put( iface, excludedMethodSet );
593         }
594     }
595
596     //
597
// Find all the methods from java.sql interfaces which are implemented by an object
598
// and which raise SQLFeatureNotSupportedException.
599
//
600
private void vetObject
601         ( Object JavaDoc candidate, HashSet<String JavaDoc> unsupportedList, HashSet<String JavaDoc> notUnderstoodList )
602         throws Exception JavaDoc
603     {
604         Class JavaDoc myClass = candidate.getClass();
605
606         vetInterfaces( candidate, myClass, unsupportedList, notUnderstoodList );
607     }
608
609     //
610
// Find all the java.sql interfaces implemented by a class and find
611
// the methods in those interfaces which raise
612
// SQLFeatureNotSupportedException when called on the passed-in candidate object.
613
//
614
private void vetInterfaces
615         ( Object JavaDoc candidate, Class JavaDoc myClass,
616           HashSet<String JavaDoc> unsupportedList, HashSet<String JavaDoc> notUnderstoodList )
617         throws Exception JavaDoc
618     {
619         Class JavaDoc superClass = myClass.getSuperclass();
620
621         if ( superClass != null )
622         { vetInterfaces( candidate, superClass, unsupportedList, notUnderstoodList ); }
623
624         //
625
// The contract for Class.getInterfaces() states that the interfaces
626
// come back in a deterministic order, namely, in the order that
627
// they were declared in the "extends" clause.
628
//
629
Class JavaDoc<?>[] interfaces = myClass.getInterfaces();
630         int interfaceCount = interfaces.length;
631
632         for ( int i = 0; i < interfaceCount; i++ )
633         {
634             Class JavaDoc<?> iface = interfaces[ i ];
635
636             if ( iface.getPackage().getName().equals( SQL_PACKAGE_NAME ) )
637             {
638                 vetInterfaceMethods( candidate, iface, unsupportedList, notUnderstoodList );
639             }
640
641             vetInterfaces( candidate, iface, unsupportedList, notUnderstoodList );
642         }
643     }
644
645     //
646
// Examine all the methods in an interface to determine which ones
647
// raise SQLFeatureNotSupportedException.
648
//
649
private void vetInterfaceMethods
650         ( Object JavaDoc candidate, Class JavaDoc iface,
651           HashSet<String JavaDoc> unsupportedList, HashSet<String JavaDoc> notUnderstoodList )
652         throws Exception JavaDoc
653     {
654         Method[] methods = sortMethods( iface );
655         int methodCount = methods.length;
656
657         for ( int i = 0; i < methodCount; i++ )
658         {
659             Method method = methods[ i ];
660
661             vetMethod( candidate, iface, method, unsupportedList, notUnderstoodList );
662         }
663     }
664
665     //
666
// Return the methods of an interface in a deterministic
667
// order. Class.getMethods() does not do us this favor.
668
//
669
private Method[] sortMethods( Class JavaDoc iface )
670         throws Exception JavaDoc
671     {
672         Method[] raw = iface.getMethods();
673         int count = raw.length;
674         Method[] cooked = new Method[ count ];
675         MethodSortable[] sortables = new MethodSortable[ count ];
676
677         for ( int i = 0; i < count; i++ ) { sortables[ i ] = new MethodSortable( raw[ i ] ); }
678
679         Arrays.sort( sortables );
680
681         for ( int i = 0; i < count; i++ ) { cooked[ i ] = sortables[ i ].getMethod(); }
682
683         return cooked;
684     }
685
686     //
687
// Examine a single method to see if it raises SQLFeatureNotSupportedException.
688
//
689
private void vetMethod
690         ( Object JavaDoc candidate, Class JavaDoc iface, Method method,
691           HashSet<String JavaDoc> unsupportedList, HashSet<String JavaDoc> notUnderstoodList )
692         throws Exception JavaDoc
693     {
694         try {
695             method.invoke( candidate, getNullArguments( method.getParameterTypes() ) );
696
697             // it's ok for the method to succeed
698
}
699         catch (Throwable JavaDoc e)
700         {
701             if ( !( e instanceof InvocationTargetException ) )
702             {
703                 recordUnexpectedError( candidate, iface, method, notUnderstoodList, e );
704             }
705             else
706             {
707                 Throwable JavaDoc cause = e.getCause();
708                 
709                 if ( cause instanceof SQLFeatureNotSupportedException )
710                 {
711                     boolean isExcludable = isExcludable( method );
712
713                     if ( !isExcludable )
714                     {
715                         StackTraceElement JavaDoc[] stack =
716                         cause.getStackTrace();
717                         int i = 0;
718                         while(i < stack.length && !stack[i].getMethodName().
719                               equals("notImplemented")){
720                                 ++i;
721                             }
722                             while(i < stack.length && stack[i].getMethodName().
723                                   equals("notImplemented")){
724                                 ++i;
725                             }
726                             if (i == stack.length) {
727                                 //cause.printStackTrace();
728
}
729                      
730                             unsupportedList.add( candidate.getClass().getName() + ": " + method + "@" + (i==stack.length?"no source":cause.getStackTrace()[i]));
731                     } else {
732
733                     }
734                 }
735                 else if ( cause instanceof SQLException )
736                 {
737                     // swallow other SQLExceptions, caused by bogus args
738
}
739                 else if ( cause instanceof NullPointerException JavaDoc )
740                 {
741                     // swallow other NPEs, caused by bogus args
742
}
743                 else if ( cause instanceof ArrayIndexOutOfBoundsException JavaDoc )
744                 {
745                     // swallow these, caused by bogus args
746
}
747                 else
748                 {
749                     recordUnexpectedError( candidate, iface, method, notUnderstoodList, cause );
750                 }
751                 
752             }
753         }
754     }
755
756     //
757
// Record an unexpected error.
758
//
759
private void recordUnexpectedError
760         ( Object JavaDoc candidate, Class JavaDoc iface, Method method,
761           HashSet<String JavaDoc> notUnderstoodList, Throwable JavaDoc cause )
762         throws Exception JavaDoc
763     {
764         notUnderstoodList.add
765             ( candidate.getClass().getName() + " " + method + " raises " + cause );
766     }
767     
768     //
769
// Returns true if this method is allowed to raise SQLFeatureNotSupportedException.
770
//
771
private boolean isExcludable(Method method )
772         throws Exception JavaDoc
773     {
774         Class JavaDoc iface = method.getDeclaringClass();
775         HashSet<Method> excludableMethods = excludableMap.get( iface );
776
777         if ( excludableMethods == null )
778         {
779             return false;
780         }
781
782         return excludableMethods.contains( method );
783     }
784     
785     /**
786      * Takes an array of classes and returns an array of objects with
787      * null values compatible with the classes. Helper method for
788      * converting a parameter list to an argument list.
789      *
790      * @param params a <code>Class[]</code> value
791      * @return an <code>Object[]</code> value
792      */

793     private Object JavaDoc[] getNullArguments(Class JavaDoc[] params) {
794         Object JavaDoc[] args = new Object JavaDoc[params.length];
795         for (int i = 0; i < params.length; i++) {
796             args[i] = getNullValueForType(params[i]);
797         }
798         return args;
799     }
800
801     /**
802      * Returns a null value compatible with the class. For instance,
803      * return <code>Boolean.FALSE</code> for primitive booleans, 0 for
804      * primitive integers and <code>null</code> for non-primitive
805      * types.
806      *
807      * @param type a <code>Class</code> value
808      * @return a null value
809      */

810     private Object JavaDoc getNullValueForType(Class JavaDoc type)
811     {
812         if (!type.isPrimitive()) {
813             return null;
814         }
815         if (type == Boolean.TYPE) {
816             return Boolean.FALSE;
817         }
818         if (type == Character.TYPE) {
819             return new Character JavaDoc((char) 0);
820         }
821         if (type == Byte.TYPE) {
822             return new Byte JavaDoc((byte) 0);
823         }
824         if (type == Short.TYPE) {
825             return new Short JavaDoc((short) 0);
826         }
827         if (type == Integer.TYPE) {
828             return new Integer JavaDoc(0);
829         }
830         if (type == Long.TYPE) {
831             return new Long JavaDoc(0L);
832         }
833         if (type == Float.TYPE) {
834             return new Float JavaDoc(0f);
835         }
836         if (type == Double.TYPE) {
837             return new Double JavaDoc(0d);
838         }
839         fail("Don't know how to handle type " + type);
840         return null; // unreachable statement
841
}
842
843     // debug print the list of methods which throw SQLFeatureNotSupportedException
844
private void printUnsupportedList( HashSet<String JavaDoc> unsupportedList )
845     {
846         int count = unsupportedList.size();
847
848         if ( count == 0 ) { return; }
849
850         println( "--------------- UNSUPPORTED METHODS ------------------" );
851         println( "--" );
852
853         String JavaDoc[] result = new String JavaDoc[ count ];
854
855         unsupportedList.toArray( result );
856         Arrays.sort( result );
857
858         for ( int i = 0; i < count; i++ )
859         {
860             println( result[ i ] );
861         }
862     }
863
864     // debug print the list of methods which have disappeared from the SQL interface
865
private void printVanishedMethodList( HashSet<String JavaDoc> vanishedMethodList )
866     {
867         int count = vanishedMethodList.size();
868
869         if ( count == 0 ) { return; }
870
871         println( "--------------- VANISHED METHODS ------------------" );
872         println( "--" );
873
874         String JavaDoc[] result = new String JavaDoc[ count ];
875
876         vanishedMethodList.toArray( result );
877         Arrays.sort( result );
878
879         for ( int i = 0; i < count; i++ )
880         {
881             println( result[ i ] );
882         }
883     }
884
885     // Debug print the list of method failures which we don't understand
886
private void printNotUnderstoodList( HashSet<String JavaDoc> notUnderstoodList )
887     {
888         int count = notUnderstoodList.size();
889
890         if ( count == 0 ) { return; }
891
892         println( "\n\n" );
893         println( "--------------- NOT UNDERSTOOD METHODS ------------------" );
894         println( "--" );
895
896         String JavaDoc[] result = new String JavaDoc[ count ];
897
898         notUnderstoodList.toArray( result );
899         Arrays.sort( result );
900
901         for ( int i = 0; i < count; i++ )
902         {
903             println( result[ i ] );
904         }
905     }
906
907     /////////////////////////////////////////////////////////////
908
//
909
// INNER CLASSES
910
//
911
/////////////////////////////////////////////////////////////
912

913     /**
914      * <p>
915      * Method descriptor for optional methods which Derby does not have
916      * to implement. We abbreviate the name of this class to make
917      * arrays of these declarations compact and readable.
918      * </p>
919      */

920     public static class MD
921     {
922         private String JavaDoc _methodName;
923         private Class JavaDoc[] _argTypes;
924
925         /** Construct from methodName and argument types. */
926         public MD( String JavaDoc methodName, Class JavaDoc[] argTypes )
927         {
928             _methodName = methodName;
929             _argTypes = argTypes;
930         }
931
932         /** Get the name of this method. */
933         public String JavaDoc getMethodName() { return _methodName; }
934
935         /** Get the types of the method's arguments */
936         public Class JavaDoc[] getArgTypes() { return _argTypes; }
937
938         /** Return whether this method is optional */
939         public boolean isOptional() { return true; }
940
941         public String JavaDoc toString()
942         {
943             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
944
945             buffer.append( _methodName );
946             buffer.append( "( " );
947
948             if ( _argTypes != null )
949             {
950                 int count = _argTypes.length;
951
952                 for ( int i = 0; i < count; i++ )
953                 {
954                     if ( i > 0 ) { buffer.append( ", " ); }
955
956                     buffer.append( _argTypes[ i ].getName() );
957                 }
958             }
959
960             buffer.append( " )" );
961
962             return buffer.toString();
963         }
964
965     }
966
967     /**
968      * <p>
969      * Method descriptor for mandatory methods which we know Derby does not
970      * implement. We abbreviate the name of this class to make
971      * arrays of these declarations compact and readable.
972      * </p>
973      */

974     public static final class FD extends MD
975     {
976         private String JavaDoc _methodName;
977         private Class JavaDoc[] _argTypes;
978
979         /** Construct from methodName and argument types. */
980         public FD( String JavaDoc methodName, Class JavaDoc[] argTypes ) { super( methodName, argTypes ); }
981
982         /** Return whether this method is optional */
983         public boolean isOptional() { return false; }
984     }
985
986     /**
987      * <p>
988      * Describes all of the methods for an interface which are allowed
989      * to raise SQLFeatureNotSupportedException.
990      * </p>
991      */

992     public static final class Exclusions
993     {
994         private Class JavaDoc _class;
995         private MD[] _excludedMethods;
996
997         /** Construct from the interface and descriptors for the methods which
998          are allowed to raise SQLFeatureNotSupportedException */

999         public Exclusions( Class JavaDoc theInterface, MD[] excludedMethods )
1000        {
1001            _class = theInterface;
1002            _excludedMethods = excludedMethods;
1003        }
1004        
1005        /** Get the interface. */
1006        public Class JavaDoc getInterface() { return _class; }
1007
1008        /** Get descriptors for the methods which may raise
1009            SQLFeatureNotSupportedException. */

1010        public MD[] getExcludedMethods() { return _excludedMethods; }
1011    }
1012
1013    /**
1014     * <p>
1015     * Used for sorting methods, which don't come back from Class.getMethods()
1016     * in a deterministic order. For extra credit, we put the close() method at
1017     * the end of the sort order so that, when we invoke the sorted methods, we
1018     * don't accidentally invalidate the receiver.
1019     * </p>
1020     */

1021    public static final class MethodSortable implements Comparable JavaDoc
1022    {
1023        private Method _method;
1024
1025        /** Conjure out of a Method */
1026        public MethodSortable( Method method ) { _method = method; }
1027
1028        /** Get the wrapped Method */
1029        public Method getMethod() { return _method; }
1030
1031        //////////////////////////////////////////////////
1032
//
1033
// Comparable BEHAVIOR
1034
//
1035
//////////////////////////////////////////////////
1036

1037        public int compareTo( Object JavaDoc other )
1038        {
1039            MethodSortable that = (MethodSortable) other;
1040            boolean thisIsClose = this.isCloseMethod();
1041            boolean thatIsClose = that.isCloseMethod();
1042
1043            // throw the close() method to the end of the sort order
1044
if ( thisIsClose )
1045            {
1046                if ( thatIsClose ) { return 0; }
1047                else { return 1; }
1048            }
1049            else if ( thatIsClose ) { return -1; }
1050
1051            return this.toString().compareTo( that.toString() );
1052        }
1053
1054        //////////////////////////////////////////////////
1055
//
1056
// Object OVERRIDES
1057
//
1058
//////////////////////////////////////////////////
1059

1060        public String JavaDoc toString() { return _method.toString(); }
1061        
1062        //////////////////////////////////////////////////
1063
//
1064
// MINIONS
1065
//
1066
//////////////////////////////////////////////////
1067

1068        // Returns true if the wrapped method is close().
1069
private boolean isCloseMethod()
1070        {
1071            return ( toString().startsWith( "close()" ) );
1072        }
1073        
1074    }
1075    
1076}
1077
1078
Popular Tags