- 所有超级接口:
-
AutoCloseable,CachedRowSet,Joinable,ResultSet,RowSet,Wrapper
- 所有已知子接口:
-
FilteredRowSet,JoinRowSet
所有实现2.1 状态 1 - 将
在此示例中,创建了一个
WebRowSet的标准接口必须实现的接口。
1.0 概述
WebRowSetImpl提供了标准的参考实现,如果需要可以进行扩展。
标准的WebRowSet XML模式定义可在以下URI找到:
当描述XML中的RowSet对象时,它描述了所需的标准XML文档格式,并且必须被所有标准WebRowSet接口的实现使用,以确保互操作性。此外,WebRowSet模式使用特定的SQL/XML模式注释,从而确保更大的跨平台互操作性。这是ISO组织目前正在进行的工作。SQL/XML定义可在以下URI找到:
模式定义描述了RowSet对象的内部数据,分为三个不同的区域:
- 属性 - 这些属性描述了标准的同步提供程序属性,以及更一般的
RowSet属性。 - 元数据 - 这描述了由
WebRowSet对象管理的表结构相关的元数据。所描述的元数据与底层java.sql.ResultSet接口中可访问的元数据密切相关。 - 数据 - 这描述了原始数据(自上次填充或同步
WebRowSet对象以来的数据状态)和当前数据。通过跟踪原始数据和当前数据之间的差异,WebRowSet保持同步更改的能力,将其数据变化同步回原始数据源。
2.0 WebRowSet 状态
以下部分演示了WebRowSet实现应如何使用XML模式描述更新、插入和删除操作,以及描述WebRowSet对象在XML中的状态。
2.1 状态 1 - 将WebRowSet对象输出到XML
在此示例中,创建了一个WebRowSet对象,并从数据源中填充了一个简单的2列5行表。将5行放入WebRowSet对象中使得可以在XML中描述它们。描述各种标准JavaBeans属性的元数据,如RowSet接口中定义的以及CachedRowSet接口中定义的标准属性,提供了描述WebRowSet属性的关键细节。使用标准的writeXml方法将WebRowSet对象输出到XML,描述内部属性如下:
<properties>
<command>select co1, col2 from test_table</command>
<concurrency>1</concurrency>
<datasource/>
<escape-processing>true</escape-processing>
<fetch-direction>0</fetch-direction>
<fetch-size>0</fetch-size>
<isolation-level>1</isolation-level>
<key-columns/>
<map/>
<max-field-size>0</max-field-size>
<max-rows>0</max-rows>
<query-timeout>0</query-timeout>
<read-only>false</read-only>
<rowset-type>TRANSACTION_READ_UNCOMMITTED</rowset-type>
<show-deleted>false</show-deleted>
<table-name/>
<url>jdbc:thin:oracle</url>
<sync-provider>
<sync-provider-name>.com.rowset.provider.RIOptimisticProvider</sync-provider-name>
<sync-provider-vendor>Oracle Corporation</sync-provider-vendor>
<sync-provider-version>1.0</sync-provider-name>
<sync-provider-grade>LOW</sync-provider-grade>
<data-source-lock>NONE</data-source-lock>
</sync-provider>
</properties>
描述WebRowSet的组成的元数据如下所示。请注意,两列都在column-definition标签之间描述。
<metadata>
<column-count>2</column-count>
<column-definition>
<column-index>1</column-index>
<auto-increment>false</auto-increment>
<case-sensitive>true</case-sensitive>
<currency>false</currency>
<nullable>1</nullable>
<signed>false</signed>
<searchable>true</searchable>
<column-display-size>10</column-display-size>
<column-label>COL1</column-label>
<column-name>COL1</column-name>
<schema-name/>
<column-precision>10</column-precision>
<column-scale>0</column-scale>
<table-name/>
<catalog-name/>
<column-type>1</column-type>
<column-type-name>CHAR</column-type-name>
</column-definition>
<column-definition>
<column-index>2</column-index>
<auto-increment>false</auto-increment>
<case-sensitive>false</case-sensitive>
<currency>false</currency>
<nullable>1</nullable>
<signed>true</signed>
<searchable>true</searchable>
<column-display-size>39</column-display-size>
<column-label>COL2</column-label>
<column-name>COL2</column-name>
<schema-name/>
<column-precision>38</column-precision>
<column-scale>0</column-scale>
<table-name/>
<catalog-name/>
<column-type>3</column-type>
<column-type-name>NUMBER</column-type-name>
</column-definition>
</metadata>
描述属性和元数据的详细信息后,以下内容详细说明了如何在XML中描述WebRowSet对象的内容。请注意,这描述了一个自实例化以来尚未经历任何修改的WebRowSet对象。每行表结构的WebRowSet对象提供了一个currentRow标签。一个columnValue标签可以包含stringData或binaryData标签,具体取决于XML值映射回的SQL类型。 binaryData标签包含Base64编码的数据,通常用于BLOB和CLOB类型数据。
<data>
<currentRow>
<columnValue>
firstrow
</columnValue>
<columnValue>
1
</columnValue>
</currentRow>
<currentRow>
<columnValue>
secondrow
</columnValue>
<columnValue>
2
</columnValue>
</currentRow>
<currentRow>
<columnValue>
thirdrow
</columnValue>
<columnValue>
3
</columnValue>
</currentRow>
<currentRow>
<columnValue>
fourthrow
</columnValue>
<columnValue>
4
</columnValue>
</currentRow>
</data>
2.2 状态 2 - 删除行
在WebRowSet对象中删除一行只需移动到要删除的行,然后调用deleteRow方法,就像在任何其他RowSet对象中一样。以下两行代码中,wrs是一个WebRowSet对象,删除第三行。
wrs.absolute(3);
wrs.deleteRow();
XML描述显示第三行标记为deleteRow,这将消除WebRowSet对象中的第三行。
<data>
<currentRow>
<columnValue>
firstrow
</columnValue>
<columnValue>
1
</columnValue>
</currentRow>
<currentRow>
<columnValue>
secondrow
</columnValue>
<columnValue>
2
</columnValue>
</currentRow>
<deleteRow>
<columnValue>
thirdrow
</columnValue>
<columnValue>
3
</columnValue>
</deleteRow>
<currentRow>
<columnValue>
fourthrow
</columnValue>
<columnValue>
4
</columnValue>
</currentRow>
</data>
2.3 状态 3 - 插入行
WebRowSet对象可以通过移动到插入行,为行中的每列调用适当的更新方法,然后调用insertRow方法来插入新行。
wrs.moveToInsertRow();
wrs.updateString(1, "fifththrow");
wrs.updateString(2, "5");
wrs.insertRow();
以下代码片段更改了刚刚插入的行中的第二列值。请注意,此代码适用于在当前行之后插入新行时,这就是为什么方法next将光标移动到正确的行。调用方法acceptChanges将更改写入数据源。
wrs.moveToCurrentRow();
wrs.next();
wrs.updateString(2, "V");
wrs.acceptChanges();
在XML中描述这一点展示了Java代码如何插入新行,然后对新插入的行中的单个字段执行更新。
<data>
<currentRow>
<columnValue>
第一行
</columnValue>
<columnValue>
1
</columnValue>
</currentRow>
<currentRow>
<columnValue>
第二行
</columnValue>
<columnValue>
2
</columnValue>
</currentRow>
<currentRow>
<columnValue>
新第三行
</columnValue>
<columnValue>
III
</columnValue>
</currentRow>
<insertRow>
<columnValue>
第五行
</columnValue>
<columnValue>
5
</columnValue>
<updateValue>
V
</updateValue>
</insertRow>
<currentRow>
<columnValue>
第四行
</columnValue>
<columnValue>
4
</columnValue>
</currentRow>
</date>
2.4 状态 4 - 修改行
修改行会生成特定的XML,记录新值和被替换的值。被替换的值成为原始值,新值成为当前值。以下代码将游标移动到特定行,执行一些修改,并在完成时更新行。
wrs.absolute(5);
wrs.updateString(1, "新第四行");
wrs.updateString(2, "IV");
wrs.updateRow();
在XML中,这由 modifyRow 标签描述。原始值和新值都包含在标签中,用于跟踪原始行。
<data>
<currentRow>
<columnValue>
第一行
</columnValue>
<columnValue>
1
</columnValue>
</currentRow>
<currentRow>
<columnValue>
第二行
</columnValue>
<columnValue>
2
</columnValue>
</currentRow>
<currentRow>
<columnValue>
新第三行
</columnValue>
<columnValue>
III
</columnValue>
</currentRow>
<currentRow>
<columnValue>
第五行
</columnValue>
<columnValue>
5
</columnValue>
</currentRow>
<modifyRow>
<columnValue>
第四行
</columnValue>
<updateValue>
新第四行
</updateValue>
<columnValue>
4
</columnValue>
<updateValue>
IV
</updateValue>
</modifyRow>
</data>
- 自 JDK 版本:
- 1.5
- 参见:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String定义了 XML 模式定义的公共标识符,该模式定义了WebRowSet实现的 XML 标记及其有效值。static final String定义了 XML 模式定义文件的 URL,该文件定义了WebRowSet实现的 XML 标记及其有效值。Fields declared in interface javax.sql.rowset.CachedRowSet
COMMIT_ON_ACCEPT_CHANGESFields declared in interface java.sql.ResultSet
CLOSE_CURSORS_AT_COMMIT, CONCUR_READ_ONLY, CONCUR_UPDATABLE, FETCH_FORWARD, FETCH_REVERSE, FETCH_UNKNOWN, HOLD_CURSORS_OVER_COMMIT, TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE, TYPE_SCROLL_SENSITIVE -
Method Summary
Modifier and TypeMethodDescriptionvoidreadXml(InputStream iStream) 读取基于流的 XML 输入以填充此WebRowSet对象。void从给定的Reader对象中读取以 XML 格式的WebRowSet对象。voidwriteXml(OutputStream oStream) 将此WebRowSet对象的数据、属性和元数据写入给定的OutputStream对象,以 XML 格式。void将此WebRowSet对象的数据、属性和元数据写入给定的Writer对象,以 XML 格式。voidwriteXml(ResultSet rs, OutputStream oStream) 使用给定的ResultSet对象的内容填充此WebRowSet对象,并将其数据、属性和元数据写入给定的OutputStream对象,以 XML 格式。void使用给定的ResultSet对象的内容填充此WebRowSet对象,并将其数据、属性和元数据写入给定的Writer对象,以 XML 格式。Methods declared in interface javax.sql.rowset.CachedRowSet
acceptChanges, acceptChanges, columnUpdated, columnUpdated, commit, createCopy, createCopyNoConstraints, createCopySchema, createShared, execute, getKeyColumns, getOriginal, getOriginalRow, getPageSize, getRowSetWarnings, getShowDeleted, getSyncProvider, getTableName, nextPage, populate, populate, previousPage, release, restoreOriginal, rollback, rollback, rowSetPopulated, setKeyColumns, setMetaData, setOriginalRow, setPageSize, setShowDeleted, setSyncProvider, setTableName, size, toCollection, toCollection, toCollection, undoDelete, undoInsert, undoUpdateMethods declared in interface javax.sql.rowset.Joinable
getMatchColumnIndexes, getMatchColumnNames, setMatchColumn, setMatchColumn, setMatchColumn, setMatchColumn, unsetMatchColumn, unsetMatchColumn, unsetMatchColumn, unsetMatchColumnMethods declared in interface java.sql.ResultSet
absolute, afterLast, beforeFirst, cancelRowUpdates, clearWarnings, close, deleteRow, findColumn, first, getArray, getArray, getAsciiStream, getAsciiStream, getBigDecimal, getBigDecimal, getBigDecimal, getBigDecimal, getBinaryStream, getBinaryStream, getBlob, getBlob, getBoolean, getBoolean, getByte, getByte, getBytes, getBytes, getCharacterStream, getCharacterStream, getClob, getClob, getConcurrency, getCursorName, getDate, getDate, getDate, getDate, getDouble, getDouble, getFetchDirection, getFetchSize, getFloat, getFloat, getHoldability, getInt, getInt, getLong, getLong, getMetaData, getNCharacterStream, getNCharacterStream, getNClob, getNClob, getNString, getNString, getObject, getObject, getObject, getObject, getObject, getObject, getRef, getRef, getRow, getRowId, getRowId, getShort, getShort, getSQLXML, getSQLXML, getStatement, getString, getString, getTime, getTime, getTime, getTime, getTimestamp, getTimestamp, getTimestamp, getTimestamp, getType, getUnicodeStream, getUnicodeStream, getURL, getURL, getWarnings, insertRow, isAfterLast, isBeforeFirst, isClosed, isFirst, isLast, last, moveToCurrentRow, moveToInsertRow, next, previous, refreshRow, relative, rowDeleted, rowInserted, rowUpdated, setFetchDirection, setFetchSize, updateArray, updateArray, updateAsciiStream, updateAsciiStream, updateAsciiStream, updateAsciiStream, updateAsciiStream, updateAsciiStream, updateBigDecimal, updateBigDecimal, updateBinaryStream, updateBinaryStream, updateBinaryStream, updateBinaryStream, updateBinaryStream, updateBinaryStream, updateBlob, updateBlob, updateBlob, updateBlob, updateBlob, updateBlob, updateBoolean, updateBoolean, updateByte, updateByte, updateBytes, updateBytes, updateCharacterStream, updateCharacterStream, updateCharacterStream, updateCharacterStream, updateCharacterStream, updateCharacterStream, updateClob, updateClob, updateClob, updateClob, updateClob, updateClob, updateDate, updateDate, updateDouble, updateDouble, updateFloat, updateFloat, updateInt, updateInt, updateLong, updateLong, updateNCharacterStream, updateNCharacterStream, updateNCharacterStream, updateNCharacterStream, updateNClob, updateNClob, updateNClob, updateNClob, updateNClob, updateNClob, updateNString, updateNString, updateNull, updateNull, updateObject, updateObject, updateObject, updateObject, updateObject, updateObject, updateObject, updateObject, updateRef, updateRef, updateRow, updateRowId, updateRowId, updateShort, updateShort, updateSQLXML, updateSQLXML, updateString, updateString, updateTime, updateTime, updateTimestamp, updateTimestamp, wasNullMethods declared in interface javax.sql.RowSet
addRowSetListener, clearParameters, execute, getCommand, getDataSourceName, getEscapeProcessing, getMaxFieldSize, getMaxRows, getPassword, getQueryTimeout, getTransactionIsolation, getTypeMap, getUrl, getUsername, isReadOnly, removeRowSetListener, setArray, setAsciiStream, setAsciiStream, setAsciiStream, setAsciiStream, setBigDecimal, setBigDecimal, setBinaryStream, setBinaryStream, setBinaryStream, setBinaryStream, setBlob, setBlob, setBlob, setBlob, setBlob, setBlob, setBoolean, setBoolean, setByte, setByte, setBytes, setBytes, setCharacterStream, setCharacterStream, setCharacterStream, setCharacterStream, setClob, setClob, setClob, setClob, setClob, setClob, setCommand, setConcurrency, setDataSourceName, setDate, setDate, setDate, setDate, setDouble, setDouble, setEscapeProcessing, setFloat, setFloat, setInt, setInt, setLong, setLong, setMaxFieldSize, setMaxRows, setNCharacterStream, setNCharacterStream, setNCharacterStream, setNCharacterStream, setNClob, setNClob, setNClob, setNClob, setNClob, setNClob, setNString, setNString, setNull, setNull, setNull, setNull, setObject, setObject, setObject, setObject, setObject, setObject, setPassword, setQueryTimeout, setReadOnly, setRef, setRowId, setRowId, setShort, setShort, setSQLXML, setSQLXML, setString, setString, setTime, setTime, setTime, setTime, setTimestamp, setTimestamp, setTimestamp, setTimestamp, setTransactionIsolation, setType, setTypeMap, setUrl, setURL, setUsernameMethods declared in interface java.sql.Wrapper
isWrapperFor, unwrap
-
Field Details
-
PUBLIC_XML_SCHEMA
定义了 XML 模式定义的公共标识符,该模式定义了WebRowSet实现的 XML 标记及其有效值。- 参见:
-
SCHEMA_SYSTEM_ID
定义了 XML 模式定义文件的 URL,该文件定义了WebRowSet实现的 XML 标记及其有效值。- 参见:
-
-
Method Details
-
readXml
从给定的Reader对象中读取以 XML 格式的WebRowSet对象。- 参数:
-
reader- 用于填充此WebRowSet对象的java.io.Reader流 - 抛出:
-
SQLException- 如果发生数据库访问错误
-
readXml
读取基于流的 XML 输入以填充此WebRowSet对象。- 参数:
-
iStream- 用于填充此WebRowSet对象的java.io.InputStream - 抛出:
-
SQLException- 如果发生数据源访问错误 -
IOException- 如果发生 IO 异常
-
writeXml
使用给定的ResultSet对象的内容填充此WebRowSet对象,并将其数据、属性和元数据写入给定的Writer对象,以 XML 格式。注意:
WebRowSet光标可能会移动以将内容写入 XML 数据源。如果以这种方式实现,则光标在writeXml()调用之前必须返回到其位置。- 参数:
-
rs- 用于填充此WebRowSet对象的ResultSet对象 -
writer- 要写入的java.io.Writer对象 - 抛出:
-
SQLException- 如果以 XML 格式写出行集内容时发生错误
-
writeXml
使用给定的ResultSet对象的内容填充此WebRowSet对象,并将其数据、属性和元数据写入给定的OutputStream对象,以 XML 格式。注意:
WebRowSet光标可能会移动以将内容写入 XML 数据源。如果以这种方式实现,则光标在writeXml()调用之前必须返回到其位置。- 参数:
-
rs- 用于填充此WebRowSet对象的ResultSet对象 -
oStream- 要写入的java.io.OutputStream - 抛出:
-
SQLException- 如果发生数据源访问错误 -
IOException- 如果发生 IO 异常
-
writeXml
将此WebRowSet对象的数据、属性和元数据写入给定的Writer对象,以 XML 格式。- 参数:
-
writer- 要写入的java.io.Writer流 - 抛出:
-
SQLException- 如果将行集内容写入 XML 时发生错误
-
writeXml
将此WebRowSet对象的数据、属性和元数据写入给定的OutputStream对象,以 XML 格式。- 参数:
-
oStream- 要写入的java.io.OutputStream流 - 抛出:
-
SQLException- 如果发生数据源访问错误 -
IOException- 如果发生 IO 异常
-