Path: blob/master/src/java.sql.rowset/share/classes/javax/sql/rowset/JdbcRowSet.java
40948 views
/*1* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.sql.rowset;2627import java.sql.*;28import javax.sql.*;29import javax.naming.*;30import java.io.*;31import java.math.*;32import java.io.*;3334/**35* The standard interface that all standard implementations of36* <code>JdbcRowSet</code> must implement.37*38* <h2>1.0 Overview</h2>39* A wrapper around a <code>ResultSet</code> object that makes it possible40* to use the result set as a JavaBeans41* component. Thus, a <code>JdbcRowSet</code> object can be one of the Beans that42* a tool makes available for composing an application. Because43* a <code>JdbcRowSet</code> is a connected rowset, that is, it continually44* maintains its connection to a database using a JDBC technology-enabled45* driver, it also effectively makes the driver a JavaBeans component.46* <P>47* Because it is always connected to its database, an instance of48* <code>JdbcRowSet</code>49* can simply take calls invoked on it and in turn call them on its50* <code>ResultSet</code> object. As a consequence, a result set can, for51* example, be a component in a Swing application.52* <P>53* Another advantage of a <code>JdbcRowSet</code> object is that it can be54* used to make a <code>ResultSet</code> object scrollable and updatable. All55* <code>RowSet</code> objects are by default scrollable and updatable. If56* the driver and database being used do not support scrolling and/or updating57* of result sets, an application can populate a <code>JdbcRowSet</code> object58* with the data of a <code>ResultSet</code> object and then operate on the59* <code>JdbcRowSet</code> object as if it were the <code>ResultSet</code>60* object.61*62* <h2>2.0 Creating a <code>JdbcRowSet</code> Object</h2>63* The reference implementation of the <code>JdbcRowSet</code> interface,64* <code>JdbcRowSetImpl</code>, provides an implementation of65* the default constructor. A new instance is initialized with66* default values, which can be set with new values as needed. A67* new instance is not really functional until its <code>execute</code>68* method is called. In general, this method does the following:69* <UL>70* <LI> establishes a connection with a database71* <LI> creates a <code>PreparedStatement</code> object and sets any of its72* placeholder parameters73* <LI> executes the statement to create a <code>ResultSet</code> object74* </UL>75* If the <code>execute</code> method is successful, it will set the76* appropriate private <code>JdbcRowSet</code> fields with the following:77* <UL>78* <LI> a <code>Connection</code> object -- the connection between the rowset79* and the database80* <LI> a <code>PreparedStatement</code> object -- the query that produces81* the result set82* <LI> a <code>ResultSet</code> object -- the result set that the rowset's83* command produced and that is being made, in effect, a JavaBeans84* component85* </UL>86* If these fields have not been set, meaning that the <code>execute</code>87* method has not executed successfully, no methods other than88* <code>execute</code> and <code>close</code> may be called on the89* rowset. All other public methods will throw an exception.90* <P>91* Before calling the <code>execute</code> method, however, the command92* and properties needed for establishing a connection must be set.93* The following code fragment creates a <code>JdbcRowSetImpl</code> object,94* sets the command and connection properties, sets the placeholder parameter,95* and then invokes the method <code>execute</code>.96* <PRE>97* JdbcRowSetImpl jrs = new JdbcRowSetImpl();98* jrs.setCommand("SELECT * FROM TITLES WHERE TYPE = ?");99* jrs.setURL("jdbc:myDriver:myAttribute");100* jrs.setUsername("cervantes");101* jrs.setPassword("sancho");102* jrs.setString(1, "BIOGRAPHY");103* jrs.execute();104* </PRE>105* The variable <code>jrs</code> now represents an instance of106* <code>JdbcRowSetImpl</code> that is a thin wrapper around the107* <code>ResultSet</code> object containing all the rows in the108* table <code>TITLES</code> where the type of book is biography.109* At this point, operations called on <code>jrs</code> will110* affect the rows in the result set, which is effectively a JavaBeans111* component.112* <P>113* The implementation of the <code>RowSet</code> method <code>execute</code> in the114* <code>JdbcRowSet</code> reference implementation differs from that in the115* <code>CachedRowSet</code>116* reference implementation to account for the different117* requirements of connected and disconnected <code>RowSet</code> objects.118*119* @author Jonathan Bruce120* @since 1.5121*/122123public interface JdbcRowSet extends RowSet, Joinable {124125/**126* Retrieves a <code>boolean</code> indicating whether rows marked127* for deletion appear in the set of current rows. If <code>true</code> is128* returned, deleted rows are visible with the current rows. If129* <code>false</code> is returned, rows are not visible with the set of130* current rows. The default value is <code>false</code>.131* <P>132* Standard rowset implementations may choose to restrict this behavior133* for security considerations or for certain deployment134* scenarios. The visibility of deleted rows is implementation-defined135* and does not represent standard behavior.136* <P>137* Note: Allowing deleted rows to remain visible complicates the behavior138* of some standard JDBC <code>RowSet</code> implementations methods.139* However, most rowset users can simply ignore this extra detail because140* only very specialized applications will likely want to take advantage of141* this feature.142*143* @return <code>true</code> if deleted rows are visible;144* <code>false</code> otherwise145* @exception SQLException if a rowset implementation is unable to146* to determine whether rows marked for deletion remain visible147* @see #setShowDeleted148*/149public boolean getShowDeleted() throws SQLException;150151/**152* Sets the property <code>showDeleted</code> to the given153* <code>boolean</code> value. This property determines whether154* rows marked for deletion continue to appear in the set of current rows.155* If the value is set to <code>true</code>, deleted rows are immediately156* visible with the set of current rows. If the value is set to157* <code>false</code>, the deleted rows are set as invisible with the158* current set of rows.159* <P>160* Standard rowset implementations may choose to restrict this behavior161* for security considerations or for certain deployment162* scenarios. This is left as implementation-defined and does not163* represent standard behavior.164*165* @param b <code>true</code> if deleted rows should be shown;166* <code>false</code> otherwise167* @exception SQLException if a rowset implementation is unable to168* to reset whether deleted rows should be visible169* @see #getShowDeleted170*/171public void setShowDeleted(boolean b) throws SQLException;172173/**174* Retrieves the first warning reported by calls on this <code>JdbcRowSet</code>175* object.176* If a second warning was reported on this <code>JdbcRowSet</code> object,177* it will be chained to the first warning and can be retrieved by178* calling the method <code>RowSetWarning.getNextWarning</code> on the179* first warning. Subsequent warnings on this <code>JdbcRowSet</code>180* object will be chained to the <code>RowSetWarning</code> objects181* returned by the method <code>RowSetWarning.getNextWarning</code>.182*183* The warning chain is automatically cleared each time a new row is read.184* This method may not be called on a <code>RowSet</code> object185* that has been closed;186* doing so will cause an <code>SQLException</code> to be thrown.187* <P>188* Because it is always connected to its data source, a <code>JdbcRowSet</code>189* object can rely on the presence of active190* <code>Statement</code>, <code>Connection</code>, and <code>ResultSet</code>191* instances. This means that applications can obtain additional192* <code>SQLWarning</code>193* notifications by calling the <code>getNextWarning</code> methods that194* they provide.195* Disconnected <code>Rowset</code> objects, such as a196* <code>CachedRowSet</code> object, do not have access to197* these <code>getNextWarning</code> methods.198*199* @return the first <code>RowSetWarning</code>200* object reported on this <code>JdbcRowSet</code> object201* or <code>null</code> if there are none202* @throws SQLException if this method is called on a closed203* <code>JdbcRowSet</code> object204* @see RowSetWarning205*/206public RowSetWarning getRowSetWarnings() throws SQLException;207208/**209* Each <code>JdbcRowSet</code> contains a <code>Connection</code> object from210* the <code>ResultSet</code> or JDBC properties passed to it's constructors.211* This method wraps the <code>Connection</code> commit method to allow flexible212* auto commit or non auto commit transactional control support.213* <p>214* Makes all changes made since the previous commit/rollback permanent215* and releases any database locks currently held by this Connection216* object. This method should be used only when auto-commit mode has217* been disabled.218*219* @throws SQLException if a database access error occurs or this220* Connection object within this <code>JdbcRowSet</code> is in auto-commit mode221* @see java.sql.Connection#setAutoCommit222*/223public void commit() throws SQLException;224225226/**227* Each <code>JdbcRowSet</code> contains a <code>Connection</code> object from228* the original <code>ResultSet</code> or JDBC properties passed to it. This229* method wraps the <code>Connection</code>'s <code>getAutoCommit</code> method230* to allow an application to determine the <code>JdbcRowSet</code> transaction231* behavior.232* <p>233* Sets this connection's auto-commit mode to the given state. If a234* connection is in auto-commit mode, then all its SQL statements will235* be executed and committed as individual transactions. Otherwise, its236* SQL statements are grouped into transactions that are terminated by a237* call to either the method commit or the method rollback. By default,238* new connections are in auto-commit mode.239*240* @return {@code true} if auto-commit is enabled; {@code false} otherwise241* @throws SQLException if a database access error occurs242* @see java.sql.Connection#getAutoCommit()243*/244public boolean getAutoCommit() throws SQLException;245246247/**248* Each <code>JdbcRowSet</code> contains a <code>Connection</code> object from249* the original <code>ResultSet</code> or JDBC properties passed to it. This250* method wraps the <code>Connection</code>'s <code>getAutoCommit</code> method251* to allow an application to set the <code>JdbcRowSet</code> transaction behavior.252* <p>253* Sets the current auto-commit mode for this <code>Connection</code> object.254* @param autoCommit {@code true} to enable auto-commit; {@code false} to255* disable auto-commit256* @throws SQLException if a database access error occurs257* @see java.sql.Connection#setAutoCommit(boolean)258*/259public void setAutoCommit(boolean autoCommit) throws SQLException;260261/**262* Each <code>JdbcRowSet</code> contains a <code>Connection</code> object from263* the original <code>ResultSet</code> or JDBC properties passed to it.264* Undoes all changes made in the current transaction and releases any265* database locks currently held by this <code>Connection</code> object. This method266* should be used only when auto-commit mode has been disabled.267*268* @throws SQLException if a database access error occurs or this <code>Connection</code>269* object within this <code>JdbcRowSet</code> is in auto-commit mode.270* @see #rollback(Savepoint)271*/272public void rollback() throws SQLException;273274275/**276* Each <code>JdbcRowSet</code> contains a <code>Connection</code> object from277* the original <code>ResultSet</code> or JDBC properties passed to it.278* Undoes all changes made in the current transaction to the last set savepoint279* and releases any database locks currently held by this <code>Connection</code>280* object. This method should be used only when auto-commit mode has been disabled.281* @param s The {@code Savepoint} to rollback to282* @throws SQLException if a database access error occurs or this <code>Connection</code>283* object within this <code>JdbcRowSet</code> is in auto-commit mode.284* @see #rollback285*/286public void rollback(Savepoint s) throws SQLException;287288}289290291