JavaTM Platform
Standard Ed. 6

javax.sql.rowset
接口 FilteredRowSet

所有超级接口:
CachedRowSet, Joinable, ResultSet, RowSet, WebRowSet, Wrapper

public interface FilteredRowSet
extends WebRowSet

所有标准 FilteredRowSet 实现都必须实现的标准接口。FilteredRowSetImpl 类提供了可在需要时扩展的参考实现。另外,供应商可通过实现此接口来随意实现其自己的版本。

1.0 背景

有时 RowSet 对象需要对其内容进行某种程度的过滤。一种可能的解决方案是为所有标准的 RowSet 实现提供一种查询语言;但是这对诸如非连接 RowSet 对象之类的轻量级组件而言是一种不切实际的方法。FilteredRowSet 接口寻求在不提供重量级查询语言和这种查询语言所需处理的情况下解决这一需求问题。

JDBC FilteredRowSet 标准实现可实现 RowSet 接口并扩展 CachedRowSetTM 类。CachedRowSet 类提供了一组受保护的光标操纵方法,FilteredRowSet 实现可重写这些方法将来提供过滤支持。

2.0 Predicate 共享

如果使用父接口中继承的 createShared 方法共享了 FilteredRowSet 实现,则应所有 FilteredRowSet 实例副本应共享 Predicate 并不做任何修改。

3.0 使用

通过实现 Predicate(请参阅 Predicate 类 JavaDoc 中的示例),便可以按下述方式使用 FilteredRowSet

     FilteredRowSet frs = new FilteredRowSetImpl();
     frs.populate(rs);
 
     Range name = new Range("Alpha", "Bravo", "columnName");
     frs.setFilter(name);
 
     frs.next() // only names from "Alpha" to "Bravo" will be returned
 
在上面的示例中,我们初始化了一个 Range 对象,它实现了 Predicate 接口。此对象表示以下约束条件:从此 FilteredRowSet 对象输出或修改的所有行必须在列 'columnName' 中,在值 'Alpha' 和 'Bravo' 之间(包括这两个值)。如果对不包含过滤器范围内的数据的 FilteredRowSet 对象应用过滤器,则不返回任何行。

此框架允许多个类实现 predicate,从而能以组合方式使用其来达到所需的过滤结果,无需进行查询语言处理。

4.0 更新 FilteredRowSet 对象

FilteredRowSet 对象上设置的 predicate 对 RowSet 对象中的所有行应用了一个标准,用来管理 RowSet 对象中的一个行子集。此标准控制可见的行子集,定义可以被修改、删除或插入的列。

因此,必须将 FilteredRowSet 对象上设置的 predicate 视为双向的,将设置的标准视为 FilteredRowSet 对象的所有视图和更新的控制机制。试图更新违反该标准的 FilteredRowSet 将导致抛出 SQLException 对象。

可在任何时间向 FilteredRowSet 实例应用新的 Predicate 对象来修改 FilteredRowSet 范围标准。如果没有检测到对 FilteredRowSet 对象的任何附加引用,则修改范围标准是可能的。新的过滤器对 FilteredRowSet 对象内所执行的标准会立即产生影响,所有后续视图和更新都将受到类似执行的影响。

5.0 过滤器外部各行的行为

在移除过滤器或应用新的过滤器之前,不能修改那些位于 FilteredRowSet 对象上设置的过滤器范围外的各行。

此外,只有位于过滤器范围内的各行才与数据源同步。


字段摘要
 
从接口 javax.sql.rowset.WebRowSet 继承的字段
PUBLIC_XML_SCHEMA, SCHEMA_SYSTEM_ID
 
从接口 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
 
方法摘要
 Predicate getFilter()
          获取此 FilteredRowSet 对象的活动过滤器。
 void setFilter(Predicate p)
          将给定的 Predicate 对象应用到此 FilteredRowSet 对象。
 
从接口 javax.sql.rowset.WebRowSet 继承的方法
readXml, readXml, writeXml, writeXml, writeXml, writeXml
 
从接口 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
 

方法详细信息

setFilter

void setFilter(Predicate p)
               throws SQLException
将给定的 Predicate 对象应用到此 FilteredRowSet 对象。过滤器同时控制入境 (inbound) 视图和出境 (outbound) 视图,限制哪些行是可见的,哪些行是可以操作的。

可以在任何时间设置新的 Predicate 对象。这样可以更改 RowSet 对象数据上的约束条件。另外,在运行时修改过滤器会出现问题,所以多个组件可以在一个 FilteredRowSet 对象上进行操作。当 FilteredRowSet 对象的底层 Predicate 对象更改时,应用程序开发人员必须负责管理对 FilteredRowSet 对象的多重处理。

参数:
p - Predicate 对象,它定义了此 FilteredRowSet 对象的过滤器。设置 null 值将清除 predicate,允许所有行成为可见行。
抛出:
SQLException - 如果在设置 Predicate 对象时发生错误

getFilter

Predicate getFilter()
获取此 FilteredRowSet 对象的活动过滤器。

返回:
FilteredRowSet 对象的 Predicate;如果没有设置过滤器,则返回 null

JavaTM Platform
Standard Ed. 6

提交错误或意见
有关更多的 API 参考资料和开发人员文档,请参阅 Java SE 开发人员文档。该文档包含更详细的、面向开发人员的描述,以及总体概述、术语定义、使用技巧和工作代码示例。

版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策