2740N/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 * 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 * 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 * 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. 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 0N/A * The synchronization mechanism that provides reader/writer capabilities for 0N/A * disconnected <code>RowSet</code> objects. 0N/A * A <code>SyncProvider</code> implementation is a class that extends the 0N/A * <code>SyncProvider</code> abstract class. 0N/A * A <code>SyncProvider</code> implementation is 0N/A * identified by a unique ID, which is its fully qualified class name. 0N/A * This name must be registered with the 0N/A * <code>SyncFactory</code> SPI, thus making the implementation available to 0N/A * all <code>RowSet</code> implementations. 0N/A * The factory mechanism in the reference implementation uses this name to instantiate 0N/A * the implementation, which can then provide a <code>RowSet</code> object with its 0N/A * reader (a <code>javax.sql.RowSetReader</code> object) and its writer (a 0N/A * <code>javax.sql.RowSetWriter</code> object). 0N/A * The Jdbc <code>RowSet</code> Implementations specification provides two 0N/A * reference implementations of the <code>SyncProvider</code> abstract class: 0N/A * <code>RIOptimisticProvider</code> and <code>RIXMLProvider</code>. 0N/A * The <code>RIOptimisticProvider</code> can set any <code>RowSet</code> 0N/A * implementation with a <code>RowSetReader</code> object and a 0N/A * <code>RowSetWriter</code> object. However, only the <code>RIXMLProvider</code> 0N/A * implementation can set an <code>XmlReader</code> object and an 0N/A * <code>XmlWriter</code> object. A <code>WebRowSet</code> object uses the 0N/A * <code>XmlReader</code> object to read data in XML format to populate itself with that 0N/A * data. It uses the <code>XmlWriter</code> object to write itself to a stream or 0N/A * <code>java.io.Writer</code> object in XML format. 0N/A * <h3>1.0 Naming Convention for Implementations</h3> 0N/A * As a guide to naming <code>SyncProvider</code> 0N/A * implementations, the following should be noted: 0N/A * <li>The name for a <code>SyncProvider</code> implementation 0N/A * is its fully qualified class name. 0N/A * <li>It is recommended that vendors supply a 0N/A * <code>SyncProvider</code> implementation in a package named <code>providers</code>. 0N/A * For instance, if a vendor named Fred, Inc. offered a 0N/A * <code>SyncProvider</code> implementation, you could have the following: 0N/A * Vendor name: Fred, Inc. 0N/A * Domain name of vendor: com.fred 0N/A * Package name: com.fred.providers 0N/A * SyncProvider implementation class name: HighAvailabilityProvider 0N/A * Fully qualified class name of SyncProvider implementation: 0N/A * com.fred.providers.HighAvailabilityProvider 0N/A * The following line of code uses the fully qualified name to register 0N/A * this implementation with the <code>SyncFactory</code> static instance. 0N/A * SyncFactory.registerProvider( 0N/A * "com.fred.providers.HighAvailabilityProvider"); 0N/A * The default <code>SyncProvider</code> object provided with the reference 0N/A * implementation uses the following name: 0N/A * com.sun.rowset.providers.RIOptimisticProvider 0N/A * A vendor can register a <code>SyncProvider</code> implementation class name 2802N/A * with Oracle Corporation by sending email to jdbc@sun.com. 2802N/A * Oracle will maintain a database listing the 0N/A * available <code>SyncProvider</code> implementations for use with compliant 0N/A * <code>RowSet</code> implementations. This database will be similar to the 0N/A * one already maintained to list available JDBC drivers. 0N/A * Vendors should refer to the reference implementation synchronization 0N/A * providers for additional guidance on how to implement a new 0N/A * <code>SyncProvider</code> implementation. 0N/A * <h3>2.0 How a <code>RowSet</code> Object Gets Its Provider</h3> 0N/A * A disconnected <code>Rowset</code> object may get access to a 0N/A * <code>SyncProvider</code> object in one of the following two ways: 0N/A * <LI>Using a constructor<BR> 0N/A * CachedRowSet crs = new CachedRowSet( 0N/A * "com.fred.providers.HighAvailabilitySyncProvider"); 0N/A * <LI>Using the <code>setSyncProvider</code> method 0N/A * CachedRowSet crs = new CachedRowSet(); 0N/A * crs.setSyncProvider("com.fred.providers.HighAvailabilitySyncProvider"); 0N/A * By default, the reference implementations of the <code>RowSet</code> synchronization 0N/A * providers are always available to the Java platform. 0N/A * If no other pluggable synchronization providers have been correctly 0N/A * registered, the <code>SyncFactory</code> will automatically generate 0N/A * an instance of the default <code>SyncProvider</code> reference implementation. 0N/A * Thus, in the preceding code fragment, if no implementation named 0N/A * <code>com.fred.providers.HighAvailabilitySyncProvider</code> has been 0N/A * registered with the <code>SyncFactory</code> instance, <i>crs</i> will be 0N/A * assigned the default provider in the reference implementation, which is 0N/A * <code>com.sun.rowset.providers.RIOptimisticProvider</code>. 0N/A * <h3>3.0 Violations and Synchronization Issues</h3> 0N/A * If an update between a disconnected <code>RowSet</code> object 0N/A * and a data source violates 0N/A * the original query or the underlying data source constraints, this will 0N/A * result in undefined behavior for all disconnected <code>RowSet</code> implementations 0N/A * and their designated <code>SyncProvider</code> implementations. 0N/A * Not defining the behavior when such violations occur offers greater flexibility 0N/A * for a <code>SyncProvider</code> 0N/A * implementation to determine its own best course of action. 0N/A * A <code>SyncProvider</code> implementation 0N/A * may choose to implement a specific handler to 0N/A * handle a subset of query violations. 0N/A * However if an original query violation or a more general data source constraint 0N/A * violation is not handled by the <code>SyncProvider</code> implementation, 0N/A * all <code>SyncProvider</code> 0N/A * objects must throw a <code>SyncProviderException</code>. 0N/A * <h3>4.0 Updatable SQL VIEWs</h3> 0N/A * It is possible for any disconnected or connected <code>RowSet</code> object to be populated 0N/A * from an SQL query that is formulated originally from an SQL <code>VIEW</code>. 0N/A * While in many cases it is possible for an update to be performed to an 0N/A * underlying view, such an update requires additional metadata, which may vary. 0N/A * The <code>SyncProvider</code> class provides two constants to indicate whether 0N/A * an implementation supports updating an SQL <code>VIEW</code>. 0N/A * <li><code><b>NONUPDATABLE_VIEW_SYNC</b></code> - Indicates that a <code>SyncProvider</code> 0N/A * implementation does not support synchronization with an SQL <code>VIEW</code> as the 0N/A * underlying source of data for the <code>RowSet</code> object. 0N/A * <li><code><b>UPDATABLE_VIEW_SYNC</b></code> - Indicates that a 0N/A * <code>SyncProvider</code> implementation 0N/A * supports synchronization with an SQL <code>VIEW</code> as the underlying source 0N/A * The default is for a <code>RowSet</code> object not to be updatable if it was 0N/A * populated with data from an SQL <code>VIEW</code>. 0N/A * <h3>5.0 <code>SyncProvider</code> Constants</h3> 0N/A * The <code>SyncProvider</code> class provides three sets of constants that 0N/A * are used as return values or parameters for <code>SyncProvider</code> methods. 0N/A * <code>SyncProvider</code> objects may be implemented to perform synchronization 0N/A * between a <code>RowSet</code> object and its underlying data source with varying 0N/A * degrees of of care. The first group of constants indicate how synchronization 0N/A * is handled. For example, <code>GRADE_NONE</code> indicates that a 0N/A * <code>SyncProvider</code> object will not take any care to see what data is 0N/A * valid and will simply write the <code>RowSet</code> data to the data source. 0N/A * <code>GRADE_MODIFIED_AT_COMMIT</code> indicates that the provider will check 0N/A * only modified data for validity. Other grades check all data for validity 0N/A * or set locks when data is modified or loaded. 0N/A * <LI>Constants to indicate the synchronization grade of a 0N/A * <code>SyncProvider</code> object 0N/A * <LI>SyncProvider.GRADE_NONE 0N/A * <LI>SyncProvider.GRADE_MODIFIED_AT_COMMIT 0N/A * <LI>SyncProvider.GRADE_CHECK_ALL_AT_COMMIT 0N/A * <LI>SyncProvider.GRADE_LOCK_WHEN_MODIFIED 0N/A * <LI>SyncProvider.GRADE_LOCK_WHEN_LOADED 0N/A * <LI>Constants to indicate what locks are set on the data source 0N/A * <LI>SyncProvider.DATASOURCE_NO_LOCK 0N/A * <LI>SyncProvider.DATASOURCE_ROW_LOCK 0N/A * <LI>SyncProvider.DATASOURCE_TABLE_LOCK 0N/A * <LI>SyncProvider.DATASOURCE_DB_LOCK 0N/A * <LI>Constants to indicate whether a <code>SyncProvider</code> object can 0N/A * perform updates to an SQL <code>VIEW</code> <BR> 0N/A * These constants are explained in the preceding section (4.0). 0N/A * <LI>SyncProvider.UPDATABLE_VIEW_SYNC 0N/A * <LI>SyncProvider.NONUPDATABLE_VIEW_SYNC 0N/A * @author Jonathan Bruce 0N/A * @see javax.sql.rowset.spi.SyncFactory 0N/A * @see javax.sql.rowset.spi.SyncFactoryException 0N/A * Creates a default <code>SyncProvider</code> object. 0N/A * Returns the unique identifier for this <code>SyncProvider</code> object. 0N/A * @return a <code>String</code> object with the fully qualified class name of 0N/A * this <code>SyncProvider</code> object 0N/A * Returns a <code>javax.sql.RowSetReader</code> object, which can be used to 0N/A * populate a <code>RowSet</code> object with data. 0N/A * @return a <code>javax.sql.RowSetReader</code> object 0N/A * Returns a <code>javax.sql.RowSetWriter</code> object, which can be 0N/A * used to write a <code>RowSet</code> object's data back to the 0N/A * underlying data source. 0N/A * @return a <code>javax.sql.RowSetWriter</code> object 0N/A * Returns a constant indicating the 0N/A * grade of synchronization a <code>RowSet</code> object can expect from 0N/A * this <code>SyncProvider</code> object. 0N/A * @return an int that is one of the following constants: 0N/A * SyncProvider.GRADE_NONE, 0N/A * SyncProvider.GRADE_CHECK_MODIFIED_AT_COMMIT, 0N/A * SyncProvider.GRADE_CHECK_ALL_AT_COMMIT, 0N/A * SyncProvider.GRADE_LOCK_WHEN_MODIFIED, 0N/A * SyncProvider.GRADE_LOCK_WHEN_LOADED 0N/A * Sets a lock on the underlying data source at the level indicated by 0N/A * <i>datasource_lock</i>. This should cause the 0N/A * <code>SyncProvider</code> to adjust its behavior by increasing or 0N/A * decreasing the level of optimism it provides for a successful 0N/A * @param datasource_lock one of the following constants indicating the severity 0N/A * level of data source lock required: 0N/A * SyncProvider.DATASOURCE_NO_LOCK, 0N/A * SyncProvider.DATASOURCE_ROW_LOCK, 0N/A * SyncProvider.DATASOURCE_TABLE_LOCK, 0N/A * SyncProvider.DATASOURCE_DB_LOCK, 0N/A * @throws SyncProviderException if an unsupported data source locking level 0N/A * @see #getDataSourceLock 0N/A * Returns the current data source lock severity level active in this 0N/A * <code>SyncProvider</code> implementation. 0N/A * @return a constant indicating the current level of data source lock 0N/A * active in this <code>SyncProvider</code> object; 0N/A * one of the following: 0N/A * SyncProvider.DATASOURCE_NO_LOCK, 0N/A * SyncProvider.DATASOURCE_ROW_LOCK, 0N/A * SyncProvider.DATASOURCE_TABLE_LOCK, 0N/A * SyncProvider.DATASOURCE_DB_LOCK 0N/A * @throws SyncProviderExceptiom if an error occurs determining the data 0N/A * source locking level. 0N/A * @see #setDataSourceLock 0N/A * Returns whether this <code>SyncProvider</code> implementation 0N/A * can perform synchronization between a <code>RowSet</code> object 0N/A * and the SQL <code>VIEW</code> in the data source from which 0N/A * the <code>RowSet</code> object got its data. 0N/A * @return an <code>int</code> saying whether this <code>SyncProvider</code> 0N/A * object supports updating an SQL <code>VIEW</code>; one of the 0N/A * SyncProvider.UPDATABLE_VIEW_SYNC, 0N/A * SyncProvider.NONUPDATABLE_VIEW_SYNC 0N/A * Returns the release version of this <code>SyncProvider</code> instance. 0N/A * @return a <code>String</code> detailing the release version of the 0N/A * <code>SyncProvider</code> implementation 0N/A * Returns the vendor name of this <code>SyncProvider</code> instance 0N/A * @return a <code>String</code> detailing the vendor name of this 0N/A * <code>SyncProvider</code> implementation 0N/A * Standard description of synchronization grades that a SyncProvider 0N/A * Indicates that no synchronization with the originating data source is 0N/A * provided. A <code>SyncProvider</code> 0N/A * implementation returning this grade will simply attempt to write 0N/A * updates in the <code>RowSet</code> object to the underlying data 0N/A * source without checking the validity of any data. 0N/A * Indicates a low level optimistic synchronization grade with 0N/A * respect to the originating data source. 0N/A * A <code>SyncProvider</code> implementation 0N/A * returning this grade will check only rows that have changed. 0N/A * Indicates a high level optimistic synchronization grade with 0N/A * respect to the originating data source. 0N/A * A <code>SyncProvider</code> implementation 0N/A * returning this grade will check all rows, including rows that have not 0N/A * Indicates a pessimistic synchronization grade with 0N/A * respect to the originating data source. 0N/A * A <code>SyncProvider</code> 0N/A * implementation returning this grade will lock the row in the originating 0N/A * Indicates the most pessimistic synchronization grade with 0N/A * respect to the originating 0N/A * data source. A <code>SyncProvider</code> 0N/A * implementation returning this grade will lock the entire view and/or 0N/A * table affected by the original statement used to populate a 0N/A * <code>RowSet</code> object. 0N/A * Indicates that no locks remain on the originating data source. This is the default 0N/A * lock setting for all <code>SyncProvider</code> implementations unless 0N/A * otherwise directed by a <code>RowSet</code> object. 0N/A * Indicates that a lock is placed on the rows that are touched by the original 0N/A * SQL statement used to populate the <code>RowSet</code> object 0N/A * that is using this <code>SyncProvider</code> object. 0N/A * Indicates that a lock is placed on all tables that are touched by the original 0N/A * SQL statement used to populate the <code>RowSet</code> object 0N/A * that is using this <code>SyncProvider</code> object. 0N/A * Indicates that a lock is placed on the entire data source that is the source of 0N/A * data for the <code>RowSet</code> object 0N/A * that is using this <code>SyncProvider</code> object. 0N/A * Indicates that a <code>SyncProvider</code> implementation 0N/A * supports synchronization between a <code>RowSet</code> object and 0N/A * the SQL <code>VIEW</code> used to populate it. 0N/A * Indicates that a <code>SyncProvider</code> implementation 0N/A * does <B>not</B> support synchronization between a <code>RowSet</code> 0N/A * object and the SQL <code>VIEW</code> used to populate it.