0N/A/*
2741N/A * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.rowset.providers;
0N/A
0N/Aimport com.sun.rowset.JdbcRowSetResourceBundle;
0N/Aimport javax.sql.*;
0N/Aimport java.io.*;
0N/A
0N/Aimport javax.sql.rowset.spi.*;
0N/Aimport com.sun.rowset.internal.*;
0N/A
0N/A/**
0N/A * The reference implementation of a JDBC Rowset synchronization provider
0N/A * providing optimistic synchronization with a relational datastore
0N/A * using any JDBC technology-enabled driver.
0N/A * <p>
0N/A * <h3>1.0 Backgroud</h3>
0N/A * This synchronization provider is registered with the
0N/A * <code>SyncFactory</code> by default as the
0N/A * <code>com.sun.rowset.providers.RIOptimisticProvider</code>.
0N/A * As an extension of the <code>SyncProvider</code> abstract
0N/A * class, it provides the reader and writer classes required by disconnected
0N/A * rowsets as <code>javax.sql.RowSetReader</code> and <code>javax.sql.RowSetWriter</code>
0N/A * interface implementations. As a reference implementation,
0N/A * <code>RIOptimisticProvider</code> provides a
0N/A * fully functional implementation offering a medium grade classification of
0N/A * syncrhonization, namely GRADE_CHECK_MODIFIED_AT_COMMIT. A
0N/A * disconnected <code>RowSet</code> implementation using the
0N/A * <code>RIOptimisticProvider</code> can expect the writer to
0N/A * check only rows that have been modified in the <code>RowSet</code> against
0N/A * the values in the data source. If there is a conflict, that is, if a value
0N/A * in the data source has been changed by another party, the
0N/A * <code>RIOptimisticProvider</code> will not write any of the changes to the data
0N/A * source and will throw a <code>SyncProviderException</code> object.
0N/A *
0N/A * <h3>2.0 Usage</h3>
0N/A * Standard disconnected <code>RowSet</code> implementations may opt to use this
0N/A * <code>SyncProvider</code> implementation in one of two ways:
0N/A * <OL>
0N/A * <LI>By specifically calling the <code>setSyncProvider</code> method
0N/A defined in the <code>CachedRowSet</code> interface
0N/A * <pre>
0N/A * CachedRowset crs = new FooCachedRowSetImpl();
0N/A * crs.setSyncProvider("com.sun.rowset.providers.RIOptimisticProvider");
0N/A * </pre>
0N/A * <LI>By specifying it in the constructor of the <code>RowSet</code>
0N/A * implementation
0N/A * <pre>
0N/A * CachedRowset crs = new FooCachedRowSetImpl(
0N/A * "com.sun.rowset.providers.RIOptimisticProvider");
0N/A * </pre>
0N/A * </OL>
0N/A * Note that because the <code>RIOptimisticProvider</code> implementation is
0N/A * the default provider, it will always be the provider when no provider ID is
0N/A * specified to the constructor.
0N/A * <P>
0N/A * See the standard <code>RowSet</code> reference implementations in the
0N/A * <code>com.sun.rowset</code> package for more details.
0N/A *
0N/A * @author Jonathan Bruce
0N/A * @see javax.sql.rowset.spi.SyncProvider
0N/A * @see javax.sql.rowset.spi.SyncProviderException
0N/A * @see javax.sql.rowset.spi.SyncFactory
0N/A * @see javax.sql.rowset.spi.SyncFactoryException
0N/A *
0N/A */
0N/Apublic final class RIOptimisticProvider extends SyncProvider implements Serializable {
0N/A
0N/A private CachedRowSetReader reader;
0N/A private CachedRowSetWriter writer;
0N/A
0N/A /**
2802N/A * The unique provider identifier.
0N/A */
0N/A private String providerID = "com.sun.rowset.providers.RIOptimisticProvider";
0N/A
0N/A /**
0N/A * The vendor name of this SyncProvider implementation
0N/A */
2802N/A private String vendorName = "Oracle Corporation";
0N/A
0N/A /**
0N/A * The version number of this SyncProvider implementation
0N/A */
0N/A private String versionNumber = "1.0";
0N/A
0N/A /**
0N/A * ResourceBundle
0N/A */
0N/A private JdbcRowSetResourceBundle resBundle;
0N/A
0N/A /**
0N/A * Creates an <code>RIOptimisticProvider</code> object initialized with the
0N/A * fully qualified class name of this <code>SyncProvider</code> implementation
0N/A * and a default reader and writer.
0N/A * <P>
0N/A * This provider is available to all disconnected <code>RowSet</code> implementations
0N/A * as the default persistence provider.
0N/A */
0N/A public RIOptimisticProvider() {
0N/A providerID = this.getClass().getName();
0N/A reader = new CachedRowSetReader();
0N/A writer = new CachedRowSetWriter();
0N/A try {
0N/A resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();
0N/A } catch(IOException ioe) {
0N/A throw new RuntimeException(ioe);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>'javax.sql.rowset.providers.RIOptimisticProvider'</code>
0N/A * provider identification string.
0N/A *
0N/A * @return String Provider ID of this persistence provider
0N/A */
0N/A public String getProviderID() {
0N/A return providerID;
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>javax.sql.RowSetWriter</code> object for this
0N/A * <code>RIOptimisticProvider</code> object. This is the writer that will
0N/A * write changes made to the <code>Rowset</code> object back to the data source.
0N/A *
0N/A * @return the <code>javax.sql.RowSetWriter</code> object for this
0N/A * <code>RIOptimisticProvider</code> object
0N/A */
0N/A public RowSetWriter getRowSetWriter() {
0N/A try {
0N/A writer.setReader(reader);
0N/A } catch (java.sql.SQLException e) {}
0N/A return writer;
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>javax.sql.RowSetReader</code> object for this
0N/A * <code>RIOptimisticProvider</code> object. This is the reader that will
0N/A * populate a <code>RowSet</code> object using this <code>RIOptimisticProvider</code>.
0N/A *
0N/A * @return the <code>javax.sql.RowSetReader</code> object for this
0N/A * <code>RIOptimisticProvider</code> object
0N/A */
0N/A public RowSetReader getRowSetReader() {
0N/A return reader;
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>SyncProvider</code> grade of synchronization that
0N/A * <code>RowSet</code> objects can expect when using this
0N/A * implementation. As an optimisic synchonization provider, the writer
0N/A * will only check rows that have been modified in the <code>RowSet</code>
0N/A * object.
0N/A */
0N/A public int getProviderGrade() {
0N/A return SyncProvider.GRADE_CHECK_MODIFIED_AT_COMMIT;
0N/A }
0N/A
0N/A /**
0N/A * Modifies the data source lock severity according to the standard
0N/A * <code>SyncProvider</code> classifications.
0N/A *
0N/A * @param datasource_lock An <code>int</code> indicating the level of locking to be
0N/A * set; must be one of the following constants:
0N/A * <PRE>
0N/A * SyncProvider.DATASOURCE_NO_LOCK,
0N/A * SyncProvider.DATASOURCE_ROW_LOCK,
0N/A * SyncProvider.DATASOURCE_TABLE_LOCK,
0N/A * SyncProvider.DATASOURCE_DB_LOCk
0N/A * </PRE>
0N/A * @throws SyncProviderException if the parameter specified is not
0N/A * <code>SyncProvider.DATASOURCE_NO_LOCK</code>
0N/A */
0N/A public void setDataSourceLock(int datasource_lock) throws SyncProviderException {
0N/A if(datasource_lock != SyncProvider.DATASOURCE_NO_LOCK ) {
0N/A throw new SyncProviderException(resBundle.handleGetObject("riop.locking").toString());
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the active data source lock severity in this
0N/A * reference implementation of the <code>SyncProvider</code>
0N/A * abstract class.
0N/A *
0N/A * @return <code>SyncProvider.DATASOURCE_NO_LOCK</code>.
0N/A * The reference implementation does not support data source locks.
0N/A */
0N/A public int getDataSourceLock() throws SyncProviderException {
0N/A return SyncProvider.DATASOURCE_NO_LOCK;
0N/A }
0N/A
0N/A /**
0N/A * Returns the supported updatable view abilities of the
0N/A * reference implementation of the <code>SyncProvider</code>
0N/A * abstract class.
0N/A *
0N/A * @return <code>SyncProvider.NONUPDATABLE_VIEW_SYNC</code>. The
0N/A * the reference implementation does not support updating tables
0N/A * that are the source of a view.
0N/A */
0N/A public int supportsUpdatableView() {
0N/A return SyncProvider.NONUPDATABLE_VIEW_SYNC;
0N/A }
0N/A
0N/A /**
0N/A * Returns the release version ID of the Reference Implementation Optimistic
0N/A * Synchronization Provider.
0N/A *
0N/A * @return the <code>String</code> detailing the version number of this SyncProvider
0N/A */
0N/A public String getVersion() {
0N/A return this.versionNumber;
0N/A }
0N/A
0N/A /**
2802N/A * Returns the vendor name of the Reference Implementation Optimistic
2802N/A * Synchronization Provider
0N/A *
0N/A * @return the <code>String</code> detailing the vendor name of this
0N/A * SyncProvider
0N/A */
0N/A public String getVendor() {
0N/A return this.vendorName;
0N/A }
2741N/A
2741N/A private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
2741N/A // Default state initialization happens here
2741N/A ois.defaultReadObject();
2741N/A // Initialization of transient Res Bundle happens here .
2741N/A try {
2741N/A resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();
2741N/A } catch(IOException ioe) {
2741N/A throw new RuntimeException(ioe);
2741N/A }
2741N/A
2741N/A }
2741N/A static final long serialVersionUID =-3143367176751761936L;
2741N/A
0N/A}