src/java.sql.rowset/share/classes/com/sun/rowset/internal/InsertRow.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 25859 jdk/src/java.sql.rowset/share/classes/com/sun/rowset/internal/InsertRow.java@3317bb8137f4
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
6530
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
     2
 * Copyright (c) 2003, 2010, 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 com.sun.rowset.JdbcRowSetResourceBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.sql.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.sql.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * A class used internally to manage a <code>CachedRowSet</code> object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * insert row.  This class keeps track of the number of columns in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * insert row and which columns have had a value inserted.  It provides
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * methods for retrieving a column value, setting a column value, and finding
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * out whether the insert row is complete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class InsertRow extends BaseRow implements Serializable, Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * An internal <code>BitSet</code> object used to keep track of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * columns in this <code>InsertRow</code> object that have had a value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * inserted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private BitSet colsInserted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * The number of columns in this <code>InsertRow</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private int cols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private JdbcRowSetResourceBundle resBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * Creates an <code>InsertRow</code> object initialized with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * given number of columns, an array for keeping track of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * original values in this insert row, and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <code>BitSet</code> object with the same number of bits as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * there are columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * @param numCols an <code>int</code> indicating the number of columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *                in this <code>InsertRow</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public InsertRow(int numCols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        origVals = new Object[numCols];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        colsInserted = new BitSet(numCols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        cols = numCols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
           resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        } catch(IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            throw new RuntimeException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * Sets the bit in this <code>InsertRow</code> object's internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <code>BitSet</code> object that corresponds to the specified column
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * in this <code>InsertRow</code> object. Setting a bit indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * that a value has been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * @param col the number of the column to be marked as inserted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *            the first column is <code>1</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    protected void markColInserted(int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        colsInserted.set(col);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * Indicates whether this <code>InsertRow</code> object has a value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * for every column that cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * @param RowSetMD the <code>RowSetMetaData</code> object for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *                 <code>CachedRowSet</code> object that maintains this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *                 <code>InsertRow</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * @return <code>true</code> if this <code>InsertRow</code> object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *         complete; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * @throws SQLException if there is an error accessing data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public boolean isCompleteRow(RowSetMetaData RowSetMD) throws SQLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        for (int i = 0; i < cols; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            if (colsInserted.get(i) == false &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                RowSetMD.isNullable(i + 1) ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                ResultSetMetaData.columnNoNulls) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * Clears all the bits in the internal <code>BitSet</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * maintained by this <code>InsertRow</code> object.  Clearing all the bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * indicates that none of the columns have had a value inserted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public void initInsertRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        for (int i = 0; i < cols; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            colsInserted.clear(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * Retrieves the value of the designated column in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * <code>InsertRow</code> object.  If no value has been inserted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * into the designated column, this method throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * <code>SQLException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * @param idx the column number of the value to be retrieved;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 *            the first column is <code>1</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * @throws SQLException if no value has been inserted into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *                                   the designated column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public Object getColumnObject(int idx) throws SQLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if (colsInserted.get(idx - 1) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            throw new SQLException(resBundle.handleGetObject("insertrow.novalue").toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        return (origVals[idx - 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * Sets the element in this <code>InsertRow</code> object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * internal array of original values that corresponds to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * designated column with the given value.  If the third
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * argument is <code>true</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * which means that the cursor is on the insert row, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * <code>InsertRow</code> object's internal <code>BitSet</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * is set so that the bit corresponding to the column being set is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * turned on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * @param idx the number of the column in the insert row to be set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 *              the first column is <code>1</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * @param val the value to be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public void setColumnObject(int idx, Object val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        origVals[idx - 1] = val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        markColInserted(idx - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
6530
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   160
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   161
    /**
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   162
     * This method re populates the resBundle
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   163
     * during the deserialization process
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   164
     *
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   165
     */
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   166
    private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   167
        // Default state initialization happens here
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   168
        ois.defaultReadObject();
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   169
        // Initialization of transient Res Bundle happens here .
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   170
        try {
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   171
           resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   172
        } catch(IOException ioe) {
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   173
            throw new RuntimeException(ioe);
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   174
        }
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   175
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   176
    }
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   177
bfb7b294dd14 6680198: UnmarshalException caused by incompatible serialVersionUID
lancea
parents: 5506
diff changeset
   178
    static final long serialVersionUID = 1066099658102869344L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
}