File: StatementTest.java

package info (click to toggle)
derby 10.14.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 78,896 kB
  • sloc: java: 691,930; sql: 42,686; xml: 20,511; sh: 3,373; sed: 96; makefile: 60
file content (742 lines) | stat: -rw-r--r-- 28,111 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
/*
 *
 * Derby - Class org.apache.derbyTesting.functionTests.tests.jdbc4.StatementTest
 *
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to you under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, 
 * software distributed under the License is distributed on an 
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
 * either express or implied. See the License for the specific 
 * language governing permissions and limitations under the License.
 */

package org.apache.derbyTesting.functionTests.tests.jdbc4;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLTimeoutException;
import java.sql.Statement;
import junit.framework.Test;
import org.apache.derby.client.am.ClientStatement;
import org.apache.derby.impl.jdbc.EmbedResultSet;
import org.apache.derby.impl.sql.execute.RowUtil;
import org.apache.derby.shared.common.sanity.SanityManager;
import org.apache.derbyTesting.functionTests.tests.jdbcapi.BatchUpdateTest;
import org.apache.derbyTesting.functionTests.tests.jdbcapi.SetQueryTimeoutTest;
import org.apache.derbyTesting.functionTests.tests.jdbcapi.Wrapper41Statement;
import org.apache.derbyTesting.functionTests.util.SQLStateConstants;
import org.apache.derbyTesting.junit.BaseJDBCTestCase;
import org.apache.derbyTesting.junit.BaseTestSuite;
import org.apache.derbyTesting.junit.TestConfiguration;

/**
 * Tests for new methods added for Statement in JDBC4.
 */
public class StatementTest
    extends BaseJDBCTestCase {

   /** Default statement used by the tests. */
    private Statement stmt = null;
    
    /**
     * Create a new test with the given name.
     *
     * @param name name of the test.
     */
    public StatementTest(String name) {
        super(name);
    }

    /**
     * Create default connection and statement.
     *
     * @throws SQLException if setAutoCommit, createStatement or 
     *                      BaseJDBCTestCase.getConnection fails.
     */
    protected void setUp() 
        throws SQLException {
        getConnection().setAutoCommit(false);
        // Create a default statement.
        stmt = createStatement();
        assertFalse("First statement must be open initially", 
                stmt.isClosed());
    }

    /**
     * Close default connection and statement if necessary.
     *
     * @throws SQLException if a database access exception occurs.
     */
    protected void tearDown() 
        throws Exception {
        // Close default statement
        if (stmt != null) {
            stmt.close();
            stmt = null;
        }

        super.tearDown();
    }

    /**
     * Check that <code>isClosed</code> returns <code>true</code> after
     * the statement has been explicitly closed.
     */
    public void testIsClosedBasic()
        throws SQLException {
        ResultSet rs = stmt.executeQuery("select count(*) from stmtTable");
        assertFalse("Statement should still be open", stmt.isClosed());
        rs.close();
        assertFalse("Statement should be open after ResultSet has been " +
                "closed", stmt.isClosed());
        stmt.close();
        assertTrue("Statement should be closed, close() has been called", 
                stmt.isClosed());
    }
    
    /**
     * Test that creating two statements on the same connection does not
     * cause side effects on the statements.
     */
    public void testIsClosedWithTwoStatementsOnSameConnection()
        throws SQLException {
        // Create a second statement on the default connection.
        Statement stmt2 = createStatement();
        assertFalse("Second statement must be open initially", 
                stmt2.isClosed());
        assertFalse("First statement should not be closed when " +
                "creating a second statement", stmt.isClosed());
        ResultSet rs = stmt2.executeQuery("select count(*) from stmtTable");
        assertFalse("Second statement should be open after call to " +
                "execute()", stmt2.isClosed());
        assertFalse("First statement should be open after call to " +
                "second statment's execute()", stmt.isClosed());
        stmt2.close();
        assertTrue("Second statement should be closed, close() has " +
                "been called!", stmt2.isClosed());
        assertFalse("First statement should be open after call to " +
                "second statment's close()", stmt.isClosed());
    }

    /**
     * Test that the two statements created on the connection are closed
     * when the connection itself is closed.
     */
    public void testIsClosedWhenClosingConnection()
        throws SQLException {
        // Create an extra statement for good measure.
        Statement stmt2 = createStatement();
        assertFalse("Second statement must be open initially",
                stmt2.isClosed());
        // Exeute something on it, as opposed to the default statement.
        stmt2.execute("select count(*) from stmtTable");
        assertFalse("Second statement should be open after call to " +
                "execute()", stmt2.isClosed());
        // Close the connection. We must commit/rollback first, or else a
        // "Invalid transaction state" exception is raised.
        rollback();
        Connection con = getConnection();
        con.close();
        assertTrue("Connection should be closed after close()", 
                con.isClosed());
        assertTrue("First statement should be closed, as parent " +
                "connection has been closed", stmt.isClosed());
        assertTrue("Second statement should be closed, as parent " +
                "connection has been closed", stmt2.isClosed());
    }
    
    /**
     * Check the state of the statement when the connection is first attempted
     * closed when in an invalid transaction state, then closed after a
     * commit. According to the JDBC 4 API documentation: </i>"It is strongly 
     * recommended that an application explictly commits or rolls back an 
     * active transaction prior to calling the close method. If the close 
     * method is called and there is an active transaction, 
     * the results are implementation-defined."</i>
     * Derby throws an exception and keeps the connection open.
     */
    public void testIsClosedWhenClosingConnectionInInvalidState()
        throws SQLException {
        stmt.executeQuery("select count(*) from stmtTable");
        // Connection should now be in an invalid transaction state.
        Connection con = stmt.getConnection();
        try {
            con.close();
            fail("Invalid transaction state exception was not thrown");
        } catch (SQLException sqle) {
            String expectedState =
                SQLStateConstants.INVALID_TRANSACTION_STATE_ACTIVE_SQL_TRANSACTION;
            assertSQLState(expectedState, sqle);
        }
        assertFalse("Statement should still be open, because " +
                "Connection.close() failed", stmt.isClosed());
        assertFalse("Connection should still be open", con.isClosed());
        // Do a commit here, since we do a rollback in another test.
        con.commit();
        con.close();
        assertTrue("Connection should be closed after close()", 
                con.isClosed());
        assertTrue("Statement should be closed, because " +
                "the connection has been closed", stmt.isClosed()); 
        stmt.close();
        assertTrue("Statement should still be closed", stmt.isClosed()); 
    }
        
    /**
     * Execute a query on a statement after the parent connection has been
     * closed.
     */
    public void testStatementExecuteAfterConnectionClose() 
        throws SQLException {
        Connection con = stmt.getConnection();
        con.close();
        assertTrue("Connection should be closed after close()", 
                con.isClosed());
        try {
            stmt.executeQuery("select count(*) from stmtTable");
        } catch (SQLException sqle) {
            assertEquals("Unexpected SQL state for performing " +
                    "operations on a closed statement.",
                    SQLStateConstants.CONNECTION_EXCEPTION_CONNECTION_DOES_NOT_EXIST,
                    sqle.getSQLState());
        }
        assertTrue("Statement should be closed, because " +
                "the connection has been closed", stmt.isClosed()); 
    }

    public void testIsWrapperForStatement() throws SQLException {
        assertTrue(stmt.isWrapperFor(Statement.class));
    }

    public void testIsNotWrapperForPreparedStatement() throws SQLException {
        assertFalse(stmt.isWrapperFor(PreparedStatement.class));
    }

    public void testIsNotWrapperForCallableStatement() throws SQLException {
        assertFalse(stmt.isWrapperFor(CallableStatement.class));
    }

    public void testIsNotWrapperForResultSet() throws SQLException {
        assertFalse(stmt.isWrapperFor(ResultSet.class));
    }

    public void testUnwrapStatement() throws SQLException {
        Statement stmt2 = stmt.unwrap(Statement.class);
        assertSame("Unwrap returned wrong object.", stmt, stmt2);
    }

    public void testUnwrapPreparedStatement() {
        try {
            PreparedStatement ps = stmt.unwrap(PreparedStatement.class);
            fail("Unwrap didn't fail.");
        } catch (SQLException e) {
            assertSQLState("XJ128", e);
        }
    }

    public void testUnwrapCallableStatement() {
        try {
            CallableStatement cs = stmt.unwrap(CallableStatement.class);
            fail("Unwrap didn't fail.");
        } catch (SQLException e) {
            assertSQLState("XJ128", e);
        }
    }

    public void testUnwrapResultSet() throws SQLException {
        try {
            ResultSet rs = stmt.unwrap(ResultSet.class);
            fail("Unwrap didn't fail.");
        } catch (SQLException e) {
            assertSQLState("XJ128", e);
        }
    }

    /**
     * Tests isPoolable, setPoolable, and the default poolability.
     */
    public void testPoolable() throws SQLException {
        assertFalse("Statement cannot be poolable by default", 
                    stmt.isPoolable()); 
        stmt.setPoolable(true);
        assertTrue("Statement must be poolable", stmt.isPoolable());

        stmt.setPoolable(false);
        assertFalse("Statement cannot be poolable", stmt.isPoolable());
    }

    /**
     * Test that Statement.setQueryTimeout() causes statements to
     * raise SQLTimeoutException per the JDBC 4.1 spec clarification.
     */
    public  void    test_jdbc4_1_queryTimeoutException() throws Exception
    {
        SQLException    se = null;

        PreparedStatement ps = prepareStatement
            (
             "select columnnumber from sys.syscolumns c, sys.systables t\n" +
             "where t.tablename = 'SYSTABLES'\n" +
             "and t.tableid = c.referenceid\n" +
             "and mod( delay_st( 5, c.columnnumber ), 3 ) = 0"
             );
        println( "Testing timeout exception for a " + ps.getClass().getName() );
        
        SetQueryTimeoutTest.StatementExecutor   executor =
            new SetQueryTimeoutTest.StatementExecutor( ps, true, 1 );
        
        executor.start();
        executor.join();
        
        ps.close();
        
        se = executor.getSQLException();

        assertNotNull( se );
        assertEquals( SQLTimeoutException.class.getName(), se.getClass().getName() );
    }

    /**
     * Test the closeOnCompletion() and isCloseOnCompletion() methods
     * when using ResultSets which close implicitly.
     */
    public void testCompletionClosure_jdbc4_1_implicitRSClosure() throws Exception
    {
        Connection  conn = getConnection();
        conn.setHoldability( ResultSet.CLOSE_CURSORS_AT_COMMIT );
        conn.setAutoCommit( true );

        PreparedStatement   ps;
        ResultSet   rs;
        Wrapper41Statement  wrapper;

        ps = conn.prepareStatement( "values ( 1 )" );
        println( "Testing implicit closure WITH autocommit on a " + ps.getClass().getName() );
        
        wrapper = new Wrapper41Statement( ps );
        wrapper.closeOnCompletion();

        rs = ps.executeQuery();
        rs.next();
        rs.next();

        assertTrue( rs.isClosed() );
        assertTrue( ps.isClosed() );

        conn.setAutoCommit( false );

        // now retry the experiment with an explicit commit

        ps = conn.prepareStatement( "values ( 1 )" );
        println( "Testing implicit closure WITHOUT autocommit on a " + ps.getClass().getName() );
        
        wrapper = new Wrapper41Statement( ps );
        wrapper.closeOnCompletion();

        rs = ps.executeQuery();
        rs.next();
        rs.next();

        assertFalse( rs.isClosed() );
        assertFalse( ps.isClosed() );

        conn.commit();
        
        assertTrue( rs.isClosed() );
        assertTrue( ps.isClosed() );
    }

    /**
     * Test the large update methods added by JDBC 4.2.
     */
    public void testLargeUpdate_jdbc4_2() throws Exception
    {
        Connection  conn = getConnection();

        largeUpdate_jdbc4_2( conn );
    }

    public  static  void    largeUpdate_jdbc4_2( Connection conn )
        throws Exception
    {
        //
        // This test makes use of a debug entry point which is a NOP
        // in an insane production build.
        //
        if (!SanityManager.DEBUG)    { return; }
        else { println( "Running largeUpdate_jdbc4_2() on debug code." ); }

        conn.prepareStatement
            (
             "create procedure setRowCountBase( newBase bigint )\n" +
             "language java parameter style java no sql\n" +
             "external name 'org.apache.derbyTesting.functionTests.tests.jdbc4.StatementTest.setRowCountBase'\n"
             ).execute();
        conn.prepareStatement
            (
             "create table bigintTable( col1 int generated always as identity, col2 bigint )"
             ).execute();

        StatementWrapper  sw = new StatementWrapper( conn.createStatement() );

        largeUpdateTest( sw, (long) Integer.MAX_VALUE );
        largeUpdateTest( sw, 0L);

        largeBatchTest( sw, (long) Integer.MAX_VALUE );
        largeBatchTest( sw, 0L);

        largeMaxRowsTest( sw,  ((long) Integer.MAX_VALUE) + 1L );

        largeBatchUpdateExceptionTest( sw, ((long) Integer.MAX_VALUE) + 1L );
    }
    private static  void    largeUpdateTest( StatementWrapper sw, long rowCountBase )
        throws Exception
    {
        //
        // This test makes use of a debug entry point which is a NOP
        // in an insane production build.
        //
        if (!SanityManager.DEBUG)    { return; }
        else { println( "Running largeUpdateTest() on debug code." ); }

        // poke the rowCountBase into the engine. all returned row counts will be
        // increased by this amount
        setRowCountBase( sw.getWrappedStatement(), false, rowCountBase );

        largeUpdateTest( sw, rowCountBase, 1L );
        largeUpdateTest( sw, rowCountBase, 3L );
    }
    private static  void    largeUpdateTest( StatementWrapper sw, long rowCountBase, long rowCount )
        throws Exception
    {
        StringBuffer    buffer = new StringBuffer();
        buffer.append( "insert into bigintTable( col2 ) values " );
        for ( long i = 0L; i < rowCount; i++ )
        {
            if ( i > 0L ) { buffer.append( ", " ); }
            buffer.append( "( " + i + " )" );
        }
        String  text = buffer.toString();

        long    expectedResult = rowCountBase + rowCount;

        vetUpdateSize( sw, (int) expectedResult,
                       sw.getWrappedStatement().executeUpdate( text ), expectedResult );
        vetUpdateSize( sw, (int) expectedResult,
                       sw.getWrappedStatement().executeUpdate( text, Statement.RETURN_GENERATED_KEYS ), expectedResult );
        vetUpdateSize( sw, (int) expectedResult,
                       sw.getWrappedStatement().executeUpdate( text, new int[] { 1 } ), expectedResult );
        vetUpdateSize( sw, (int) expectedResult,
                       sw.getWrappedStatement().executeUpdate( text, new String[] { "COL1" } ), expectedResult );

        vetUpdateSize( sw, expectedResult, sw.executeLargeUpdate( text ), expectedResult );
        vetUpdateSize( sw, expectedResult, sw.executeLargeUpdate( text, Statement.RETURN_GENERATED_KEYS ), expectedResult );
        vetUpdateSize( sw, expectedResult, sw.executeLargeUpdate( text, new int[] { 1 } ), expectedResult );
        vetUpdateSize( sw, expectedResult, sw.executeLargeUpdate( text, new String[] { "COL1" } ), expectedResult );
    }
    private static  void    vetUpdateSize( StatementWrapper sw, int expected, int actual, long longAnswer )
        throws Exception
    {
        assertEquals( expected, actual );
        assertEquals( expected, sw.getWrappedStatement().getUpdateCount() );
        assertEquals( longAnswer, sw.getLargeUpdateCount() );
    }
    private static  void    vetUpdateSize( StatementWrapper sw, long expected, long actual, long longAnswer )
        throws Exception
    {
        assertEquals( expected, actual );
        assertEquals( (int) expected, sw.getWrappedStatement().getUpdateCount() );
        assertEquals( longAnswer, sw.getLargeUpdateCount() );
    }
    private static  void    largeBatchTest( StatementWrapper sw, long rowCountBase )
        throws Exception
    {
        //
        // This test makes use of a debug entry point which is a NOP
        // in an insane production build.
        //
        if (!SanityManager.DEBUG)    { return; }

        println( "Large batch test with rowCountBase = " + rowCountBase );
        
        // poke the rowCountBase into the engine. all returned row counts will be
        // increased by this amount
        sw.getWrappedStatement().clearBatch();
        setRowCountBase( sw.getWrappedStatement(), false, rowCountBase );

        long[]  expectedResult = new long[] { rowCountBase + 1L, rowCountBase + 1L, rowCountBase + 2L };

        createBatch( sw );
        assertEquals( sw.getWrappedStatement().executeBatch(), squashLongs( expectedResult ) );

        createBatch( sw );
        assertEquals( sw.executeLargeBatch(), expectedResult );
    }
    private static  void    createBatch( StatementTest.StatementWrapper sw )
        throws Exception
    {
        sw.getWrappedStatement().clearBatch();
        truncate( sw );
        sw.getWrappedStatement().addBatch( "insert into bigintTable( col2 ) values ( 1 )" );
        sw.getWrappedStatement().addBatch( "update bigintTable set col2 = 2" );
        sw.getWrappedStatement().addBatch( "insert into bigintTable( col2 ) values ( 3 ), ( 4 )" );
    }
    private static  void    largeMaxRowsTest( StatementWrapper sw, long maxRows )
        throws Exception
    {
        //
        // This test makes use of a debug entry point which is a NOP
        // in an insane production build.
        //
        if (!SanityManager.DEBUG)    { return; }

        println( "Large max rows test with maxRows = " + maxRows );

        long    expectedRowCount = 3L;

        truncate( sw );
        sw.getWrappedStatement().execute( "insert into bigintTable( col2 ) values ( 1 ), ( 2 ), ( 3 ), ( 4 ), ( 5 )" );
        
        setRowCountBase( sw.getWrappedStatement(), usingDerbyNetClient(), maxRows - expectedRowCount );

        sw.setLargeMaxRows( maxRows );
        
        ResultSet   rs = sw.getWrappedStatement().executeQuery( "select * from bigintTable" );
        int     rowCount = 0;
        while( rs.next() ) { rowCount++; }
        rs.close();

        setRowCountBase( sw.getWrappedStatement(), usingDerbyNetClient(), 0L );
        
        assertEquals( expectedRowCount, rowCount );
        assertEquals( maxRows, sw.getLargeMaxRows() );
    }
    private static  void    largeBatchUpdateExceptionTest( StatementWrapper sw, long rowCountBase )
        throws Exception
    {
        //
        // This test makes use of a debug entry point which is a NOP
        // in an insane production build.
        //
        if (!SanityManager.DEBUG)    { return; }

        println( "Large batch update exception test with rowCountBase = " + rowCountBase );
        
        sw.getWrappedStatement().clearBatch();
        sw.getWrappedStatement().execute( "create table intTable( col1 int generated always as identity, col2 int )" );

        // poke the rowCountBase into the engine. all returned row counts will be
        // increased by this amount
        setRowCountBase( sw.getWrappedStatement(), false, rowCountBase );

        //
        // Create a batch of statements. The last one will die on an overflow condition.
        //
        sw.getWrappedStatement().addBatch( "insert into intTable( col2 ) values ( 1 )" );
        sw.getWrappedStatement().addBatch( "insert into intTable( col2 ) values ( 1 )" );
        sw.getWrappedStatement().addBatch( "update intTable set col2 = 2147483647 + 1" );

        if ( usingEmbedded() )
        {
            BatchUpdateTest.assertBatchExecuteError
                (
                 "22003", sw.getWrappedStatement(),
                 new long[] { rowCountBase + 1L, rowCountBase + 1L }
                 );
        }
        else if ( usingDerbyNetClient() )
        {
            BatchUpdateTest.assertBatchExecuteError
                (
                 "XJ208", sw.getWrappedStatement(),
                 new long[] { rowCountBase + 1L, rowCountBase + 1L, -3 }
                 );
        }
        
        sw.getWrappedStatement().clearBatch();
        setRowCountBase( sw.getWrappedStatement(), false, 0L );
    }
        
    public static  void    setRowCountBase
        ( Statement stmt, boolean onClient, long rowCountBase )
        throws Exception
    {
        if ( onClient )
        {
            ClientStatement.setFetchedRowBase( rowCountBase );
        }
        else
        {
            stmt.execute( "call setRowCountBase( " + rowCountBase + " )" );
        }
    }
    private static  void    truncate( StatementTest.StatementWrapper sw )
        throws Exception
    {
        sw.getWrappedStatement().execute( "truncate table bigintTable" );
    }
    private static  int[]   squashLongs( long[] longs )
    {
        int count = (longs == null) ? 0 : longs.length;
        int[]   ints = new int[ count ];
        for ( int i = 0; i < count; i++ ) { ints[ i ] = (int) longs[ i ]; }

        return ints;
    }
    
    /**
     * Create test suite for StatementTest.
     */
    public static Test suite() {
        BaseTestSuite suite = new BaseTestSuite("StatementTest suite");
        // Decorate test suite with a TestSetup class.
        suite.addTest(new StatementTestSetup(
                        new BaseTestSuite(StatementTest.class)));
        suite.addTest(TestConfiguration.clientServerDecorator(
            new StatementTestSetup(new BaseTestSuite(StatementTest.class))));
        return suite;
    }

    ////////////////////////////////////////////////////////////////////////
    //
    // NESTED JDBC 4.2 WRAPPER AROUND A Statement
    //
    ////////////////////////////////////////////////////////////////////////

    /**
     * <p>
     * This wrapper is used to expose JDBC 4.2 methods which can run on
     * VM rev levels lower than Java 8.
     * </p>
     */
    public  static  class   StatementWrapper
    {
        private Statement   _wrappedStatement;

        public  StatementWrapper( Statement wrappedStatement )
        {
            _wrappedStatement = wrappedStatement;
        }

        public  Statement   getWrappedStatement() { return _wrappedStatement; }

        // New methods added by JDBC 4.2
        public  long[] executeLargeBatch() throws SQLException
        {
            return ((long[]) invoke
                (
                 "executeLargeBatch",
                 new Class[] {},
                 new Object[] {}
                 ));
        }
        public  long executeLargeUpdate( String sql ) throws SQLException
        {
            return ((Long) invoke
                (
                 "executeLargeUpdate",
                 new Class[] { String.class },
                 new Object[] { sql }
                 )).longValue();
        }
        public  long executeLargeUpdate( String sql, int autoGeneratedKeys) throws SQLException
        {
            return ((Long) invoke
                (
                 "executeLargeUpdate",
                 new Class[] { String.class, Integer.TYPE },
                 new Object[] { sql, autoGeneratedKeys }
                 )).longValue();
        }
        public  long executeLargeUpdate( String sql, int[] columnIndexes ) throws SQLException
        {
            return ((Long) invoke
                (
                 "executeLargeUpdate",
                 new Class[] { String.class, columnIndexes.getClass() },
                 new Object[] { sql, columnIndexes }
                 )).longValue();
        }
        public  long executeLargeUpdate( String sql, String[] columnNames ) throws SQLException
        {
            return ((Long) invoke
                (
                 "executeLargeUpdate",
                 new Class[] { String.class, columnNames.getClass() },
                 new Object[] { sql, columnNames }
                 )).longValue();
        }
        public  long getLargeMaxRows() throws SQLException
        {
            return ((Long) invoke
                (
                 "getLargeMaxRows",
                 new Class[] {},
                 new Object[] {}
                 )).longValue();
        }
        public  long getLargeUpdateCount() throws SQLException
        {
            return ((Long) invoke
                (
                 "getLargeUpdateCount",
                 new Class[] {},
                 new Object[] {}
                 )).longValue();
        }
        public  void setLargeMaxRows( long max ) throws SQLException
        {
            invoke
                (
                 "setLargeMaxRows",
                 new Class[] { Long.TYPE },
                 new Object[] { max }
                 );
        }


        // Reflection minion
        protected Object  invoke( String methodName, Class[] argTypes, Object[] argValues )
            throws SQLException
        {
            try {
                Method  method = _wrappedStatement.getClass().getMethod( methodName, argTypes );

                return method.invoke( _wrappedStatement, argValues );
            }
            catch (NoSuchMethodException nsme) { throw wrap( nsme ); }
            catch (SecurityException se) { throw wrap( se ); }
            catch (IllegalAccessException iae) { throw wrap( iae ); }
            catch (IllegalArgumentException iare) { throw wrap( iare ); }
            catch (InvocationTargetException ite) { throw wrap( ite ); }
        }
        private SQLException    wrap( Throwable t ) { return new SQLException( t.getMessage(), t ); }
    }
    
    ////////////////////////////////////////////////////////////////////////
    //
    // PROCEDURE FOR BUMPING THE RETURNED ROW COUNT, FOR TESTING JDBC 4.2.
    //
    ////////////////////////////////////////////////////////////////////////

    /** Set the base which is used for returned row counts and fetched row counters */
    public  static  void    setRowCountBase( long newBase )
    {
        EmbedResultSet.setFetchedRowBase( newBase );
        RowUtil.setRowCountBase( newBase );
    }

} // End class StatementTest