Path: blob/master/src/java.sql.rowset/share/classes/com/sun/rowset/providers/package-info.java
40948 views
/*1* Copyright (c) 2003, 2020, 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*/2425/**26*27* Repository for the {@code RowSet} reference implementations of the28* {@code SyncProvider} abstract class. These implementations provide a29* disconnected {@code RowSet}30* object with the ability to synchronize the data in the underlying data31* source with its data. These implementations are provided as32* the default {@code SyncProvider} implementations and are accessible via the33* {@code SyncProvider} SPI managed by the {@code SyncFactory}.34*35* <h2>1.0 {@code SyncProvider} Reference Implementations</h2>36* The main job of a {@code SyncProvider} implementation is to manage37* the reader and writer mechanisms.38* The {@code SyncProvider} SPI, as specified in the {@code javax.sql.rowset.spi}39* package, provides a pluggable mechanism by which {@code javax.sql.RowSetReader}40* and {@code javax.sql.RowSetWriter} implementations can be supplied to a disconnected41* {@code RowSet} object.42* <P>43* A reader, a {@code javax.sql.RowSetReader}44* object, does the work necessary to populate a {@code RowSet} object with data.45* A writer, a {@code javax.sql.RowSetWriter} object, does the work necessary for46* synchronizing a {@code RowSet} object's data with the data in the originating47* source of data. Put another way, a writer writes a {@code RowSet}48* object's data back to the data source.49* <P>50* Generally speaking, the course of events is this. The reader makes a connection to51* the data source and reads the data from a {@code ResultSet} object into its52* {@code RowSet} object. Then it closes the connection. While53* the {@code RowSet} object is disconnected, an application makes some modifications54* to the data and calls the method {@code acceptChanges}. At this point, the55* writer is called to write the changes back to the database table or view56* from which the original data came. This is called <i>synchronization</i>.57* <P>58* If the data in the originating data source has not changed, there is no problem59* with just writing the {@code RowSet} object's new data to the data source.60* If it has changed, however, there is a conflict that needs to be resolved. One61* way to solve the problem is not to let the data in the data source be changed in62* the first place, which can be done by setting locks on a row, a table, or the63* whole data source. Setting locks is a way to avoid conflicts, but it can be64* very expensive. Another approach, which is at the other end of the spectrum,65* is simply to assume that no conflicts will occur and thus do nothing to avoid66* conflicts.67* Different {@code SyncProvider} implementations may handle synchronization in68* any of these ways, varying from doing no checking for69* conflicts, to doing various levels of checking, to guaranteeing that there are no70* conflicts.71* <P>72* The {@code SyncProvider} class offers methods to help a {@code RowSet}73* object discover and manage how a provider handles synchronization.74* The method {@code getProviderGrade} returns the75* grade of synchronization a provider offers. An application can76* direct the provider to use a particular level of locking by calling77* the method {@code setDataSourceLock} and specifying the level of locking desired.78* If a {@code RowSet} object's data came from an SQL {@code VIEW}, an79* application may call the method {@code supportsUpdatableView} to80* find out whether the {@code VIEW} can be updated.81* <P>82* Synchronization is done completely behind the scenes, so it is third party vendors of83* synchronization provider implementations who have to take care of this complex task.84* Application programmers can decide which provider to use and the level of locking to85* be done, but they are free from having to worry about the implementation details.86* <P>87* The JDBC {@code RowSet} Implementations reference implementation provides two88* implementations of the {@code SyncProvider} class:89*90* <UL>91* <LI>92* <b>{@code RIOptimisticProvider}</b> - provides the {@code javax.sql.RowSetReader}93* and {@code javax.sql.RowSetWriter} interface implementations and provides94* an optimistic concurrency model for synchronization. This model assumes that there95* will be few conflicts and therefore uses a relatively low grade of synchronization.96* If no other provider is available, this is the default provider that the97* {@code SyncFactory} will supply to a {@code RowSet} object.98* <br>99* <LI>100* <b>{@code RIXMLProvider}</b> - provides the {@code XmlReader} (an extension101* of the {@code javax.sql.RowSetReader} interface) and the {@code XmlWriter}102* (an extension of the {@code javax.sql.RowSetWriter} interface) to enable103* {@code WebRowSet} objects to write their state to a104* well formed XML document according to the {@code WebRowSet} XML schema105* definition.<br>106* </UL>107*108* <h2>2.0 Basics in RowSet Population & Synchronization</h2>109* A rowset's first task is to populate itself with rows of column values.110* Generally, these rows will come from a relational database, so a rowset111* has properties that supply what is necessary for making a connection to112* a database and executing a query. A rowset that does not need to establish113* a connection and execute a command, such as one that gets its data from114* a tabular file instead of a relational database, does not need to have these115* properties set. The vast majority of RowSets, however, do need to set these116* properties. The general rule is that a RowSet is required to set only the117* properties that it uses.<br>118* <br>119* The {@code command} property contains the query that determines what120* data a {@code RowSet} will contain. Rowsets have methods for setting a query's121* parameter(s), which means that a query can be executed multiple times with122* different parameters to produce different result sets. Or the query can be123* changed to something completely new to get a new result set.124* <p>Once a rowset contains the rows from a {@code ResultSet} object or some125* other data source, its column values can be updated, and its rows can be126* inserted or deleted. Any method that causes a change in the rowset's values127* or cursor position also notifies any object that has been registered as128* a listener with the rowset. So, for example, a table that displays the rowset's129* data in an applet can be notified of changes and make updates as they130* occur.<br>131* <br>132* The changes made to a rowset can be propagated back to the original data133* source to keep the rowset and its data source synchronized. Although this134* involves many operations behind the scenes, it is completely transparent135* to the application programmer and remains the concern of the RowSet provider136* developer. All an application has to do is invoke the method {@code acceptChanges},137* and the data source backing the rowset will be updated to match the current138* values in the rowset. </p>139*140* <p>A disconnected rowset, such as a {@code CachedRowSet} or {@code WebRowSet}141* object, establishes a connection to populate itself with data from a database142* and then closes the connection. The {@code RowSet} object will remain143* disconnected until it wants to propagate changes back to its database table,144* which is optional. To write its changes back to the database (synchronize with145* the database), the rowset establishes a connection, write the changes, and then146* once again disconnects itself.<br>147* </p>148*149* <h2> 3.0 Other Possible Implementations</h2>150* There are many other possible implementations of the {@code SyncProvider} abstract151* class. One possibility is to employ a more robust synchronization model, which152* would give a {@code RowSet} object increased trust in the provider's153* ability to get any updates back to the original data source. Another possibility154* is a more formal synchronization mechanism such as SyncML155* (<a href="http://www.syncml.org/">http://www.syncml.org/</a>) <br>156*/157package com.sun.rowset.providers;158159160