Path: blob/master/src/java.sql.rowset/share/classes/javax/sql/rowset/spi/SyncProvider.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.spi;2627import javax.sql.*;2829/**30* The synchronization mechanism that provides reader/writer capabilities for31* disconnected <code>RowSet</code> objects.32* A <code>SyncProvider</code> implementation is a class that extends the33* <code>SyncProvider</code> abstract class.34* <P>35* A <code>SyncProvider</code> implementation is36* identified by a unique ID, which is its fully qualified class name.37* This name must be registered with the38* <code>SyncFactory</code> SPI, thus making the implementation available to39* all <code>RowSet</code> implementations.40* The factory mechanism in the reference implementation uses this name to instantiate41* the implementation, which can then provide a <code>RowSet</code> object with its42* reader (a <code>javax.sql.RowSetReader</code> object) and its writer (a43* <code>javax.sql.RowSetWriter</code> object).44* <P>45* The Jdbc <code>RowSet</code> Implementations specification provides two46* reference implementations of the <code>SyncProvider</code> abstract class:47* <code>RIOptimisticProvider</code> and <code>RIXMLProvider</code>.48* The <code>RIOptimisticProvider</code> can set any <code>RowSet</code>49* implementation with a <code>RowSetReader</code> object and a50* <code>RowSetWriter</code> object. However, only the <code>RIXMLProvider</code>51* implementation can set an <code>XmlReader</code> object and an52* <code>XmlWriter</code> object. A <code>WebRowSet</code> object uses the53* <code>XmlReader</code> object to read data in XML format to populate itself with that54* data. It uses the <code>XmlWriter</code> object to write itself to a stream or55* <code>java.io.Writer</code> object in XML format.56*57* <h2>1.0 Naming Convention for Implementations</h2>58* As a guide to naming <code>SyncProvider</code>59* implementations, the following should be noted:60* <UL>61* <li>The name for a <code>SyncProvider</code> implementation62* is its fully qualified class name.63* <li>It is recommended that vendors supply a64* <code>SyncProvider</code> implementation in a package named <code>providers</code>.65* </UL>66* <p>67* For instance, if a vendor named Fred, Inc. offered a68* <code>SyncProvider</code> implementation, you could have the following:69* <PRE>70* Vendor name: Fred, Inc.71* Domain name of vendor: com.fred72* Package name: com.fred.providers73* SyncProvider implementation class name: HighAvailabilityProvider74*75* Fully qualified class name of SyncProvider implementation:76* com.fred.providers.HighAvailabilityProvider77* </PRE>78* <P>79* The following line of code uses the fully qualified name to register80* this implementation with the <code>SyncFactory</code> static instance.81* <PRE>82* SyncFactory.registerProvider(83* "com.fred.providers.HighAvailabilityProvider");84* </PRE>85* <P>86* The default <code>SyncProvider</code> object provided with the reference87* implementation uses the following name:88* <pre>89* com.sun.rowset.providers.RIOptimisticProvider90* </pre>91* <p>92* Vendors should refer to the reference implementation synchronization93* providers for additional guidance on how to implement a new94* <code>SyncProvider</code> implementation.95*96* <h2>2.0 How a <code>RowSet</code> Object Gets Its Provider</h2>97*98* A disconnected <code>Rowset</code> object may get access to a99* <code>SyncProvider</code> object in one of the following two ways:100* <UL>101* <LI>Using a constructor<BR>102* <PRE>103* CachedRowSet crs = new CachedRowSet(104* "com.fred.providers.HighAvailabilitySyncProvider");105* </PRE>106* <LI>Using the <code>setSyncProvider</code> method107* <PRE>108* CachedRowSet crs = new CachedRowSet();109* crs.setSyncProvider("com.fred.providers.HighAvailabilitySyncProvider");110* </PRE>111112* </UL>113* <p>114* By default, the reference implementations of the <code>RowSet</code> synchronization115* providers are always available to the Java platform.116* If no other pluggable synchronization providers have been correctly117* registered, the <code>SyncFactory</code> will automatically generate118* an instance of the default <code>SyncProvider</code> reference implementation.119* Thus, in the preceding code fragment, if no implementation named120* <code>com.fred.providers.HighAvailabilitySyncProvider</code> has been121* registered with the <code>SyncFactory</code> instance, <i>crs</i> will be122* assigned the default provider in the reference implementation, which is123* <code>com.sun.rowset.providers.RIOptimisticProvider</code>.124*125* <h2>3.0 Violations and Synchronization Issues</h2>126* If an update between a disconnected <code>RowSet</code> object127* and a data source violates128* the original query or the underlying data source constraints, this will129* result in undefined behavior for all disconnected <code>RowSet</code> implementations130* and their designated <code>SyncProvider</code> implementations.131* Not defining the behavior when such violations occur offers greater flexibility132* for a <code>SyncProvider</code>133* implementation to determine its own best course of action.134* <p>135* A <code>SyncProvider</code> implementation136* may choose to implement a specific handler to137* handle a subset of query violations.138* However if an original query violation or a more general data source constraint139* violation is not handled by the <code>SyncProvider</code> implementation,140* all <code>SyncProvider</code>141* objects must throw a <code>SyncProviderException</code>.142*143* <h2>4.0 Updatable SQL VIEWs</h2>144* It is possible for any disconnected or connected <code>RowSet</code> object to be populated145* from an SQL query that is formulated originally from an SQL <code>VIEW</code>.146* While in many cases it is possible for an update to be performed to an147* underlying view, such an update requires additional metadata, which may vary.148* The <code>SyncProvider</code> class provides two constants to indicate whether149* an implementation supports updating an SQL <code>VIEW</code>.150* <ul>151* <li><code><b>NONUPDATABLE_VIEW_SYNC</b></code> - Indicates that a <code>SyncProvider</code>152* implementation does not support synchronization with an SQL <code>VIEW</code> as the153* underlying source of data for the <code>RowSet</code> object.154* <li><code><b>UPDATABLE_VIEW_SYNC</b></code> - Indicates that a155* <code>SyncProvider</code> implementation156* supports synchronization with an SQL <code>VIEW</code> as the underlying source157* of data.158* </ul>159* <P>160* The default is for a <code>RowSet</code> object not to be updatable if it was161* populated with data from an SQL <code>VIEW</code>.162*163* <h2>5.0 <code>SyncProvider</code> Constants</h2>164* The <code>SyncProvider</code> class provides three sets of constants that165* are used as return values or parameters for <code>SyncProvider</code> methods.166* <code>SyncProvider</code> objects may be implemented to perform synchronization167* between a <code>RowSet</code> object and its underlying data source with varying168* degrees of care. The first group of constants indicate how synchronization169* is handled. For example, <code>GRADE_NONE</code> indicates that a170* <code>SyncProvider</code> object will not take any care to see what data is171* valid and will simply write the <code>RowSet</code> data to the data source.172* <code>GRADE_MODIFIED_AT_COMMIT</code> indicates that the provider will check173* only modified data for validity. Other grades check all data for validity174* or set locks when data is modified or loaded.175* <OL>176* <LI>Constants to indicate the synchronization grade of a177* <code>SyncProvider</code> object178* <UL>179* <LI>SyncProvider.GRADE_NONE180* <LI>SyncProvider.GRADE_MODIFIED_AT_COMMIT181* <LI>SyncProvider.GRADE_CHECK_ALL_AT_COMMIT182* <LI>SyncProvider.GRADE_LOCK_WHEN_MODIFIED183* <LI>SyncProvider.GRADE_LOCK_WHEN_LOADED184* </UL>185* <LI>Constants to indicate what locks are set on the data source186* <UL>187* <LI>SyncProvider.DATASOURCE_NO_LOCK188* <LI>SyncProvider.DATASOURCE_ROW_LOCK189* <LI>SyncProvider.DATASOURCE_TABLE_LOCK190* <LI>SyncProvider.DATASOURCE_DB_LOCK191* </UL>192* <LI>Constants to indicate whether a <code>SyncProvider</code> object can193* perform updates to an SQL <code>VIEW</code> <BR>194* These constants are explained in the preceding section (4.0).195* <UL>196* <LI>SyncProvider.UPDATABLE_VIEW_SYNC197* <LI>SyncProvider.NONUPDATABLE_VIEW_SYNC198* </UL>199* </OL>200*201* @author Jonathan Bruce202* @see javax.sql.rowset.spi.SyncFactory203* @see javax.sql.rowset.spi.SyncFactoryException204* @since 1.5205*/206public abstract class SyncProvider {207208/**209* Creates a default <code>SyncProvider</code> object.210*/211public SyncProvider() {212}213214/**215* Returns the unique identifier for this <code>SyncProvider</code> object.216*217* @return a <code>String</code> object with the fully qualified class name of218* this <code>SyncProvider</code> object219*/220public abstract String getProviderID();221222/**223* Returns a <code>javax.sql.RowSetReader</code> object, which can be used to224* populate a <code>RowSet</code> object with data.225*226* @return a <code>javax.sql.RowSetReader</code> object227*/228public abstract RowSetReader getRowSetReader();229230/**231* Returns a <code>javax.sql.RowSetWriter</code> object, which can be232* used to write a <code>RowSet</code> object's data back to the233* underlying data source.234*235* @return a <code>javax.sql.RowSetWriter</code> object236*/237public abstract RowSetWriter getRowSetWriter();238239/**240* Returns a constant indicating the241* grade of synchronization a <code>RowSet</code> object can expect from242* this <code>SyncProvider</code> object.243*244* @return an int that is one of the following constants:245* SyncProvider.GRADE_NONE,246* SyncProvider.GRADE_CHECK_MODIFIED_AT_COMMIT,247* SyncProvider.GRADE_CHECK_ALL_AT_COMMIT,248* SyncProvider.GRADE_LOCK_WHEN_MODIFIED,249* SyncProvider.GRADE_LOCK_WHEN_LOADED250*/251public abstract int getProviderGrade();252253254/**255* Sets a lock on the underlying data source at the level indicated by256* <i>datasource_lock</i>. This should cause the257* <code>SyncProvider</code> to adjust its behavior by increasing or258* decreasing the level of optimism it provides for a successful259* synchronization.260*261* @param datasource_lock one of the following constants indicating the severity262* level of data source lock required:263* <pre>264* SyncProvider.DATASOURCE_NO_LOCK,265* SyncProvider.DATASOURCE_ROW_LOCK,266* SyncProvider.DATASOURCE_TABLE_LOCK,267* SyncProvider.DATASOURCE_DB_LOCK,268* </pre>269* @throws SyncProviderException if an unsupported data source locking level270* is set.271* @see #getDataSourceLock272*/273public abstract void setDataSourceLock(int datasource_lock)274throws SyncProviderException;275276/**277* Returns the current data source lock severity level active in this278* <code>SyncProvider</code> implementation.279*280* @return a constant indicating the current level of data source lock281* active in this <code>SyncProvider</code> object;282* one of the following:283* <pre>284* SyncProvider.DATASOURCE_NO_LOCK,285* SyncProvider.DATASOURCE_ROW_LOCK,286* SyncProvider.DATASOURCE_TABLE_LOCK,287* SyncProvider.DATASOURCE_DB_LOCK288* </pre>289* @throws SyncProviderException if an error occurs determining the data290* source locking level.291* @see #setDataSourceLock292293*/294public abstract int getDataSourceLock()295throws SyncProviderException;296297/**298* Returns whether this <code>SyncProvider</code> implementation299* can perform synchronization between a <code>RowSet</code> object300* and the SQL <code>VIEW</code> in the data source from which301* the <code>RowSet</code> object got its data.302*303* @return an <code>int</code> saying whether this <code>SyncProvider</code>304* object supports updating an SQL <code>VIEW</code>; one of the305* following:306* SyncProvider.UPDATABLE_VIEW_SYNC,307* SyncProvider.NONUPDATABLE_VIEW_SYNC308*/309public abstract int supportsUpdatableView();310311/**312* Returns the release version of this <code>SyncProvider</code> instance.313*314* @return a <code>String</code> detailing the release version of the315* <code>SyncProvider</code> implementation316*/317public abstract String getVersion();318319/**320* Returns the vendor name of this <code>SyncProvider</code> instance321*322* @return a <code>String</code> detailing the vendor name of this323* <code>SyncProvider</code> implementation324*/325public abstract String getVendor();326327/*328* Standard description of synchronization grades that a SyncProvider329* could provide.330*/331332/**333* Indicates that no synchronization with the originating data source is334* provided. A <code>SyncProvider</code>335* implementation returning this grade will simply attempt to write336* updates in the <code>RowSet</code> object to the underlying data337* source without checking the validity of any data.338*339*/340public static final int GRADE_NONE = 1;341342/**343* Indicates a low level optimistic synchronization grade with344* respect to the originating data source.345*346* A <code>SyncProvider</code> implementation347* returning this grade will check only rows that have changed.348*349*/350public static final int GRADE_CHECK_MODIFIED_AT_COMMIT = 2;351352/**353* Indicates a high level optimistic synchronization grade with354* respect to the originating data source.355*356* A <code>SyncProvider</code> implementation357* returning this grade will check all rows, including rows that have not358* changed.359*/360public static final int GRADE_CHECK_ALL_AT_COMMIT = 3;361362/**363* Indicates a pessimistic synchronization grade with364* respect to the originating data source.365*366* A <code>SyncProvider</code>367* implementation returning this grade will lock the row in the originating368* data source.369*/370public static final int GRADE_LOCK_WHEN_MODIFIED = 4;371372/**373* Indicates the most pessimistic synchronization grade with374* respect to the originating375* data source. A <code>SyncProvider</code>376* implementation returning this grade will lock the entire view and/or377* table affected by the original statement used to populate a378* <code>RowSet</code> object.379*/380public static final int GRADE_LOCK_WHEN_LOADED = 5;381382/**383* Indicates that no locks remain on the originating data source. This is the default384* lock setting for all <code>SyncProvider</code> implementations unless385* otherwise directed by a <code>RowSet</code> object.386*/387public static final int DATASOURCE_NO_LOCK = 1;388389/**390* Indicates that a lock is placed on the rows that are touched by the original391* SQL statement used to populate the <code>RowSet</code> object392* that is using this <code>SyncProvider</code> object.393*/394public static final int DATASOURCE_ROW_LOCK = 2;395396/**397* Indicates that a lock is placed on all tables that are touched by the original398* SQL statement used to populate the <code>RowSet</code> object399* that is using this <code>SyncProvider</code> object.400*/401public static final int DATASOURCE_TABLE_LOCK = 3;402403/**404* Indicates that a lock is placed on the entire data source that is the source of405* data for the <code>RowSet</code> object406* that is using this <code>SyncProvider</code> object.407*/408public static final int DATASOURCE_DB_LOCK = 4;409410/**411* Indicates that a <code>SyncProvider</code> implementation412* supports synchronization between a <code>RowSet</code> object and413* the SQL <code>VIEW</code> used to populate it.414*/415public static final int UPDATABLE_VIEW_SYNC = 5;416417/**418* Indicates that a <code>SyncProvider</code> implementation419* does <B>not</B> support synchronization between a <code>RowSet</code>420* object and the SQL <code>VIEW</code> used to populate it.421*/422public static final int NONUPDATABLE_VIEW_SYNC = 6;423}424425426