KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > sql > rowset > spi > SyncProvider


1 /*
2  * @(#)SyncProvider.java 1.9 04/03/11
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.sql.rowset.spi;
9
10 import javax.sql.*;
11
12 /**
13  * The synchronization mechanism that provides reader/writer capabilities for
14  * disconnected <code>RowSet</code> objects.
15  * A <code>SyncProvider</code> implementation is a class that extends the
16  * <code>SyncProvider</code> abstract class.
17  * <P>
18  * A <code>SyncProvider</code> implementation is
19  * identified by a unique ID, which is its fully qualified class name.
20  * This name must be registered with the
21  * <code>SyncFactory</code> SPI, thus making the implementation available to
22  * all <code>RowSet</code> implementations.
23  * The factory mechanism in the reference implementation uses this name to instantiate
24  * the implementation, which can then provide a <code>RowSet</code> object with its
25  * reader (a <code>javax.sql.RowSetReader</code> object) and its writer (a
26  * <code>javax.sql.RowSetWriter</code> object).
27  * <P>
28  * The Jdbc <code>RowSet</code> Implementations specification provides two
29  * reference implementations of the <code>SyncProvider</code> abstract class:
30  * <code>RIOptimisticProvider</code> and <code>RIXMLProvider</code>.
31  * The <code>RIOptimisticProvider</code> can set any <code>RowSet</code>
32  * implementation with a <code>RowSetReader</code> object and a
33  * <code>RowSetWriter</code> object. However, only the <code>RIXMLProvider</code>
34  * implementation can set an <code>XmlReader</code> object and an
35  * <code>XmlWriter</code> object. A <code>WebRowSet</code> object uses the
36  * <code>XmlReader</code> object to read data in XML format to populate itself with that
37  * data. It uses the <code>XmlWriter</code> object to write itself to a stream or
38  * <code>java.io.Writer</code> object in XML format.
39  * <P>
40  * <h3>1.0 Naming Convention for Implementations</h3>
41  * As a guide to naming <code>SyncProvider</code>
42  * implementations, the following should be noted:
43  * <UL>
44  * <li>The name for a <code>SyncProvider</code> implementation
45  * is its fully qualified class name.
46  * <li>It is recommended that vendors supply a
47  * <code>SyncProvider</code> implementation in a package named <code>providers</code>.
48  * </UL>
49  * <p>
50  * For instance, if a vendor named Fred, Inc. offered a
51  * <code>SyncProvider</code> implementation, you could have the following:
52  * <PRE>
53  * Vendor name: Fred, Inc.
54  * Domain name of vendor: com.fred
55  * Package name: com.fred.providers
56  * SyncProvider implementation class name: HighAvailabilityProvider
57  *
58  * Fully qualified class name of SyncProvider implementation:
59  * com.fred.providers.HighAvailabilityProvider
60  * </PRE>
61  * <P>
62  * The following line of code uses the fully qualified name to register
63  * this implementation with the <code>SyncFactory</code> static instance.
64  * <PRE>
65  * SyncFactory.registerProvider(
66  * "com.fred.providers.HighAvailabilityProvider");
67  * </PRE>
68  * <P>
69  * The default <code>SyncProvider</code> object provided with the reference
70  * implementation uses the following name:
71  * <pre>
72  * com.sun.rowset.providers.RIOptimisticProvider
73  * </pre>
74  * <p>
75  * A vendor can register a <code>SyncProvider</code> implementation class name
76  * with Sun Microsystems, Inc. by sending email to jdbc@sun.com.
77  * Sun will maintain a database listing the
78  * available <code>SyncProvider</code> implementations for use with compliant
79  * <code>RowSet</code> implementations. This database will be similar to the
80  * one already maintained to list available JDBC drivers.
81  * <P>
82  * Vendors should refer to the reference implementation synchronization
83  * providers for additional guidance on how to implement a new
84  * <code>SyncProvider</code> implementation.
85  *
86  * <h3>2.0 How a <code>RowSet</code> Object Gets Its Provider</h3>
87  *
88  * A disconnected <code>Rowset</code> object may get access to a
89  * <code>SyncProvider</code> object in one of the following two ways:
90  * <UL>
91  * <LI>Using a constructor<BR>
92  * <PRE>
93  * CachedRowSet crs = new CachedRowSet(
94  * "com.fred.providers.HighAvailabilitySyncProvider");
95  * </PRE>
96  * <LI>Using the <code>setSyncProvider</code> method
97  * <PRE>
98  * CachedRowSet crs = new CachedRowSet();
99  * crs.setSyncProvider("com.fred.providers.HighAvailabilitySyncProvider");
100  * </PRE>
101
102  * </UL>
103  * <p>
104  * By default, the reference implementations of the <code>RowSet</code> synchronization
105  * providers are always available to the Java platform.
106  * If no other pluggable synchronization providers have been correctly
107  * registered, the <code>SyncFactory</code> will automatically generate
108  * an instance of the default <code>SyncProvider</code> reference implementation.
109  * Thus, in the preceding code fragment, if no implementation named
110  * <code>com.fred.providers.HighAvailabilitySyncProvider</code> has been
111  * registered with the <code>SyncFactory</code> instance, <i>crs</i> will be
112  * assigned the default provider in the reference implementation, which is
113  * <code>com.sun.rowset.providers.RIOptimisticProvider</code>.
114  * <p>
115  * <h3>3.0 Violations and Synchronization Issues</h3>
116  * If an update between a disconnected <code>RowSet</code> object
117  * and a data source violates
118  * the original query or the underlying data source constraints, this will
119  * result in undefined behavior for all disconnected <code>RowSet</code> implementations
120  * and their designated <code>SyncProvider</code> implementations.
121  * Not defining the behavior when such violations occur offers greater flexibility
122  * for a <code>SyncProvider</code>
123  * implementation to determine its own best course of action.
124  * <p>
125  * A <code>SyncProvider</code> implementation
126  * may choose to implement a specific handler to
127  * handle a subset of query violations.
128  * However if an original query violation or a more general data source constraint
129  * violation is not handled by the <code>SyncProvider</code> implementation,
130  * all <code>SyncProvider</code>
131  * objects must throw a <code>SyncProviderException</code>.
132  * <p>
133  * <h3>4.0 Updatable SQL VIEWs</h3>
134  * It is possible for any disconnected or connected <code>RowSet</code> object to be populated
135  * from an SQL query that is formulated originally from an SQL <code>VIEW</code>.
136  * While in many cases it is possible for an update to be performed to an
137  * underlying view, such an update requires additional metadata, which may vary.
138  * The <code>SyncProvider</code> class provides two constants to indicate whether
139  * an implementation supports updating an SQL <code>VIEW</code>.
140  * <ul>
141  * <li><code><b>NONUPDATABLE_VIEW_SYNC</b></code> - Indicates that a <code>SyncProvider</code>
142  * implementation does not support synchronization with an SQL <code>VIEW</code> as the
143  * underlying source of data for the <code>RowSet</code> object.
144  * <li><code><b>UPDATABLE_VIEW_SYNC</b></code> - Indicates that a
145  * <code>SyncProvider</code> implementation
146  * supports synchronization with an SQL <code>VIEW</code> as the underlying source
147  * of data.
148  * </ul>
149  * <P>
150  * The default is for a <code>RowSet</code> object not to be updatable if it was
151  * populated with data from an SQL <code>VIEW</code>.
152  * <P>
153  * <h3>5.0 <code>SyncProvider</code> Constants</h3>
154  * The <code>SyncProvider</code> class provides three sets of constants that
155  * are used as return values or parameters for <code>SyncProvider</code> methods.
156  * <code>SyncProvider</code> objects may be implemented to perform synchronization
157  * between a <code>RowSet</code> object and its underlying data source with varying
158  * degrees of of care. The first group of constants indicate how synchronization
159  * is handled. For example, <code>GRADE_NONE</code> indicates that a
160  * <code>SyncProvider</code> object will not take any care to see what data is
161  * valid and will simply write the <code>RowSet</code> data to the data source.
162  * <code>GRADE_MODIFIED_AT_COMMIT</code> indicates that the provider will check
163  * only modified data for validity. Other grades check all data for validity
164  * or set locks when data is modified or loaded.
165  * <OL>
166  * <LI>Constants to indicate the synchronization grade of a
167  * <code>SyncProvider</code> object
168  * <UL>
169  * <LI>SyncProvider.GRADE_NONE
170  * <LI>SyncProvider.GRADE_MODIFIED_AT_COMMIT
171  * <LI>SyncProvider.GRADE_CHECK_ALL_AT_COMMIT
172  * <LI>SyncProvider.GRADE_LOCK_WHEN_MODIFIED
173  * <LI>SyncProvider.GRADE_LOCK_WHEN_LOADED
174  * </UL>
175  * <LI>Constants to indicate what locks are set on the data source
176  * <UL>
177  * <LI>SyncProvider.DATASOURCE_NO_LOCK
178  * <LI>SyncProvider.DATASOURCE_ROW_LOCK
179  * <LI>SyncProvider.DATASOURCE_TABLE_LOCK
180  * <LI>SyncProvider.DATASOURCE_DB_LOCK
181  * </UL>
182  * <LI>Constants to indicate whether a <code>SyncProvider</code> object can
183  * perform updates to an SQL <code>VIEW</code> <BR>
184  * These constants are explained in the preceding section (4.0).
185  * <UL>
186  * <LI>SyncProvider.UPDATABLE_VIEW_SYNC
187  * <LI>SyncProvider.NONUPDATABLE_VIEW_SYNC
188  * </UL>
189  * </OL>
190  *
191  * @author Jonathan Bruce
192  * @see javax.sql.rowset.spi.SyncFactory
193  * @see javax.sql.rowset.spi.SyncFactoryException
194  */

195 public abstract class SyncProvider {
196
197    /**
198     * Creates a default <code>SyncProvider</code> object.
199     */

200     public SyncProvider() {
201     }
202     
203     /**
204      * Returns the unique identifier for this <code>SyncProvider</code> object.
205      *
206      * @return a <code>String</code> object with the fully qualified class name of
207      * this <code>SyncProvider</code> object
208      */

209     public abstract String JavaDoc getProviderID();
210         
211     /**
212      * Returns a <code>javax.sql.RowSetReader</code> object, which can be used to
213      * populate a <code>RowSet</code> object with data.
214      *
215      * @return a <code>javax.sql.RowSetReader</code> object
216      */

217     public abstract RowSetReader getRowSetReader();
218
219     /**
220      * Returns a <code>javax.sql.RowSetWriter</code> object, which can be
221      * used to write a <code>RowSet</code> object's data back to the
222      * underlying data source.
223      *
224      * @return a <code>javax.sql.RowSetWriter</code> object
225      */

226     public abstract RowSetWriter getRowSetWriter();
227
228     /**
229      * Returns a constant indicating the
230      * grade of synchronization a <code>RowSet</code> object can expect from
231      * this <code>SyncProvider</code> object.
232      *
233      * @return an int that is one of the following constants:
234      * SyncProvider.GRADE_NONE,
235      * SyncProvider.GRADE_CHECK_MODIFIED_AT_COMMIT,
236      * SyncProvider.GRADE_CHECK_ALL_AT_COMMIT,
237      * SyncProvider.GRADE_LOCK_WHEN_MODIFIED,
238      * SyncProvider.GRADE_LOCK_WHEN_LOADED
239      */

240     public abstract int getProviderGrade();
241
242
243     /**
244      * Sets a lock on the underlying data source at the level indicated by
245      * <i>datasource_lock</i>. This should cause the
246      * <code>SyncProvider</code> to adjust its behavior by increasing or
247      * decreasing the level of optimism it provides for a successful
248      * synchronization.
249      *
250      * @param datasource_lock one of the following constants indicating the severity
251      * level of data source lock required:
252      * <pre>
253      * SyncProvider.DATASOURCE_NO_LOCK,
254      * SyncProvider.DATASOURCE_ROW_LOCK,
255      * SyncProvider.DATASOURCE_TABLE_LOCK,
256      * SyncProvider.DATASOURCE_DB_LOCK,
257      * </pre>
258      * @throws SyncProviderException if an unsupported data source locking level
259      * is set.
260      * @see #getDataSourceLock
261      */

262     public abstract void setDataSourceLock(int datasource_lock)
263         throws SyncProviderException JavaDoc;
264
265     /**
266      * Returns the current data source lock severity level active in this
267      * <code>SyncProvider</code> implementation.
268      *
269      * @return a constant indicating the current level of data source lock
270      * active in this <code>SyncProvider</code> object;
271      * one of the following:
272      * <pre>
273      * SyncProvider.DATASOURCE_NO_LOCK,
274      * SyncProvider.DATASOURCE_ROW_LOCK,
275      * SyncProvider.DATASOURCE_TABLE_LOCK,
276      * SyncProvider.DATASOURCE_DB_LOCK
277      * </pre>
278      * @throws SyncProviderExceptiom if an error occurs determining the data
279      * source locking level.
280      * @see #setDataSourceLock
281
282      */

283     public abstract int getDataSourceLock()
284         throws SyncProviderException JavaDoc;
285
286     /**
287      * Returns whether this <code>SyncProvider</code> implementation
288      * can perform synchronization between a <code>RowSet</code> object
289      * and the SQL <code>VIEW</code> in the data source from which
290      * the <code>RowSet</code> object got its data.
291      *
292      * @return an <code>int</code> saying whether this <code>SyncProvider</code>
293      * object supports updating an SQL <code>VIEW</code>; one of the
294      * following:
295      * SyncProvider.UPDATABLE_VIEW_SYNC,
296      * SyncProvider.NONUPDATABLE_VIEW_SYNC
297      */

298     public abstract int supportsUpdatableView();
299       
300     /**
301      * Returns the release version of this <code>SyncProvider</code> instance.
302      *
303      * @return a <code>String</code> detailing the release version of the
304      * <code>SyncProvider</code> implementation
305      */

306     public abstract String JavaDoc getVersion();
307     
308     /**
309      * Returns the vendor name of this <code>SyncProvider</code> instance
310      *
311      * @return a <code>String</code> detailing the vendor name of this
312      * <code>SyncProvider</code> implementation
313      */

314     public abstract String JavaDoc getVendor();
315
316     /*
317      * Standard description of synchronization grades that a SyncProvider
318      * could provide.
319      */

320
321     /**
322      * Indicates that no synchronization with the originating data source is
323      * provided. A <code>SyncProvider</code>
324      * implementation returning this grade will simply attempt to write
325      * updates in the <code>RowSet</code> object to the underlying data
326      * source without checking the validity of any data.
327      *
328      */

329     public static int GRADE_NONE = 1;
330
331     /**
332      * Indicates a low level optimistic synchronization grade with
333      * respect to the originating data source.
334      *
335      * A <code>SyncProvider</code> implementation
336      * returning this grade will check only rows that have changed.
337      *
338      */

339     public static int GRADE_CHECK_MODIFIED_AT_COMMIT = 2;
340
341     /**
342      * Indicates a high level optimistic synchronization grade with
343      * respect to the originating data source.
344      *
345      * A <code>SyncProvider</code> implementation
346      * returning this grade will check all rows, including rows that have not
347      * changed.
348      */

349     public static int GRADE_CHECK_ALL_AT_COMMIT = 3;
350
351     /**
352      * Indicates a pessimistic synchronization grade with
353      * respect to the originating data source.
354      *
355      * A <code>SyncProvider</code>
356      * implementation returning this grade will lock the row in the originating
357      * data source.
358      */

359     public static int GRADE_LOCK_WHEN_MODIFIED = 4;
360
361     /**
362      * Indicates the most pessimistic synchronization grade with
363      * respect to the originating
364      * data source. A <code>SyncProvider</code>
365      * implementation returning this grade will lock the entire view and/or
366      * table affected by the original statement used to populate a
367      * <code>RowSet</code> object.
368      */

369     public static int GRADE_LOCK_WHEN_LOADED = 5;
370     
371     /**
372      * Indicates that no locks remain on the originating data source. This is the default
373      * lock setting for all <code>SyncProvider</code> implementations unless
374      * otherwise directed by a <code>RowSet</code> object.
375      */

376     public static int DATASOURCE_NO_LOCK = 1;
377
378     /**
379      * Indicates that a lock is placed on the rows that are touched by the original
380      * SQL statement used to populate the <code>RowSet</code> object
381      * that is using this <code>SyncProvider</code> object.
382      */

383     public static int DATASOURCE_ROW_LOCK = 2;
384
385     /**
386      * Indicates that a lock is placed on all tables that are touched by the original
387      * SQL statement used to populate the <code>RowSet</code> object
388      * that is using this <code>SyncProvider</code> object.
389      */

390     public static int DATASOURCE_TABLE_LOCK = 3;
391
392     /**
393      * Indicates that a lock is placed on the entire data source that is the source of
394      * data for the <code>RowSet</code> object
395      * that is using this <code>SyncProvider</code> object.
396      */

397     public static int DATASOURCE_DB_LOCK = 4;
398
399     /**
400      * Indicates that a <code>SyncProvider</code> implementation
401      * supports synchronization between a <code>RowSet</code> object and
402      * the SQL <code>VIEW</code> used to populate it.
403      */

404     public static int UPDATABLE_VIEW_SYNC = 5;
405
406     /**
407      * Indicates that a <code>SyncProvider</code> implementation
408      * does <B>not</B> support synchronization between a <code>RowSet</code>
409      * object and the SQL <code>VIEW</code> used to populate it.
410      */

411     public static int NONUPDATABLE_VIEW_SYNC = 6;
412 }
413
Popular Tags