/* * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /** * The standard classes and interfaces that a third party vendor has to * use in its implementation of a synchronization provider. These classes and * interfaces are referred to as the Service Provider Interface (SPI). To make it possible * for a {@code RowSet} object to use an implementation, the vendor must register * it with the {@code SyncFactory} singleton. (See the class comment for * {@code SyncProvider} for a full explanation of the registration process and * the naming convention to be used.) * *
* The following classes and interfaces make up the {@code javax.sql.rowset.spi} * package: *
* A {@code SyncProvider} implementation provides a disconnected {@code RowSet} * object with the mechanisms for reading data into it and for writing data that has been * modified in it * back to the underlying data source. A reader, a {@code RowSetReader} or * {@code XMLReader} object, reads data into a {@code RowSet} object when the * {@code CachedRowSet} methods {@code execute} or {@code populate} * are called. A writer, a {@code RowSetWriter} or {@code XMLWriter} * object, writes changes back to the underlying data source when the * {@code CachedRowSet} method {@code acceptChanges} is called. *
* The process of writing changes in a {@code RowSet} object to its data source * is known as synchronization. The {@code SyncProvider} implementation that a * {@code RowSet} object is using determines the level of synchronization that the * {@code RowSet} object's writer uses. The various levels of synchronization are * referred to as grades. *
* The lower grades of synchronization are * known as optimistic concurrency levels because they optimistically * assume that there will be no conflicts or very few conflicts. A conflict exists when * the same data modified in the {@code RowSet} object has also been modified * in the data source. Using the optimistic concurrency model means that if there * is a conflict, modifications to either the data source or the {@code RowSet} * object will be lost. *
* Higher grades of synchronization are called pessimistic because they assume * that others will be accessing the data source and making modifications. These * grades set varying levels of locks to increase the chances that no conflicts * occur. *
* The lowest level of synchronization is simply writing any changes made to the * {@code RowSet} object to its underlying data source. The writer does * nothing to check for conflicts. * If there is a conflict and the data * source values are overwritten, the changes other parties have made by to the data * source are lost. *
* The {@code RIXMLProvider} implementation uses the lowest level * of synchronization and just writes {@code RowSet} changes to the data source. * *
* For the next level up, the * writer checks to see if there are any conflicts, and if there are, * it does not write anything to the data source. The problem with this concurrency * level is that if another party has modified the corresponding data in the data source * since the {@code RowSet} object got its data, * the changes made to the {@code RowSet} object are lost. The * {@code RIOptimisticProvider} implementation uses this level of synchronization. *
* At higher levels of synchronization, referred to as pessimistic concurrency, * the writer take steps to avoid conflicts by setting locks. Setting locks * can vary from setting a lock on a single row to setting a lock on a table * or the entire data source. The level of synchronization is therefore a tradeoff * between the ability of users to access the data source concurrently and the ability * of the writer to keep the data in the {@code RowSet} object and its data source * synchronized. *
* It is a requirement that all disconnected {@code RowSet} objects * ({@code CachedRowSet}, {@code FilteredRowSet}, {@code JoinRowSet}, * and {@code WebRowSet} objects) obtain their {@code SyncProvider} objects * from the {@code SyncFactory} mechanism. *
* The reference implementation (RI) provides two synchronization providers. *
* If a {@code WebRowSet} object does not specify a provider in its constructor, the * {@code SyncFactory} will give it an instance of {@code RIOptimisticProvider}. * However, the constructor for {@code WebRowSet} is implemented to set the provider * to the {@code RIXMLProvider}, which reads and writes a {@code RowSet} object * in XML format. *
* See the SyncProvider class * specification for further details. *
* Vendors may develop a {@code SyncProvider} implementation with any one of the possible * levels of synchronization, thus giving {@code RowSet} objects a choice of * synchronization mechanisms. * *
* The Service Provider Interface provides a pluggable mechanism by which * {@code SyncProvider} implementations can be registered and then generated when * required. The lazy reference mechanism employed by the {@code SyncFactory} limits * unnecessary resource consumption by not creating an instance until it is * required by a disconnected * {@code RowSet} object. The {@code SyncFactory} class also provides * a standard API to configure logging options and streams that may be provided * by a particular {@code SyncProvider} implementation. *
* 2.2 Registering with the {@code SyncFactory} *
* A third party {@code SyncProvider} implementation must be registered with the * {@code SyncFactory} in order for a disconnected {@code RowSet} object * to obtain it and thereby use its {@code javax.sql.RowSetReader} and * {@code javax.sql.RowSetWriter} * implementations. The following registration mechanisms are available to all * {@code SyncProvider} implementations: *
* Details on how to specify the system properties or properties in a property file * and how to configure the JNDI Context are explained in detail in the * {@code SyncFactory} class description. *
* 2.3 SyncFactory Provider Instance Generation Policies *
* The {@code SyncFactory} generates a requested {@code SyncProvider} * object if the provider has been correctly registered. The * following policies are adhered to when either a disconnected {@code RowSet} object * is instantiated with a specified {@code SyncProvider} implementation or is * reconfigured at runtime with an alternative {@code SyncProvider} object. *
* These policies are explored in more detail in the * {@code SyncFactory} class. * *
* A compliant {@code SyncProvider} implementation that is fully pluggable * into the {@code SyncFactory} must extend and implement all * abstract methods in the {@code SyncProvider} * class. In addition, an implementation must determine the * grade, locking and updatable view capabilities defined in the * {@code SyncProvider} class definition. One or more of the * {@code SyncProvider} description criteria must be supported. It * is expected that vendor implementations will offer a range of grade, locking, and * updatable view capabilities. *
* Furthermore, the {@code SyncProvider} naming convention must be followed as * detailed in the {@code SyncProvider} class * description. *
* 3.2 Grades *
* JSR 114 defines a set of grades to describe the quality of synchronization * a {@code SyncProvider} object can offer a disconnected {@code RowSet} * object. These grades are listed from the lowest quality of service to the highest. *
* 3.3 Locks *
* JSR 114 defines a set of constants that specify whether any locks have been * placed on a {@code RowSet} object's underlying data source and, if so, * on which constructs the locks are placed. These locks will remain on the data * source while the {@code RowSet} object is disconnected from the data source. *
* These constants should be considered complementary to the * grade constants. The default setting for the majority of grade settings requires * that no data source locks remain when a {@code RowSet} object is disconnected * from its data source. * The grades {@code GRADE_LOCK_WHEN_MODIFIED} and * {@code GRADE_LOCK_WHEN_LOADED} allow a disconnected {@code RowSet} object * to have a fine-grained control over the degree of locking. *
* 3.4 Updatable Views *
* A {@code RowSet} object may be populated with data from an SQL {@code VIEW}. * The following constants indicate whether a {@code SyncProvider} object can * update data in the table or tables from which the {@code VIEW} was derived. *
* 3.5 Usage of {@code SyncProvider} Grading and Locking *
* In the example below, the reference {@code CachedRowSetImpl} implementation
* reconfigures its current {@code SyncProvider} object by calling the
* {@code setSyncProvider} method.
*
*
* CachedRowSetImpl crs = new CachedRowSetImpl();
* crs.setSyncProvider("com.foo.bar.HASyncProvider");
*
* An application can retrieve the {@code SyncProvider} object currently in use
* by a disconnected {@code RowSet} object. It can also retrieve the
* grade of synchronization with which the provider was implemented and the degree of
* locking currently in use. In addition, an application has the flexibility to set
* the degree of locking to be used, which can increase the possibilities for successful
* synchronization. These operation are shown in the following code fragment.
*
* SyncProvider sync = crs.getSyncProvider();
*
* switch (sync.getProviderGrade()) {
* case: SyncProvider.GRADE_CHECK_ALL_AT_COMMIT
* //A high grade of optimistic synchronization
* break;
* case: SyncProvider.GRADE_CHECK_MODIFIED_AT_COMMIT
* //A low grade of optimistic synchronization
* break;
* case: SyncProvider.GRADE_LOCK_WHEN_LOADED
* // A pessimistic synchronization grade
* break;
* case: SyncProvider.GRADE_LOCK_WHEN_MODIFIED
* // A pessimistic synchronization grade
* break;
* case: SyncProvider.GRADE_NONE
* // No synchronization with the originating data source provided
* break;
* }
*
* switch (sync.getDataSourceLock() {
* case: SyncProvider.DATASOURCE_DB_LOCK
* // A lock is placed on the entire datasource that is used by the
* // {@code RowSet} object
* break;
*
* case: SyncProvider.DATASOURCE_NO_LOCK
* // No locks remain on the originating data source.
* break;
*
* case: SyncProvider.DATASOURCE_ROW_LOCK
* // A lock is placed on the rows that are touched by the original
* // SQL statement used to populate
* // the RowSet object that is using the SyncProvider
* break;
*
* case: DATASOURCE_TABLE_LOCK
* // A lock is placed on all tables that are touched by the original
* // SQL statement used to populated
* // the RowSet object that is using the SyncProvider
* break;
*
*
* It is also possible using the static utility method in the
* {@code SyncFactory} class to determine the list of {@code SyncProvider}
* implementations currently registered with the {@code SyncFactory}.
*
* * Enumeration e = SyncFactory.getRegisteredProviders(); ** * *
* A {@code SyncResolver} object, which is a special kind of * {@code CachedRowSet} object or * a {@code JdbcRowSet} object that has implemented the {@code SyncResolver} * interface, examines the conflicts row by row. It is a duplicate of the * {@code RowSet} object being synchronized except that it contains only the data * from the data source this is causing a conflict. All of the other column values are * set to {@code null}. To navigate from one conflict value to another, a * {@code SyncResolver} object provides the methods {@code nextConflict} and * {@code previousConflict}. *
* The {@code SyncResolver} interface also * provides methods for doing the following: *
* When the {@code CachedRowSet} method {@code acceptChanges} is called, it * delegates to the {@code RowSet} object's {@code SyncProvider} object. * How the writer provided by that {@code SyncProvider} object is implemented * determines what level (grade) of checking for conflicts will be done. After all * checking for conflicts is completed and one or more conflicts has been found, the method * {@code acceptChanges} throws a {@code SyncProviderException} object. The * application can catch the exception and use it to obtain a {@code SyncResolver} object. *
* The application can then use {@code SyncResolver} methods to get information * about each conflict and decide what to do. If the application logic or the user * decides that a value in the {@code RowSet} object should be the one to * persist, the application or user can overwrite the data source value with it. *
* The comment for the {@code SyncResolver} interface has more detail. * *