Path: blob/master/src/java.sql.rowset/share/classes/com/sun/rowset/providers/RIXMLProvider.java
40948 views
/*1* Copyright (c) 2003, 2019, 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*/2425package com.sun.rowset.providers;2627import com.sun.rowset.JdbcRowSetResourceBundle;28import java.io.IOException;29import java.sql.*;30import javax.sql.*;3132import javax.sql.rowset.spi.*;3334/**35* A reference implementation of a JDBC RowSet synchronization provider36* with the ability to read and write rowsets in well formed XML using the37* standard WebRowSet schema.38*39* <h2>1.0 Background</h2>40* This synchronization provider is registered with the41* <code>SyncFactory</code> by default as the42* <code>com.sun.rowset.providers.RIXMLProvider</code>.43* <P>44* A <code>WebRowSet</code> object uses an <code>RIXMLProvider</code> implementation45* to read an XML data source or to write itself in XML format using the46* <code>WebRowSet</code> XML schema definition available at47* <pre>48* <a href="http://xmlns.jcp.org/xml/ns//jdbc/webrowset.xsd">http://xmlns.jcp.org/xml/ns//jdbc/webrowset.xsd</a>49* </pre>50* The <code>RIXMLProvider</code> implementation has a synchronization level of51* GRADE_NONE, which means that it does no checking at all for conflicts. It52* simply writes a <code>WebRowSet</code> object to a file.53* <h2>2.0 Usage</h2>54* A <code>WebRowSet</code> implementation is created with an <code>RIXMLProvider</code>55* by default.56* <pre>57* WebRowSet wrs = new FooWebRowSetImpl();58* </pre>59* The <code>SyncFactory</code> always provides an instance of60* <code>RIOptimisticProvider</code> when no provider is specified,61* but the implementation of the default constructor for <code>WebRowSet</code> sets the62* provider to be the <code>RIXMLProvider</code> implementation. Therefore,63* the following line of code is executed behind the scenes as part of the64* implementation of the default constructor.65* <pre>66* wrs.setSyncProvider("com.sun.rowset.providers.RIXMLProvider");67* </pre>68* See the standard <code>RowSet</code> reference implementations in the69* <code>com.sun.rowset</code> package for more details.70*71* @author Jonathan Bruce72* @see javax.sql.rowset.spi.SyncProvider73* @see javax.sql.rowset.spi.SyncProviderException74* @see javax.sql.rowset.spi.SyncFactory75* @see javax.sql.rowset.spi.SyncFactoryException76*/77public final class RIXMLProvider extends SyncProvider {7879/**80* The unique provider identifier.81*/82private String providerID = "com.sun.rowset.providers.RIXMLProvider";8384/**85* The vendor name of this SyncProvider implementation.86*/87private String vendorName = "Oracle Corporation";8889/**90* The version number of this SyncProvider implementation.91*/92private String versionNumber = "1.0";9394private JdbcRowSetResourceBundle resBundle;9596private XmlReader xmlReader;97private XmlWriter xmlWriter;9899/**100* This provider is available to all JDBC <code>RowSet</code> implementations as the101* default persistence provider.102*/103public RIXMLProvider() {104providerID = this.getClass().getName();105try {106resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();107} catch(IOException ioe) {108throw new RuntimeException(ioe);109}110}111112/**113* Returns <code>"javax.sql.rowset.providers.RIXMLProvider"</code>, which is114* the fully qualified class name of this provider implementation.115*116* @return a <code>String</code> object with the fully specified class name of117* this <code>RIOptimisticProvider</code> implementation118*/119public String getProviderID() {120return providerID;121}122123// additional methods that sit on top of reader/writer methods back to124// original datasource. Allow XML state to be written out and in125126/**127* Sets this <code>WebRowSet</code> object's reader to the given128* <code>XmlReader</code> object.129*130* @throws SQLException if a database access error occurs131*/132public void setXmlReader(XmlReader reader) throws SQLException {133xmlReader = reader;134}135136/**137* Sets this <code>WebRowSet</code> object's writer to the given138* <code>XmlWriter</code> object.139*140* @throws SQLException if a database access error occurs141*/142public void setXmlWriter(XmlWriter writer) throws SQLException {143xmlWriter = writer;144}145146/**147* Retrieves the reader that this <code>WebRowSet</code> object148* will call when its <code>readXml</code> method is called.149*150* @return the <code>XmlReader</code> object for this SyncProvider151* @throws SQLException if a database access error occurs152*/153public XmlReader getXmlReader() throws SQLException {154return xmlReader;155}156157/**158* Retrieves the writer that this <code>WebRowSet</code> object159* will call when its <code>writeXml</code> method is called.160*161* @return the <code>XmlWriter</code> for this SyncProvider162* @throws SQLException if a database access error occurs163*/164public XmlWriter getXmlWriter() throws SQLException {165return xmlWriter;166}167168/**169* Returns the <code>SyncProvider</code> grade of syncrhonization that170* <code>RowSet</code> object instances can expect when using this171* implementation. As this implementation provides no synchonization172* facilities to the XML data source, the lowest grade is returned.173*174* @return the <code>SyncProvider</code> syncronization grade of this175* provider; must be one of the following constants:176* <PRE>177* SyncProvider.GRADE_NONE,178* SyncProvider.GRADE_MODIFIED_AT_COMMIT,179* SyncProvider.GRADE_CHECK_ALL_AT_COMMIT,180* SyncProvider.GRADE_LOCK_WHEN_MODIFIED,181* SyncProvider.GRADE_LOCK_WHEN_LOADED182* </PRE>183*184*/185public int getProviderGrade() {186return SyncProvider.GRADE_NONE;187}188189/**190* Returns the default UPDATABLE_VIEW behavior of this reader191*192*/193public int supportsUpdatableView() {194return SyncProvider.NONUPDATABLE_VIEW_SYNC;195}196197/**198* Returns the default DATASOURCE_LOCK behavior of this reader199*/200public int getDataSourceLock() throws SyncProviderException {201return SyncProvider.DATASOURCE_NO_LOCK;202}203204/**205* Throws an unsupported operation exception as this method does206* function with non-locking XML data sources.207*/208public void setDataSourceLock(int lock) throws SyncProviderException {209throw new UnsupportedOperationException(resBundle.handleGetObject("rixml.unsupp").toString());210}211212/**213* Returns a null object as RowSetWriters are not returned by this SyncProvider214*/215public RowSetWriter getRowSetWriter() {216return null;217}218219/**220* Returns a null object as RowSetWriter objects are not returned by this221* SyncProvider222*/223public RowSetReader getRowSetReader() {224return null;225}226227/**228* Returns the release version ID of the Reference Implementation Optimistic229* Synchronization Provider.230*231* @return the <code>String</code> detailing the version number of this SyncProvider232*/233public String getVersion() {234return this.versionNumber;235}236237/**238* Returns the vendor name of the Reference Implemntation Optimistic239* Syncchronication Provider240*241* @return the <code>String</code> detailing the vendor name of this242* SyncProvider243*/244public String getVendor() {245return this.vendorName;246}247}248249250