JavaTM 2 Platform
Standard Ed. 6

javax.sql.rowset
接口 WebRowSet

所有超级接口:
CachedRowSet, Joinable, ResultSet, RowSet, Wrapper
所有已知子接口:
FilteredRowSet, JoinRowSet

public interface WebRowSet
extends CachedRowSet

所有 WebRowSet 的实现都必须实现的标准接口。

1.0 概述

WebRowSetImpl 提供可在需要时扩展的标准参考实现。

标准的 WebRowSet XML 模式定义位于以下 URI 中:

它描述使用 XML 描述 RowSet 对象时所需的标准 XML 文档格式,所有 WebRowSet 接口的标准实现必须使用该文档格式以确保互操作性。此外,WebRowSet 模式使用特定的 SQL/XML 模式注释,从而确保较高的跨平台互操作性。目前 ISO 组织正在为此而努力。SQL/XML 定义可从以下 URI 中得到: 模式定义从以下三个不同方面描述 RowSet 对象的内部数据:

2.0 WebRowSet 状态

以下几部分演示 WebRowSet 实现应该如何使用 XML 模式来描述更新、插入和删除操作,以及描述 XML 中 WebRowSet 对象的状态。

2.1 状态 1 - 将 WebRowSet 对象输出为 XML

在此示例中,创建一个 WebRowSet 对象,并使用取自数据源的一个简单的 2 列、5 行表进行填充。具有 WebRowSet 对象中的 5 个行使以 XML 描述它们成为可能。描述在 RowSet 接口中定义的各种标准 JavaBeans 属性和在 CachedRowSetTM 接口中定义的标准属性的元数据,提供描述 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_UNCOMMITED</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>Sun Microsystems</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 的组成的元数据使用 XML 描述的细节如下所示。注意,两个列都在 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 对象。currentRow 标记将被映射到 WebRowSet 对象所提供的表结构的每一个行。columnValue 标记可能包含 stringDatabinaryData 标记,这取决于将 XML 值映射回的 SQL 类型。binaryData 标记包含 Base64 编码的数据,通常用于 BLOBCLOB 类型数据。
 <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 对象一样。以下两个代码行(其中 wrsWebRowSet 对象)将删除第三行。
     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>
                        firstrow
                </columnValue>
                <columnValue>
                        1
                </columnValue>
        </currentRow>
        <currentRow>
                <columnValue>
                        secondrow
                </columnValue>
                <columnValue>
                        2
                </columnValue>
        </currentRow>
        <currentRow>
                <columnValue>
                        newthirdrow
                </columnValue>
                <columnValue>
                        III
                </columnValue>
        </currentRow>
        <insertRow>
                <columnValue>
                        fifthrow
                </columnValue>
                <columnValue>
                        5
                </columnValue>
                <updateValue>
                        V
                </updateValue>
        </insertRow>
        <currentRow>
                <columnValue>
                        fourthrow
                </columnValue>
                <columnValue>
                        4
                </columnValue>
        </currentRow>
</date>
 

2.4 状态 4 - 修改行

修改行生成特定的 XML,该 XML 记录新值和被替换的值。被替换的值变成原始值,而新值变成当前值。以下代码将指针移动到特定行,执行一些修改,并在完成时更新行。
 wrs.absolute(5);
 wrs.updateString(1, "new4thRow");
 wrs.updateString(2, "IV");
 wrs.updateRow();
 
在 XML 中,此操作用 modifyRow 标记描述。出于原始行跟踪目的,原始值和新值都包含在该标记中。
 <data>
        <currentRow>
                <columnValue>
                        firstrow
                </columnValue>
                <columnValue>
                        1
                </columnValue>
        </currentRow>
        <currentRow>
                <columnValue>
                        secondrow
                </columnValue>
                <columnValue>
                        2
                </columnValue>
        </currentRow>
        <currentRow>
                <columnValue>
                        newthirdrow
                </columnValue>
                <columnValue>
                        III
                </columnValue>
        </currentRow>
        <currentRow>
                <columnValue>
                        fifthrow
                </columnValue>
                <columnValue>
                        5
                </columnValue>
        </currentRow>
        <modifyRow>
                <columnValue>
                        fourthrow
                </columnValue>
                <updateValue>
                        new4thRow
                </updateValue>
                <columnValue>
                        4
                </columnValue>
                <updateValue>
                        IV
                </updateValue>
        </modifyRow>
 </data>
 

另请参见:
JdbcRowSet, CachedRowSet, FilteredRowSet, JoinRowSet

字段摘要
static String PUBLIC_XML_SCHEMA
          为 WebRowSet 实现定义 XML 标记及其有效值的 XML 模式定义的公共标识符。
static String SCHEMA_SYSTEM_ID
          为 WebRowSet 实现定义 XML 标记及其有效值的 XML 模式定义的 URL。
 
从接口 javax.sql.rowset.CachedRowSet 继承的字段
COMMIT_ON_ACCEPT_CHANGES
 
从接口 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
 
方法摘要
 void readXml(InputStream iStream)
          读取基于流的 XML 输入,以填充此 WebRowSet 对象。
 void readXml(Reader reader)
          从给定的 Reader 对象以其 XML 格式读取 WebRowSet 对象。
 void writeXml(OutputStream oStream)
          以 XML 格式将此 WebRowSet 对象的数据、属性和元数据写入给定的 OutputStream 对象。
 void writeXml(ResultSet rs, OutputStream oStream)
          使用给定 ResultSet 对象的内容填充此 WebRowSet 对象,并以 XML 格式将其数据、属性和元数据写入给定的 OutputStream 对象。
 void writeXml(ResultSet rs, Writer writer)
          使用给定 ResultSet 对象的内容填充此 WebRowSet 对象,并以 XML 格式将其数据、属性和元数据写入给定的 Writer 对象。
 void writeXml(Writer writer)
          以 XML 格式将此 WebRowSet 对象的数据、属性和元数据写入给定的 Writer 对象。
 
从接口 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, undoUpdate
 
从接口 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, setUsername
 
从接口 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, 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, updateRef, updateRef, updateRow, updateRowId, updateRowId, updateShort, updateShort, updateSQLXML, updateSQLXML, updateString, updateString, updateTime, updateTime, updateTimestamp, updateTimestamp, wasNull
 
从接口 java.sql.Wrapper 继承的方法
isWrapperFor, unwrap
 
从接口 javax.sql.rowset.Joinable 继承的方法
getMatchColumnIndexes, getMatchColumnNames, setMatchColumn, setMatchColumn, setMatchColumn, setMatchColumn, unsetMatchColumn, unsetMatchColumn, unsetMatchColumn, unsetMatchColumn
 

字段详细信息

PUBLIC_XML_SCHEMA

static final String PUBLIC_XML_SCHEMA
WebRowSet 实现定义 XML 标记及其有效值的 XML 模式定义的公共标识符。

另请参见:
常量字段值

SCHEMA_SYSTEM_ID

static final String SCHEMA_SYSTEM_ID
WebRowSet 实现定义 XML 标记及其有效值的 XML 模式定义的 URL。

另请参见:
常量字段值
方法详细信息

readXml

void readXml(Reader reader)
             throws SQLException
从给定的 Reader 对象以其 XML 格式读取 WebRowSet 对象。

参数:
reader - 用于填充此 WebRowSet 对象的 java.io.Reader 流。
抛出:
SQLException - 如果发生数据库访问错误

readXml

void readXml(InputStream iStream)
             throws SQLException,
                    IOException
读取基于流的 XML 输入,以填充此 WebRowSet 对象。

参数:
iStream - 用来填充此 WebRowSet 对象的 java.io.InputStream
抛出:
SQLException - 如果发生数据源访问错误
IOException - 如果发生 IO 异常

writeXml

void writeXml(ResultSet rs,
              Writer writer)
              throws SQLException
使用给定 ResultSet 对象的内容填充此 WebRowSet 对象,并以 XML 格式将其数据、属性和元数据写入给定的 Writer 对象。

注:可以移动 WebRowSet 指针将内容写出到 XML 数据源中。如果以这种方式实现,则在调用 writeXml() 之前指针必须先返回其位置。

参数:
rs - 用于填充此 WebRowSet 对象的 ResultSet 对象
writer - 要写入的 java.io.Writer 对象。
抛出:
SQLException - 如果在以 XML 格式写出 rowset 内容时发生错误

writeXml

void writeXml(ResultSet rs,
              OutputStream oStream)
              throws SQLException,
                     IOException
使用给定 ResultSet 对象的内容填充此 WebRowSet 对象,并以 XML 格式将其数据、属性和元数据写入给定的 OutputStream 对象。

注:可以移动 WebRowSet 指针将内容写出到 XML 数据源中。如果以这种方式实现,则在调用 writeXml() 之前必须先将指针返回其位置。

参数:
rs - 用于填充此 WebRowSet 对象的 ResultSet 对象
oStream - 要写入的 java.io.OutputStream
抛出:
SQLException - 如果发生数据源访问错误
IOException - 如果发生 IO 异常

writeXml

void writeXml(Writer writer)
              throws SQLException
以 XML 格式将此 WebRowSet 对象的数据、属性和元数据写入给定的 Writer 对象。

参数:
writer - 要写入的 java.io.Writer
抛出:
SQLException - 如果在将 rowset 内容写出到 XML 时出错

writeXml

void writeXml(OutputStream oStream)
              throws SQLException,
                     IOException
以 XML 格式将此 WebRowSet 对象的数据、属性和元数据写入给定的 OutputStream 对象。

参数:
oStream - 要写入的 java.io.OutputStream
抛出:
SQLException - 如果发生数据源访问错误
IOException - 如果发生 IO 异常

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见

版权所有 2008 Sun Microsystems, Inc. 保留所有权利。请遵守GNU General Public License, version 2 only