Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/sql/rowset/spi/SyncProvider.java
38918 views
/*1* Copyright (c) 2003, 2013, 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* <h3>1.0 Naming Convention for Implementations</h3>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* A vendor can register a <code>SyncProvider</code> implementation class name93* with Oracle Corporation by sending email to [email protected].94* Oracle will maintain a database listing the95* available <code>SyncProvider</code> implementations for use with compliant96* <code>RowSet</code> implementations. This database will be similar to the97* one already maintained to list available JDBC drivers.98* <P>99* Vendors should refer to the reference implementation synchronization100* providers for additional guidance on how to implement a new101* <code>SyncProvider</code> implementation.102*103* <h3>2.0 How a <code>RowSet</code> Object Gets Its Provider</h3>104*105* A disconnected <code>Rowset</code> object may get access to a106* <code>SyncProvider</code> object in one of the following two ways:107* <UL>108* <LI>Using a constructor<BR>109* <PRE>110* CachedRowSet crs = new CachedRowSet(111* "com.fred.providers.HighAvailabilitySyncProvider");112* </PRE>113* <LI>Using the <code>setSyncProvider</code> method114* <PRE>115* CachedRowSet crs = new CachedRowSet();116* crs.setSyncProvider("com.fred.providers.HighAvailabilitySyncProvider");117* </PRE>118119* </UL>120* <p>121* By default, the reference implementations of the <code>RowSet</code> synchronization122* providers are always available to the Java platform.123* If no other pluggable synchronization providers have been correctly124* registered, the <code>SyncFactory</code> will automatically generate125* an instance of the default <code>SyncProvider</code> reference implementation.126* Thus, in the preceding code fragment, if no implementation named127* <code>com.fred.providers.HighAvailabilitySyncProvider</code> has been128* registered with the <code>SyncFactory</code> instance, <i>crs</i> will be129* assigned the default provider in the reference implementation, which is130* <code>com.sun.rowset.providers.RIOptimisticProvider</code>.131*132* <h3>3.0 Violations and Synchronization Issues</h3>133* If an update between a disconnected <code>RowSet</code> object134* and a data source violates135* the original query or the underlying data source constraints, this will136* result in undefined behavior for all disconnected <code>RowSet</code> implementations137* and their designated <code>SyncProvider</code> implementations.138* Not defining the behavior when such violations occur offers greater flexibility139* for a <code>SyncProvider</code>140* implementation to determine its own best course of action.141* <p>142* A <code>SyncProvider</code> implementation143* may choose to implement a specific handler to144* handle a subset of query violations.145* However if an original query violation or a more general data source constraint146* violation is not handled by the <code>SyncProvider</code> implementation,147* all <code>SyncProvider</code>148* objects must throw a <code>SyncProviderException</code>.149*150* <h3>4.0 Updatable SQL VIEWs</h3>151* It is possible for any disconnected or connected <code>RowSet</code> object to be populated152* from an SQL query that is formulated originally from an SQL <code>VIEW</code>.153* While in many cases it is possible for an update to be performed to an154* underlying view, such an update requires additional metadata, which may vary.155* The <code>SyncProvider</code> class provides two constants to indicate whether156* an implementation supports updating an SQL <code>VIEW</code>.157* <ul>158* <li><code><b>NONUPDATABLE_VIEW_SYNC</b></code> - Indicates that a <code>SyncProvider</code>159* implementation does not support synchronization with an SQL <code>VIEW</code> as the160* underlying source of data for the <code>RowSet</code> object.161* <li><code><b>UPDATABLE_VIEW_SYNC</b></code> - Indicates that a162* <code>SyncProvider</code> implementation163* supports synchronization with an SQL <code>VIEW</code> as the underlying source164* of data.165* </ul>166* <P>167* The default is for a <code>RowSet</code> object not to be updatable if it was168* populated with data from an SQL <code>VIEW</code>.169*170* <h3>5.0 <code>SyncProvider</code> Constants</h3>171* The <code>SyncProvider</code> class provides three sets of constants that172* are used as return values or parameters for <code>SyncProvider</code> methods.173* <code>SyncProvider</code> objects may be implemented to perform synchronization174* between a <code>RowSet</code> object and its underlying data source with varying175* degrees of of care. The first group of constants indicate how synchronization176* is handled. For example, <code>GRADE_NONE</code> indicates that a177* <code>SyncProvider</code> object will not take any care to see what data is178* valid and will simply write the <code>RowSet</code> data to the data source.179* <code>GRADE_MODIFIED_AT_COMMIT</code> indicates that the provider will check180* only modified data for validity. Other grades check all data for validity181* or set locks when data is modified or loaded.182* <OL>183* <LI>Constants to indicate the synchronization grade of a184* <code>SyncProvider</code> object185* <UL>186* <LI>SyncProvider.GRADE_NONE187* <LI>SyncProvider.GRADE_MODIFIED_AT_COMMIT188* <LI>SyncProvider.GRADE_CHECK_ALL_AT_COMMIT189* <LI>SyncProvider.GRADE_LOCK_WHEN_MODIFIED190* <LI>SyncProvider.GRADE_LOCK_WHEN_LOADED191* </UL>192* <LI>Constants to indicate what locks are set on the data source193* <UL>194* <LI>SyncProvider.DATASOURCE_NO_LOCK195* <LI>SyncProvider.DATASOURCE_ROW_LOCK196* <LI>SyncProvider.DATASOURCE_TABLE_LOCK197* <LI>SyncProvider.DATASOURCE_DB_LOCK198* </UL>199* <LI>Constants to indicate whether a <code>SyncProvider</code> object can200* perform updates to an SQL <code>VIEW</code> <BR>201* These constants are explained in the preceding section (4.0).202* <UL>203* <LI>SyncProvider.UPDATABLE_VIEW_SYNC204* <LI>SyncProvider.NONUPDATABLE_VIEW_SYNC205* </UL>206* </OL>207*208* @author Jonathan Bruce209* @see javax.sql.rowset.spi.SyncFactory210* @see javax.sql.rowset.spi.SyncFactoryException211*/212public abstract class SyncProvider {213214/**215* Creates a default <code>SyncProvider</code> object.216*/217public SyncProvider() {218}219220/**221* Returns the unique identifier for this <code>SyncProvider</code> object.222*223* @return a <code>String</code> object with the fully qualified class name of224* this <code>SyncProvider</code> object225*/226public abstract String getProviderID();227228/**229* Returns a <code>javax.sql.RowSetReader</code> object, which can be used to230* populate a <code>RowSet</code> object with data.231*232* @return a <code>javax.sql.RowSetReader</code> object233*/234public abstract RowSetReader getRowSetReader();235236/**237* Returns a <code>javax.sql.RowSetWriter</code> object, which can be238* used to write a <code>RowSet</code> object's data back to the239* underlying data source.240*241* @return a <code>javax.sql.RowSetWriter</code> object242*/243public abstract RowSetWriter getRowSetWriter();244245/**246* Returns a constant indicating the247* grade of synchronization a <code>RowSet</code> object can expect from248* this <code>SyncProvider</code> object.249*250* @return an int that is one of the following constants:251* SyncProvider.GRADE_NONE,252* SyncProvider.GRADE_CHECK_MODIFIED_AT_COMMIT,253* SyncProvider.GRADE_CHECK_ALL_AT_COMMIT,254* SyncProvider.GRADE_LOCK_WHEN_MODIFIED,255* SyncProvider.GRADE_LOCK_WHEN_LOADED256*/257public abstract int getProviderGrade();258259260/**261* Sets a lock on the underlying data source at the level indicated by262* <i>datasource_lock</i>. This should cause the263* <code>SyncProvider</code> to adjust its behavior by increasing or264* decreasing the level of optimism it provides for a successful265* synchronization.266*267* @param datasource_lock one of the following constants indicating the severity268* level of data source lock required:269* <pre>270* SyncProvider.DATASOURCE_NO_LOCK,271* SyncProvider.DATASOURCE_ROW_LOCK,272* SyncProvider.DATASOURCE_TABLE_LOCK,273* SyncProvider.DATASOURCE_DB_LOCK,274* </pre>275* @throws SyncProviderException if an unsupported data source locking level276* is set.277* @see #getDataSourceLock278*/279public abstract void setDataSourceLock(int datasource_lock)280throws SyncProviderException;281282/**283* Returns the current data source lock severity level active in this284* <code>SyncProvider</code> implementation.285*286* @return a constant indicating the current level of data source lock287* active in this <code>SyncProvider</code> object;288* one of the following:289* <pre>290* SyncProvider.DATASOURCE_NO_LOCK,291* SyncProvider.DATASOURCE_ROW_LOCK,292* SyncProvider.DATASOURCE_TABLE_LOCK,293* SyncProvider.DATASOURCE_DB_LOCK294* </pre>295* @throws SyncProviderException if an error occurs determining the data296* source locking level.297* @see #setDataSourceLock298299*/300public abstract int getDataSourceLock()301throws SyncProviderException;302303/**304* Returns whether this <code>SyncProvider</code> implementation305* can perform synchronization between a <code>RowSet</code> object306* and the SQL <code>VIEW</code> in the data source from which307* the <code>RowSet</code> object got its data.308*309* @return an <code>int</code> saying whether this <code>SyncProvider</code>310* object supports updating an SQL <code>VIEW</code>; one of the311* following:312* SyncProvider.UPDATABLE_VIEW_SYNC,313* SyncProvider.NONUPDATABLE_VIEW_SYNC314*/315public abstract int supportsUpdatableView();316317/**318* Returns the release version of this <code>SyncProvider</code> instance.319*320* @return a <code>String</code> detailing the release version of the321* <code>SyncProvider</code> implementation322*/323public abstract String getVersion();324325/**326* Returns the vendor name of this <code>SyncProvider</code> instance327*328* @return a <code>String</code> detailing the vendor name of this329* <code>SyncProvider</code> implementation330*/331public abstract String getVendor();332333/*334* Standard description of synchronization grades that a SyncProvider335* could provide.336*/337338/**339* Indicates that no synchronization with the originating data source is340* provided. A <code>SyncProvider</code>341* implementation returning this grade will simply attempt to write342* updates in the <code>RowSet</code> object to the underlying data343* source without checking the validity of any data.344*345*/346public static final int GRADE_NONE = 1;347348/**349* Indicates a low level optimistic synchronization grade with350* respect to the originating data source.351*352* A <code>SyncProvider</code> implementation353* returning this grade will check only rows that have changed.354*355*/356public static final int GRADE_CHECK_MODIFIED_AT_COMMIT = 2;357358/**359* Indicates a high level optimistic synchronization grade with360* respect to the originating data source.361*362* A <code>SyncProvider</code> implementation363* returning this grade will check all rows, including rows that have not364* changed.365*/366public static final int GRADE_CHECK_ALL_AT_COMMIT = 3;367368/**369* Indicates a pessimistic synchronization grade with370* respect to the originating data source.371*372* A <code>SyncProvider</code>373* implementation returning this grade will lock the row in the originating374* data source.375*/376public static final int GRADE_LOCK_WHEN_MODIFIED = 4;377378/**379* Indicates the most pessimistic synchronization grade with380* respect to the originating381* data source. A <code>SyncProvider</code>382* implementation returning this grade will lock the entire view and/or383* table affected by the original statement used to populate a384* <code>RowSet</code> object.385*/386public static final int GRADE_LOCK_WHEN_LOADED = 5;387388/**389* Indicates that no locks remain on the originating data source. This is the default390* lock setting for all <code>SyncProvider</code> implementations unless391* otherwise directed by a <code>RowSet</code> object.392*/393public static final int DATASOURCE_NO_LOCK = 1;394395/**396* Indicates that a lock is placed on the rows that are touched by the original397* SQL statement used to populate the <code>RowSet</code> object398* that is using this <code>SyncProvider</code> object.399*/400public static final int DATASOURCE_ROW_LOCK = 2;401402/**403* Indicates that a lock is placed on all tables that are touched by the original404* SQL statement used to populate the <code>RowSet</code> object405* that is using this <code>SyncProvider</code> object.406*/407public static final int DATASOURCE_TABLE_LOCK = 3;408409/**410* Indicates that a lock is placed on the entire data source that is the source of411* data for the <code>RowSet</code> object412* that is using this <code>SyncProvider</code> object.413*/414public static final int DATASOURCE_DB_LOCK = 4;415416/**417* Indicates that a <code>SyncProvider</code> implementation418* supports synchronization between a <code>RowSet</code> object and419* the SQL <code>VIEW</code> used to populate it.420*/421public static final int UPDATABLE_VIEW_SYNC = 5;422423/**424* Indicates that a <code>SyncProvider</code> implementation425* does <B>not</B> support synchronization between a <code>RowSet</code>426* object and the SQL <code>VIEW</code> used to populate it.427*/428public static final int NONUPDATABLE_VIEW_SYNC = 6;429}430431432