0N/A/*
2741N/A * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.rowset.internal;
0N/A
0N/Aimport com.sun.rowset.JdbcRowSetResourceBundle;
0N/Aimport java.sql.*;
0N/Aimport javax.sql.*;
0N/Aimport java.io.*;
0N/Aimport java.util.*;
0N/A
0N/A/**
0N/A * A class used internally to manage a <code>CachedRowSet</code> object's
0N/A * insert row. This class keeps track of the number of columns in the
0N/A * insert row and which columns have had a value inserted. It provides
0N/A * methods for retrieving a column value, setting a column value, and finding
0N/A * out whether the insert row is complete.
0N/A */
0N/Apublic class InsertRow extends BaseRow implements Serializable, Cloneable {
0N/A
0N/A/**
0N/A * An internal <code>BitSet</code> object used to keep track of the
0N/A * columns in this <code>InsertRow</code> object that have had a value
0N/A * inserted.
0N/A */
0N/A private BitSet colsInserted;
0N/A
0N/A/**
0N/A * The number of columns in this <code>InsertRow</code> object.
0N/A */
0N/A private int cols;
0N/A
0N/A private JdbcRowSetResourceBundle resBundle;
0N/A
0N/A/**
0N/A * Creates an <code>InsertRow</code> object initialized with the
0N/A * given number of columns, an array for keeping track of the
0N/A * original values in this insert row, and a
0N/A * <code>BitSet</code> object with the same number of bits as
0N/A * there are columns.
0N/A *
0N/A * @param numCols an <code>int</code> indicating the number of columns
0N/A * in this <code>InsertRow</code> object
0N/A */
0N/A public InsertRow(int numCols) {
0N/A origVals = new Object[numCols];
0N/A colsInserted = new BitSet(numCols);
0N/A cols = numCols;
0N/A try {
0N/A resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();
0N/A } catch(IOException ioe) {
0N/A throw new RuntimeException(ioe);
0N/A }
0N/A }
0N/A
0N/A/**
0N/A * Sets the bit in this <code>InsertRow</code> object's internal
0N/A * <code>BitSet</code> object that corresponds to the specified column
0N/A * in this <code>InsertRow</code> object. Setting a bit indicates
0N/A * that a value has been set.
0N/A *
0N/A * @param col the number of the column to be marked as inserted;
0N/A * the first column is <code>1</code>
0N/A */
0N/A protected void markColInserted(int col) {
0N/A colsInserted.set(col);
0N/A }
0N/A
0N/A/**
0N/A * Indicates whether this <code>InsertRow</code> object has a value
0N/A * for every column that cannot be null.
0N/A * @param RowSetMD the <code>RowSetMetaData</code> object for the
0N/A * <code>CachedRowSet</code> object that maintains this
0N/A * <code>InsertRow</code> object
0N/A * @return <code>true</code> if this <code>InsertRow</code> object is
0N/A * complete; <code>false</code> otherwise
0N/A * @throws SQLException if there is an error accessing data
0N/A */
0N/A public boolean isCompleteRow(RowSetMetaData RowSetMD) throws SQLException {
0N/A for (int i = 0; i < cols; i++) {
0N/A if (colsInserted.get(i) == false &&
0N/A RowSetMD.isNullable(i + 1) ==
0N/A ResultSetMetaData.columnNoNulls) {
0N/A return false;
0N/A }
0N/A
0N/A }
0N/A return true;
0N/A }
0N/A
0N/A/**
0N/A * Clears all the bits in the internal <code>BitSet</code> object
0N/A * maintained by this <code>InsertRow</code> object. Clearing all the bits
0N/A * indicates that none of the columns have had a value inserted.
0N/A */
0N/A public void initInsertRow() {
0N/A for (int i = 0; i < cols; i++) {
0N/A colsInserted.clear(i);
0N/A }
0N/A }
0N/A
0N/A/**
0N/A * Retrieves the value of the designated column in this
0N/A * <code>InsertRow</code> object. If no value has been inserted
0N/A * into the designated column, this method throws an
0N/A * <code>SQLException</code>.
0N/A *
0N/A * @param idx the column number of the value to be retrieved;
0N/A * the first column is <code>1</code>
0N/A * @throws SQLException if no value has been inserted into
0N/A * the designated column
0N/A */
0N/A public Object getColumnObject(int idx) throws SQLException {
0N/A if (colsInserted.get(idx - 1) == false) {
0N/A throw new SQLException(resBundle.handleGetObject("insertrow.novalue").toString());
0N/A }
0N/A return (origVals[idx - 1]);
0N/A }
0N/A
0N/A/**
0N/A * Sets the element in this <code>InsertRow</code> object's
0N/A * internal array of original values that corresponds to the
0N/A * designated column with the given value. If the third
0N/A * argument is <code>true</code>,
0N/A * which means that the cursor is on the insert row, this
0N/A * <code>InsertRow</code> object's internal <code>BitSet</code> object
0N/A * is set so that the bit corresponding to the column being set is
0N/A * turned on.
0N/A *
0N/A * @param idx the number of the column in the insert row to be set;
0N/A * the first column is <code>1</code>
0N/A * @param val the value to be set
0N/A */
0N/A public void setColumnObject(int idx, Object val) {
0N/A origVals[idx - 1] = val;
0N/A markColInserted(idx - 1);
0N/A }
2741N/A
2741N/A /**
2741N/A * This method re populates the resBundle
2741N/A * during the deserialization process
2741N/A *
2741N/A */
2741N/A private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
2741N/A // Default state initialization happens here
2741N/A ois.defaultReadObject();
2741N/A // Initialization of transient Res Bundle happens here .
2741N/A try {
2741N/A resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();
2741N/A } catch(IOException ioe) {
2741N/A throw new RuntimeException(ioe);
2741N/A }
2741N/A
2741N/A }
2741N/A
2741N/A static final long serialVersionUID = 1066099658102869344L;
0N/A}