0N/A<!
DOCTYPE doctype PUBLIC "-//w3c//dtd html 4.0 transitional//en">
0N/A <
meta http-
equiv="Content-Type" 0N/A <
meta name="GENERATOR" 2362N/ACopyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved. 0N/ADO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/AThis code is free software; you can redistribute it and/or modify it 0N/Aunder the terms of the GNU General Public License version 2 only, as 2362N/Apublished by the Free Software Foundation. Oracle designates this 0N/Aparticular file as subject to the "Classpath" exception as provided 2362N/Aby Oracle in the LICENSE file that accompanied this code. 0N/AThis code is distributed in the hope that it will be useful, but WITHOUT 0N/AANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/AFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/Aversion 2 for more details (a copy is included in the LICENSE file that 0N/Aaccompanied this code). 0N/AYou should have received a copy of the GNU General Public License version 0N/A2 along with this work; if not, write to the Free Software Foundation, 0N/AInc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2365N/APlease contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A <
body bgcolor="#ffffff">
0N/A Repository for the <
tt>RowSet</
tt> reference implementations of the
0N/A <
tt>SyncProvider</
tt> abstract class. These implementations provide a
0N/A disconnected <
code>RowSet</
code>
0N/A object with the ability to synchronize the data in the underlying data
0N/A source with its data. These implementations are provided as
0N/Athe default <
tt>SyncProvider</
tt> implementations and are accessible via the
0N/A<
tt>SyncProvider</
tt> SPI managed by the <
tt>SyncFactory</
tt>.
0N/A<
h3>1.0 <
code>SyncProvider</
code> Reference Implementations</
h3>
0N/A The main job of a <
tt>SyncProvider</
tt> implementation is to manage
0N/Athe reader and writer mechanisms.
0N/A<
tt>RowSet</
tt> object.
0N/Aobject, does the work necessary to populate a <
code>RowSet</
code> object with data.
0N/Asynchronizing a <
code>RowSet</
code> object's data with the data in the originating
0N/Asource of data. Put another way, a writer writes a <
code>RowSet</
code>
0N/Aobject's data back to the data source.
0N/AGenerally speaking, the course of events is this. The reader makes a connection to
0N/Athe data source and reads the data from a <
code>ResultSet</
code> object into its
0N/A<
code>RowSet</
code> object. Then it closes the connection. While
0N/Athe <
code>RowSet</
code> object is disconnected, an application makes some modifications
0N/Ato the data and calls the method <
code>acceptChanges</
code>. At this point, the
0N/Awriter is called to write the changes back to the database table or view
0N/Afrom which the original data came. This is called <
i>synchronization</
i>.
0N/AIf the data in the originating data source has not changed, there is no problem
0N/Awith just writing the <
code>RowSet</
code> object's new data to the data source.
0N/AIf it has changed, however, there is a conflict that needs to be resolved. One
0N/Away to solve the problem is not to let the data in the data source be changed in
0N/Athe first place, which can be done by setting locks on a row, a table, or the
0N/Awhole data source. Setting locks is a way to avoid conflicts, but it can be
0N/Avery expensive. Another approach, which is at the other end of the spectrum,
0N/A is simply to assume that no conflicts will occur and thus do nothing to avoid
0N/ADifferent <
code>SyncProvider</
code> implementations may handle synchronization in
0N/Aany of these ways, varying from doing no checking for
0N/Aconflicts, to doing various levels of checking, to guaranteeing that there are no
0N/AThe <
code>SyncProvider</
code> class offers methods to help a <
code>RowSet</
code>
0N/Aobject discover and manage how a provider handles synchronization.
0N/AThe method <
code>getProviderGrade</
code> returns the
0N/Agrade of synchronization a provider offers. An application can
0N/Adirect the provider to use a particular level of locking by calling
0N/Athe method <
code>setDataSourceLock</
code> and specifying the level of locking desired.
0N/AIf a <
code>RowSet</
code> object's data came from an SQL <
code>VIEW</
code>, an
0N/Aapplication may call the method <
code>supportsUpdatableView</
code> to
0N/Afind out whether the <
code>VIEW</
code> can be updated.
0N/ASynchronization is done completely behind the scenes, so it is third party vendors of
0N/Asynchronization provider implementations who have to take care of this complex task.
0N/AApplication programmers can decide which provider to use and the level of locking to
0N/Abe done, but they are free from having to worry about the implementation details.
0N/AThe JDBC <
code>RowSet</
code> Implementations reference implementation provides two
0N/Aimplementations of the <
code>SyncProvider</
code> class:
0N/Aan optimistic concurrency model for synchronization. This model assumes that there
0N/Awill be few conflicts and therefore uses a relatively low grade of synchronization.
0N/AIf no other provider is available, this is the default provider that the
0N/A<
code>SyncFactory</
code> will supply to a <
code>RowSet</
code> object.
0N/A <
b><
tt>RIXMLProvider </
tt></
b>- provides the <
tt>XmlReader</
tt> (an extension
0N/A <
tt>WebRowSet</
tt> objects to write their state to a
0N/Awell formed XML document according to the <
tt>WebRowSet</
tt> XML schema
0N/A<
h3>2.0 Basics in RowSet Population & Synchronization</
h3>
0N/A A rowset's first task is to populate itself with rows of column values.
0N/AGenerally, these rows will come from a relational database, so a rowset
0N/Ahas properties that supply what is necessary for making a connection to
0N/Aa database and executing a query. A rowset that does not need to establish
0N/Aa connection and execute a command, such as one that gets its data from
0N/Aa tabular file instead of a relational database, does not need to have these
0N/Aproperties set. The vast majority of RowSets, however, do need to set these
0N/Aproperties. The general rule is that a RowSet is required to set only the
0N/Aproperties that it uses.<
br>
0N/A The <
tt>command</
tt> property contains the query that determines what
0N/Adata a <
code>RowSet</
code> will contain. Rowsets have methods for setting a query's
0N/Aparameter(s), which means that a query can be executed multiple times with
0N/Adifferent parameters to produce different result sets. Or the query can be
0N/Achanged to something completely new to get a new result set.
0N/A<
p>Once a rowset contains the rows from a <
tt>ResultSet</
tt> object or some
0N/A other data source, its column values can be updated, and its rows can be
0N/A inserted or deleted. Any method that causes a change in the rowset's values
0N/A or cursor position also notifies any object that has been registered as
0N/Aa listener with the rowset. So, for example, a table that displays the rowset's
0N/A data in an applet can can be notified of changes and make updates as they
0N/A The changes made to a rowset can be propagated back to the original data
0N/A source to keep the rowset and its data source synchronized. Although this
0N/A involves many operations behind the scenes, it is completely transparent
0N/A to the application programmer and remains the concern of the RowSet provider
0N/A developer. All an application has to do is invoke the method <
tt>acceptChanges</
tt>,
0N/A and the data source backing the rowset will be updated to match the current
0N/A values in the rowset. </
p>
0N/A<
p>A disconnected rowset, such as a <
tt>CachedRowSet</
tt> or <
tt>WebRowSet</
tt>
0N/A object, establishes a connection to populate itself with data from a database
0N/A and then closes the connection. The <
code>RowSet</
code> object will remain
0N/A disconnected until it wants to propagate changes back to its database table,
0N/A which is optional. To write its changes back to the database (synchronize with
0N/A the database), the rowset establishes a connection, write the changes, and then
0N/A once again disconnects itself.<
br>
0N/A<
h3> 3.0 Other Possible Implementations</
h3>
0N/A There are many other possible implementations of the <
tt>SyncProvider</
tt> abstract
0N/A class. One possibility is to employ a more robust synchronization model, which
0N/A would give a <
code>RowSet</
code> object increased trust in the provider's
0N/A ability to get any updates back to the original data source. Another possibility
0N/A is a more formal synchronization mechanism such as SyncML