|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
public interface WebRowSet
所有 WebRowSet 的實作都必須實作的標準介面。
WebRowSetImpl 提供可在需要時擴展的標準參考實作。
標準的 WebRowSet XML 網要定義位於以下 URI 中:
http://java.sun.com/xml/ns/jdbc/webrowset.xsd它描述使用 XML 描述
RowSet 物件時所需的標準 XML 文檔格式,所有 WebRowSet 介面的標準實作必須使用該文檔格式以確保互操作性。此外,WebRowSet 網要使用特定的 SQL/XML 網要註釋,從而確保較高的跨平臺互操作性。目前 ISO 組織正在為此而努力。SQL/XML 定義可從以下 URI 中得到:
http://standards.iso.org/iso/9075/2002/12/sqlxml網要定義從以下三個不同方面描述
RowSet 物件的內部資料:
RowSet 屬性之外,這些屬性還描述標準同步提供者屬性。
WebRowSet 物件管理的表格結構關聯的元資料。描述的元資料與在底層 java.sql.ResultSet 介面中可存取的元資料是緊密聯繫在一起的。
WebRowSet 物件的上一次填充或上一次同步以來的資料狀態)和當前資料。通過追蹤原始資料和當前資料之間的 delta,WebRowSet 維持其資料中的更改與原始資料源同步的能力。
WebRowSet 實作應該如何使用 XML 網要來描述更新、插入和刪除操作,以及描述 XML 中 WebRowSet 物件的狀態。
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 標記可能包含 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>
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>
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>
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 |
| 方法摘要 | |
|---|---|
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 物件。 |
| 從介面 java.sql.Wrapper 繼承的方法 |
|---|
isWrapperFor, unwrap |
| 從介面 javax.sql.rowset.Joinable 繼承的方法 |
|---|
getMatchColumnIndexes, getMatchColumnNames, setMatchColumn, setMatchColumn, setMatchColumn, setMatchColumn, unsetMatchColumn, unsetMatchColumn, unsetMatchColumn, unsetMatchColumn |
| 欄位詳細資訊 |
|---|
static final String PUBLIC_XML_SCHEMA
WebRowSet 實作定義 XML 標記及其有效值的 XML 網要定義的公共標識符。
static final String SCHEMA_SYSTEM_ID
WebRowSet 實作定義 XML 標記及其有效值的 XML 網要定義的 URL。
| 方法詳細資訊 |
|---|
void readXml(Reader reader)
throws SQLException
Reader 物件以其 XML 格式讀取 WebRowSet 物件。
reader - 用於填充此 WebRowSet 物件的 java.io.Reader 串流。
SQLException - 如果發生資料庫存取錯誤
void readXml(InputStream iStream)
throws SQLException,
IOException
WebRowSet 物件。
iStream - 用來填充此 WebRowSet 物件的 java.io.InputStream
SQLException - 如果發生資料源存取錯誤
IOException - 如果發生 IO 異常
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 內容時發生錯誤
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 異常
void writeXml(Writer writer)
throws SQLException
WebRowSet 物件的資料、屬性和元資料寫入給定的 Writer 物件。
writer - 要寫入的 java.io.Writer 串流
SQLException - 如果在將 rowset 內容寫出到 XML 時出錯
void writeXml(OutputStream oStream)
throws SQLException,
IOException
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。