src/java.sql.rowset/share/classes/com/sun/rowset/internal/CachedRowSetReader.java
author kvn
Fri, 30 Mar 2018 07:47:20 -0700
changeset 49654 16f53c9c7493
parent 47216 71c04702a3d5
permissions -rw-r--r--
8200461: MeetIncompatibleInterfaceArrays test fails with -Xcomp Summary: Add requires to run test only in Xmixed mode. Reviewed-by: simonis
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 11129
diff changeset
     2
 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.rowset.internal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.sql.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.sql.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.naming.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import com.sun.rowset.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.sql.rowset.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.sql.rowset.spi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * The facility called by the <code>RIOptimisticProvider</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * internally to read data into it.  The calling <code>RowSet</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * must have implemented the <code>RowSetInternal</code> interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * and have the standard <code>CachedRowSetReader</code> object set as its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * reader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * This implementation always reads all rows of the data source,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * and it assumes that the <code>command</code> property for the caller
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * is set with a query that is appropriate for execution by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <code>PreparedStatement</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * Typically the <code>SyncFactory</code> manages the <code>RowSetReader</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * the <code>RowSetWriter</code> implementations using <code>SyncProvider</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * Standard JDBC RowSet implementations provide an object instance of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * reader by invoking the <code>SyncProvider.getRowSetReader()</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @author Jonathan Bruce
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @see javax.sql.rowset.spi.SyncProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @see javax.sql.rowset.spi.SyncFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @see javax.sql.rowset.spi.SyncFactoryException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public class CachedRowSetReader implements RowSetReader, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * The field that keeps track of whether the writer associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * this <code>CachedRowSetReader</code> object's rowset has been called since
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * the rowset was populated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * When this <code>CachedRowSetReader</code> object reads data into
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * its rowset, it sets the field <code>writerCalls</code> to 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * When the writer associated with the rowset is called to write
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * data back to the underlying data source, its <code>writeData</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * method calls the method <code>CachedRowSetReader.reset</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * which increments <code>writerCalls</code> and returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * if <code>writerCalls</code> is 1. Thus, <code>writerCalls</code> equals
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * 1 after the first call to <code>writeData</code> that occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * after the rowset has had data read into it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private int writerCalls = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private boolean userCon = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private int startPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private JdbcRowSetResourceBundle resBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public CachedRowSetReader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        } catch(IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            throw new RuntimeException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * Reads data from a data source and populates the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * <code>RowSet</code> object with that data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * This method is called by the rowset internally when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * the application invokes the method <code>execute</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * to read a new set of rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * After clearing the rowset of its contents, if any, and setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * the number of writer calls to <code>0</code>, this reader calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * its <code>connect</code> method to make
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * a connection to the rowset's data source. Depending on which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * of the rowset's properties have been set, the <code>connect</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * method will use a <code>DataSource</code> object or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * <code>DriverManager</code> facility to make a connection to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * data source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Once the connection to the data source is made, this reader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * executes the query in the calling <code>CachedRowSet</code> object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * <code>command</code> property. Then it calls the rowset's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * <code>populate</code> method, which reads data from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * <code>ResultSet</code> object produced by executing the rowset's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * command. The rowset is then populated with this data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * This method's final act is to close the connection it made, thus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * leaving the rowset disconnected from its data source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @param caller a <code>RowSet</code> object that has implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *               the <code>RowSetInternal</code> interface and had
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *               this <code>CachedRowSetReader</code> object set as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *               its reader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @throws SQLException if there is a database access error, there is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *         problem making the connection, or the command property has not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *         been set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public void readData(RowSetInternal caller) throws SQLException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        Connection con = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            CachedRowSet crs = (CachedRowSet)caller;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            // Get rid of the current contents of the rowset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
             * Checking added to verify whether page size has been set or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
             * If set then do not close the object as certain parameters need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
             * to be maintained.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            if(crs.getPageSize() == 0 && crs.size() >0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
               // When page size is not set,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
               // crs.size() will show the total no of rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
               crs.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            writerCalls = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            // Get a connection.  This reader assumes that the necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            // properties have been set on the caller to let it supply a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            // connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            userCon = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            con = this.connect(caller);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            // Check our assumptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            if (con == null || crs.getCommand() == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                throw new SQLException(resBundle.handleGetObject("crsreader.connecterr").toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                con.setTransactionIsolation(crs.getTransactionIsolation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            // Use JDBC to read the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            PreparedStatement pstmt = con.prepareStatement(crs.getCommand());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            // Pass any input parameters to JDBC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            decodeParams(caller.getParams(), pstmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                pstmt.setMaxRows(crs.getMaxRows());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                pstmt.setMaxFieldSize(crs.getMaxFieldSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                pstmt.setEscapeProcessing(crs.getEscapeProcessing());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                pstmt.setQueryTimeout(crs.getQueryTimeout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                 * drivers may not support the above - esp. older
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                 * drivers being used by the bridge..
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                throw new SQLException(ex.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            if(crs.getCommand().toLowerCase().indexOf("select") != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                // can be (crs.getCommand()).indexOf("select")) == 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                // because we will be getting resultset when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                // it may be the case that some false select query with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                // select coming in between instead of first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                // if ((crs.getCommand()).indexOf("?")) does not return -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                // implies a Prepared Statement like query exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                ResultSet rs = pstmt.executeQuery();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
               if(crs.getPageSize() == 0){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                      crs.populate(rs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
               else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                       /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                        * If page size has been set then create a ResultSet object that is scrollable using a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                        * PreparedStatement handle.Also call the populate(ResultSet,int) function to populate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                        * a page of data as specified by the page size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                       pstmt = con.prepareStatement(crs.getCommand(),ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                       decodeParams(caller.getParams(), pstmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                       try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                               pstmt.setMaxRows(crs.getMaxRows());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                               pstmt.setMaxFieldSize(crs.getMaxFieldSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                               pstmt.setEscapeProcessing(crs.getEscapeProcessing());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                               pstmt.setQueryTimeout(crs.getQueryTimeout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                           } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                          /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                           * drivers may not support the above - esp. older
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                           * drivers being used by the bridge..
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                           */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                            throw new SQLException(ex.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                       rs = pstmt.executeQuery();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                       crs.populate(rs,startPosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                rs.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            } else  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                pstmt.executeUpdate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            // Get the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            pstmt.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                con.commit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            } catch (SQLException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            // only close connections we created...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            if (getCloseConnection() == true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                con.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        catch (SQLException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            // Throw an exception if reading fails for any reason.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            throw ex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                // only close connections we created...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                if (con != null && getCloseConnection() == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                        if (!con.getAutoCommit()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                            con.rollback();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                    } catch (Exception dummy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                         * not an error condition, we're closing anyway, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                         * we'd like to clean up any locks if we can since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                         * it is not clear the connection pool will clean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                         * these connections in a timely manner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                    con.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                    con = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            } catch (SQLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                // will get exception if something already went wrong, but don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                // override that exception with this one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * Checks to see if the writer associated with this reader needs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * to reset its state.  The writer will need to initialize its state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * if new contents have been read since the writer was last called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * This method is called by the writer that was registered with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * this reader when components were being wired together.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @return <code>true</code> if writer associated with this reader needs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *         to reset the values of its fields; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @throws SQLException if an access error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    public boolean reset() throws SQLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        writerCalls++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        return writerCalls == 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * Establishes a connection with the data source for the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * <code>RowSet</code> object.  If the rowset's <code>dataSourceName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * property has been set, this method uses the JNDI API to retrieve the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * <code>DataSource</code> object that it can use to make the connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * If the url, username, and password properties have been set, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * method uses the <code>DriverManager.getConnection</code> method to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * make the connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * This method is used internally by the reader and writer associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * the calling <code>RowSet</code> object; an application never calls it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * @param caller a <code>RowSet</code> object that has implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *               the <code>RowSetInternal</code> interface and had
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *               this <code>CachedRowSetReader</code> object set as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *               its reader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @return a <code>Connection</code> object that represents a connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *         to the caller's data source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @throws SQLException if an access error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    public Connection connect(RowSetInternal caller) throws SQLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        // Get a JDBC connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        if (caller.getConnection() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            // A connection was passed to execute(), so use it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            // As we are using a connection the user gave us we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            // won't close it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            userCon = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            return caller.getConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        else if (((RowSet)caller).getDataSourceName() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            // Connect using JNDI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                Context ctx = new InitialContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                DataSource ds = (DataSource)ctx.lookup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                    (((RowSet)caller).getDataSourceName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                // Check for username, password,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                // if it exists try getting a Connection handle through them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                // else try without these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                // else throw SQLException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                if(((RowSet)caller).getUsername() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                     return ds.getConnection(((RowSet)caller).getUsername(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                                            ((RowSet)caller).getPassword());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                     return ds.getConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            catch (javax.naming.NamingException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                SQLException sqlEx = new SQLException(resBundle.handleGetObject("crsreader.connect").toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                sqlEx.initCause(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                throw sqlEx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        } else if (((RowSet)caller).getUrl() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            // Connect using the driver manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            return DriverManager.getConnection(((RowSet)caller).getUrl(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                                               ((RowSet)caller).getUsername(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                                               ((RowSet)caller).getPassword());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * Sets the parameter placeholders
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * in the rowset's command (the given <code>PreparedStatement</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * object) with the parameters in the given array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * This method, called internally by the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * <code>CachedRowSetReader.readData</code>, reads each parameter, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * based on its type, determines the correct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * <code>PreparedStatement.setXXX</code> method to use for setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * that parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @param params an array of parameters to be used with the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     *               <code>PreparedStatement</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @param pstmt  the <code>PreparedStatement</code> object that is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *               command for the calling rowset and into which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *               the given parameters are to be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @throws SQLException if an access error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     */
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 6530
diff changeset
   366
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    private void decodeParams(Object[] params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                              PreparedStatement pstmt) throws SQLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    // There is a corresponding decodeParams in JdbcRowSetImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    // which does the same as this method. This is a design flaw.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    // Update the JdbcRowSetImpl.decodeParams when you update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    // this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    // Adding the same comments to JdbcRowSetImpl.decodeParams.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        int arraySize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        Object[] param = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        for (int i=0; i < params.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            if (params[i] instanceof Object[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                param = (Object[])params[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                if (param.length == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                    if (param[0] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                        pstmt.setNull(i + 1, ((Integer)param[1]).intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                    if (param[0] instanceof java.sql.Date ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                        param[0] instanceof java.sql.Time ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                        param[0] instanceof java.sql.Timestamp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                        System.err.println(resBundle.handleGetObject("crsreader.datedetected").toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                        if (param[1] instanceof java.util.Calendar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                            System.err.println(resBundle.handleGetObject("crsreader.caldetected").toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                            pstmt.setDate(i + 1, (java.sql.Date)param[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                                       (java.util.Calendar)param[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                            throw new SQLException(resBundle.handleGetObject("crsreader.paramtype").toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                    if (param[0] instanceof Reader) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                        pstmt.setCharacterStream(i + 1, (Reader)param[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                                              ((Integer)param[1]).intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                     * What's left should be setObject(int, Object, scale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                    if (param[1] instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                        pstmt.setObject(i + 1, param[0], ((Integer)param[1]).intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                } else if (param.length == 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                    if (param[0] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                        pstmt.setNull(i + 1, ((Integer)param[1]).intValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                                   (String)param[2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                    if (param[0] instanceof java.io.InputStream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                        switch (((Integer)param[2]).intValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                        case CachedRowSetImpl.UNICODE_STREAM_PARAM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                            pstmt.setUnicodeStream(i + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                                                (java.io.InputStream)param[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                                                ((Integer)param[1]).intValue());
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 6530
diff changeset
   432
                            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                        case CachedRowSetImpl.BINARY_STREAM_PARAM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                            pstmt.setBinaryStream(i + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                                               (java.io.InputStream)param[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                                               ((Integer)param[1]).intValue());
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 6530
diff changeset
   437
                            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                        case CachedRowSetImpl.ASCII_STREAM_PARAM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                            pstmt.setAsciiStream(i + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                                              (java.io.InputStream)param[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                                              ((Integer)param[1]).intValue());
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 6530
diff changeset
   442
                            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                            throw new SQLException(resBundle.handleGetObject("crsreader.paramtype").toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                     * no point at looking at the first element now;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                     * what's left must be the setObject() cases.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                    if (param[1] instanceof Integer && param[2] instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                        pstmt.setObject(i + 1, param[0], ((Integer)param[1]).intValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                                     ((Integer)param[2]).intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                    throw new SQLException(resBundle.handleGetObject("crsreader.paramtype").toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    // common case - this catches all SQL92 types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                    pstmt.setObject(i + 1, params[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            }  else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
               // Try to get all the params to be set here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
               pstmt.setObject(i + 1, params[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * Assists in determining whether the current connection was created by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * CachedRowSet to ensure incorrect connections are not prematurely terminated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * @return a boolean giving the status of whether the connection has been closed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    protected boolean getCloseConnection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        if (userCon == true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     *  This sets the start position in the ResultSet from where to begin. This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * called by the Reader in the CachedRowSetImpl to set the position on the page
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * to begin populating from.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * @param pos integer indicating the position in the <code>ResultSet</code> to begin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     *        populating from.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    public void setStartPosition(int pos){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        startPosition = pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
6530
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   497
    private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   498
        // Default state initialization happens here
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   499
        ois.defaultReadObject();
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   500
        // Initialization of  Res Bundle happens here .
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   501
        try {
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   502
           resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   503
        } catch(IOException ioe) {
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   504
            throw new RuntimeException(ioe);
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   505
        }
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   506
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   507
    }
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   508
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   509
    static final long serialVersionUID =5049738185801363801L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
}