Path: blob/master/src/java.sql.rowset/share/classes/javax/sql/rowset/WebRowSet.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 javax.sql.rowset;2627import java.sql.*;28import javax.sql.*;29import javax.naming.*;30import java.io.*;31import java.math.*;32import org.xml.sax.*;3334/**35* The standard interface that all implementations of a {@code WebRowSet}36* must implement.37*38* <h2>1.0 Overview</h2>39* The {@code WebRowSetImpl} provides the standard40* reference implementation, which may be extended if required.41* <P>42* The standard WebRowSet XML Schema definition is available at the following43* URI:44* <ul>45* <li>46* <a href="http://xmlns.jcp.org/xml/ns//jdbc/webrowset.xsd">http://xmlns.jcp.org/xml/ns//jdbc/webrowset.xsd</a>47* </li>48* </ul>49* It describes the standard XML document format required when describing a50* {@code RowSet} object in XML and must be used be all standard implementations51* of the {@code WebRowSet} interface to ensure interoperability. In addition,52* the {@code WebRowSet} schema uses specific SQL/XML Schema annotations,53* thus ensuring greater cross54* platform interoperability. This is an effort currently under way at the ISO55* organization. The SQL/XML definition is available at the following URI:56* <ul>57* <li>58* <a href="http://standards.iso.org/iso/9075/2002/12/sqlxml.xsd">http://standards.iso.org/iso/9075/2002/12/sqlxml.xsd</a>59* </li>60* </ul>61* The schema definition describes the internal data of a {@code RowSet} object62* in three distinct areas:63* <UL>64* <li>properties - These properties describe the standard synchronization65* provider properties in addition to the more general {@code RowSet} properties.66* </li>67* <li>metadata - This describes the metadata associated with the tabular structure governed by a68* {@code WebRowSet} object. The metadata described is closely aligned with the69* metadata accessible in the underlying {@code java.sql.ResultSet} interface.70* </li>71* <li>data - This describes the original data (the state of data since the72* last population73* or last synchronization of the {@code WebRowSet} object) and the current74* data. By keeping track of the delta between the original data and the current data,75* a {@code WebRowSet} maintains the ability to synchronize changes76* in its data back to the originating data source.77* </li>78* </ul>79*80* <h2>2.0 WebRowSet States</h2>81* The following sections demonstrates how a {@code WebRowSet} implementation82* should use the XML Schema to describe update, insert, and delete operations83* and to describe the state of a {@code WebRowSet} object in XML.84*85* <h2>2.1 State 1 - Outputting a {@code WebRowSet} Object to XML</h2>86* In this example, a {@code WebRowSet} object is created and populated with a simple 2 column,87* 5 row table from a data source. Having the 5 rows in a {@code WebRowSet} object88* makes it possible to describe them in XML. The89* metadata describing the various standard JavaBeans properties as defined90* in the RowSet interface plus the standard properties defined in91* the {@code CachedRowSet} interface92* provide key details that describe WebRowSet93* properties. Outputting the WebRowSet object to XML using the standard94* {@code writeXml} methods describes the internal properties as follows:95* <PRE>96* {@code97* <properties>98* <command>select co1, col2 from test_table</command>99* <concurrency>1</concurrency>100* <datasource/>101* <escape-processing>true</escape-processing>102* <fetch-direction>0</fetch-direction>103* <fetch-size>0</fetch-size>104* <isolation-level>1</isolation-level>105* <key-columns/>106* <map/>107* <max-field-size>0</max-field-size>108* <max-rows>0</max-rows>109* <query-timeout>0</query-timeout>110* <read-only>false</read-only>111* <rowset-type>TRANSACTION_READ_UNCOMMITTED</rowset-type>112* <show-deleted>false</show-deleted>113* <table-name/>114* <url>jdbc:thin:oracle</url>115* <sync-provider>116* <sync-provider-name>.com.rowset.provider.RIOptimisticProvider</sync-provider-name>117* <sync-provider-vendor>Oracle Corporation</sync-provider-vendor>118* <sync-provider-version>1.0</sync-provider-name>119* <sync-provider-grade>LOW</sync-provider-grade>120* <data-source-lock>NONE</data-source-lock>121* </sync-provider>122* </properties>123* } </PRE>124* The meta-data describing the make up of the WebRowSet is described125* in XML as detailed below. Note both columns are described between the126* {@code column-definition} tags.127* <PRE>128* {@code129* <metadata>130* <column-count>2</column-count>131* <column-definition>132* <column-index>1</column-index>133* <auto-increment>false</auto-increment>134* <case-sensitive>true</case-sensitive>135* <currency>false</currency>136* <nullable>1</nullable>137* <signed>false</signed>138* <searchable>true</searchable>139* <column-display-size>10</column-display-size>140* <column-label>COL1</column-label>141* <column-name>COL1</column-name>142* <schema-name/>143* <column-precision>10</column-precision>144* <column-scale>0</column-scale>145* <table-name/>146* <catalog-name/>147* <column-type>1</column-type>148* <column-type-name>CHAR</column-type-name>149* </column-definition>150* <column-definition>151* <column-index>2</column-index>152* <auto-increment>false</auto-increment>153* <case-sensitive>false</case-sensitive>154* <currency>false</currency>155* <nullable>1</nullable>156* <signed>true</signed>157* <searchable>true</searchable>158* <column-display-size>39</column-display-size>159* <column-label>COL2</column-label>160* <column-name>COL2</column-name>161* <schema-name/>162* <column-precision>38</column-precision>163* <column-scale>0</column-scale>164* <table-name/>165* <catalog-name/>166* <column-type>3</column-type>167* <column-type-name>NUMBER</column-type-name>168* </column-definition>169* </metadata>170* }</PRE>171* Having detailed how the properties and metadata are described, the following details172* how the contents of a {@code WebRowSet} object is described in XML. Note, that173* this describes a {@code WebRowSet} object that has not undergone any174* modifications since its instantiation.175* A {@code currentRow} tag is mapped to each row of the table structure that the176* {@code WebRowSet} object provides. A {@code columnValue} tag may contain177* either the {@code stringData} or {@code binaryData} tag, according to178* the SQL type that179* the XML value is mapping back to. The {@code binaryData} tag contains data in the180* Base64 encoding and is typically used for {@code BLOB} and {@code CLOB} type data.181* <PRE>182* {@code183* <data>184* <currentRow>185* <columnValue>186* firstrow187* </columnValue>188* <columnValue>189* 1190* </columnValue>191* </currentRow>192* <currentRow>193* <columnValue>194* secondrow195* </columnValue>196* <columnValue>197* 2198* </columnValue>199* </currentRow>200* <currentRow>201* <columnValue>202* thirdrow203* </columnValue>204* <columnValue>205* 3206* </columnValue>207* </currentRow>208* <currentRow>209* <columnValue>210* fourthrow211* </columnValue>212* <columnValue>213* 4214* </columnValue>215* </currentRow>216* </data>217* }</PRE>218* <h2>2.2 State 2 - Deleting a Row</h2>219* Deleting a row in a {@code WebRowSet} object involves simply moving to the row220* to be deleted and then calling the method {@code deleteRow}, as in any other221* {@code RowSet} object. The following222* two lines of code, in which <i>wrs</i> is a {@code WebRowSet} object, delete223* the third row.224* <PRE>225* wrs.absolute(3);226* wrs.deleteRow();227* </PRE>228* The XML description shows the third row is marked as a {@code deleteRow},229* which eliminates the third row in the {@code WebRowSet} object.230* <PRE>231* {@code232* <data>233* <currentRow>234* <columnValue>235* firstrow236* </columnValue>237* <columnValue>238* 1239* </columnValue>240* </currentRow>241* <currentRow>242* <columnValue>243* secondrow244* </columnValue>245* <columnValue>246* 2247* </columnValue>248* </currentRow>249* <deleteRow>250* <columnValue>251* thirdrow252* </columnValue>253* <columnValue>254* 3255* </columnValue>256* </deleteRow>257* <currentRow>258* <columnValue>259* fourthrow260* </columnValue>261* <columnValue>262* 4263* </columnValue>264* </currentRow>265* </data>266*} </PRE>267* <h2>2.3 State 3 - Inserting a Row</h2>268* A {@code WebRowSet} object can insert a new row by moving to the insert row,269* calling the appropriate updater methods for each column in the row, and then270* calling the method {@code insertRow}.271* <PRE>272* {@code273* wrs.moveToInsertRow();274* wrs.updateString(1, "fifththrow");275* wrs.updateString(2, "5");276* wrs.insertRow();277* }</PRE>278* The following code fragment changes the second column value in the row just inserted.279* Note that this code applies when new rows are inserted right after the current row,280* which is why the method {@code next} moves the cursor to the correct row.281* Calling the method {@code acceptChanges} writes the change to the data source.282*283* <PRE>284* {@code wrs.moveToCurrentRow();285* wrs.next();286* wrs.updateString(2, "V");287* wrs.acceptChanges();288* }</PRE>289* Describing this in XML demonstrates where the Java code inserts a new row and then290* performs an update on the newly inserted row on an individual field.291* <PRE>292* {@code293* <data>294* <currentRow>295* <columnValue>296* firstrow297* </columnValue>298* <columnValue>299* 1300* </columnValue>301* </currentRow>302* <currentRow>303* <columnValue>304* secondrow305* </columnValue>306* <columnValue>307* 2308* </columnValue>309* </currentRow>310* <currentRow>311* <columnValue>312* newthirdrow313* </columnValue>314* <columnValue>315* III316* </columnValue>317* </currentRow>318* <insertRow>319* <columnValue>320* fifthrow321* </columnValue>322* <columnValue>323* 5324* </columnValue>325* <updateValue>326* V327* </updateValue>328* </insertRow>329* <currentRow>330* <columnValue>331* fourthrow332* </columnValue>333* <columnValue>334* 4335* </columnValue>336* </currentRow>337* </date>338*} </PRE>339* <h2>2.4 State 4 - Modifying a Row</h2>340* Modifying a row produces specific XML that records both the new value and the341* value that was replaced. The value that was replaced becomes the original value,342* and the new value becomes the current value. The following343* code moves the cursor to a specific row, performs some modifications, and updates344* the row when complete.345* <PRE>346*{@code347* wrs.absolute(5);348* wrs.updateString(1, "new4thRow");349* wrs.updateString(2, "IV");350* wrs.updateRow();351* }</PRE>352* In XML, this is described by the {@code modifyRow} tag. Both the original and new353* values are contained within the tag for original row tracking purposes.354* <PRE>355* {@code356* <data>357* <currentRow>358* <columnValue>359* firstrow360* </columnValue>361* <columnValue>362* 1363* </columnValue>364* </currentRow>365* <currentRow>366* <columnValue>367* secondrow368* </columnValue>369* <columnValue>370* 2371* </columnValue>372* </currentRow>373* <currentRow>374* <columnValue>375* newthirdrow376* </columnValue>377* <columnValue>378* III379* </columnValue>380* </currentRow>381* <currentRow>382* <columnValue>383* fifthrow384* </columnValue>385* <columnValue>386* 5387* </columnValue>388* </currentRow>389* <modifyRow>390* <columnValue>391* fourthrow392* </columnValue>393* <updateValue>394* new4thRow395* </updateValue>396* <columnValue>397* 4398* </columnValue>399* <updateValue>400* IV401* </updateValue>402* </modifyRow>403* </data>404* }</PRE>405*406* @see javax.sql.rowset.JdbcRowSet407* @see javax.sql.rowset.CachedRowSet408* @see javax.sql.rowset.FilteredRowSet409* @see javax.sql.rowset.JoinRowSet410* @since 1.5411*/412413public interface WebRowSet extends CachedRowSet {414415/**416* Reads a {@code WebRowSet} object in its XML format from the given417* {@code Reader} object.418*419* @param reader the {@code java.io.Reader} stream from which this420* {@code WebRowSet} object will be populated421422* @throws SQLException if a database access error occurs423*/424public void readXml(java.io.Reader reader) throws SQLException;425426/**427* Reads a stream based XML input to populate this {@code WebRowSet}428* object.429*430* @param iStream the {@code java.io.InputStream} from which this431* {@code WebRowSet} object will be populated432* @throws SQLException if a data source access error occurs433* @throws IOException if an IO exception occurs434*/435public void readXml(java.io.InputStream iStream) throws SQLException, IOException;436437/**438* Populates this {@code WebRowSet} object with439* the contents of the given {@code ResultSet} object and writes its440* data, properties, and metadata441* to the given {@code Writer} object in XML format.442* <p>443* NOTE: The {@code WebRowSet} cursor may be moved to write out the444* contents to the XML data source. If implemented in this way, the cursor <b>must</b>445* be returned to its position just prior to the {@code writeXml()} call.446*447* @param rs the {@code ResultSet} object with which to populate this448* {@code WebRowSet} object449* @param writer the {@code java.io.Writer} object to write to.450* @throws SQLException if an error occurs writing out the rowset451* contents in XML format452*/453public void writeXml(ResultSet rs, java.io.Writer writer) throws SQLException;454455/**456* Populates this {@code WebRowSet} object with457* the contents of the given {@code ResultSet} object and writes its458* data, properties, and metadata459* to the given {@code OutputStream} object in XML format.460* <p>461* NOTE: The {@code WebRowSet} cursor may be moved to write out the462* contents to the XML data source. If implemented in this way, the cursor <b>must</b>463* be returned to its position just prior to the {@code writeXml()} call.464*465* @param rs the {@code ResultSet} object with which to populate this466* {@code WebRowSet} object467* @param oStream the {@code java.io.OutputStream} to write to468* @throws SQLException if a data source access error occurs469* @throws IOException if a IO exception occurs470*/471public void writeXml(ResultSet rs, java.io.OutputStream oStream) throws SQLException, IOException;472473/**474* Writes the data, properties, and metadata for this {@code WebRowSet} object475* to the given {@code Writer} object in XML format.476*477* @param writer the {@code java.io.Writer} stream to write to478* @throws SQLException if an error occurs writing out the rowset479* contents to XML480*/481public void writeXml(java.io.Writer writer) throws SQLException;482483/**484* Writes the data, properties, and metadata for this {@code WebRowSet} object485* to the given {@code OutputStream} object in XML format.486*487* @param oStream the {@code java.io.OutputStream} stream to write to488* @throws SQLException if a data source access error occurs489* @throws IOException if a IO exception occurs490*/491public void writeXml(java.io.OutputStream oStream) throws SQLException, IOException;492493/**494* The public identifier for the XML Schema definition that defines the XML495* tags and their valid values for a {@code WebRowSet} implementation.496*/497public static String PUBLIC_XML_SCHEMA =498"--//Oracle Corporation//XSD Schema//EN";499500/**501* The URL for the XML Schema definition file that defines the XML tags and502* their valid values for a {@code WebRowSet} implementation.503*/504public static String SCHEMA_SYSTEM_ID = "http://java.sun.com/xml/ns/jdbc/webrowset.xsd";505}506507508