Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/sql/rowset/Predicate.java
38918 views
/*1* Copyright (c) 2003, 2013, 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 javax.sql.*;28import java.sql.*;2930/**31* The standard interface that provides the framework for all32* <code>FilteredRowSet</code> objects to describe their filters.33*34* <h3>1.0 Background</h3>35* The <code>Predicate</code> interface is a standard interface that36* applications can implement to define the filter they wish to apply to a37* a <code>FilteredRowSet</code> object. A <code>FilteredRowSet</code>38* object consumes implementations of this interface and enforces the39* constraints defined in the implementation of the method <code>evaluate</code>.40* A <code>FilteredRowSet</code> object enforces the filter constraints in a41* bi-directional manner: It outputs only rows that are within42* the constraints of the filter; and conversely, it inserts, modifies, or updates43* only rows that are within the constraints of the filter.44*45* <h3>2.0 Implementation Guidelines</h3>46* In order to supply a predicate for the <code>FilteredRowSet</code>.47* this interface must be implemented. At this time, the JDBC RowSet48* Implementations (JSR-114) does not specify any standard filters definitions.49* By specifying a standard means and mechanism for a range of filters to be50* defined and deployed with both the reference and vendor implementations51* of the <code>FilteredRowSet</code> interface, this allows for a flexible52* and application motivated implementations of <code>Predicate</code> to emerge.53* <p>54* A sample implementation would look something like this:55* <pre>{@code56* public class Range implements Predicate {57*58* private int[] lo;59* private int[] hi;60* private int[] idx;61*62* public Range(int[] lo, int[] hi, int[] idx) {63* this.lo = lo;64* this.hi = hi;65* this.idx = idx;66* }67*68* public boolean evaluate(RowSet rs) {69*70* // Check the present row determine if it lies71* // within the filtering criteria.72*73* for (int i = 0; i < idx.length; i++) {74* int value;75* try {76* value = (Integer) rs.getObject(idx[i]);77* } catch (SQLException ex) {78* Logger.getLogger(Range.class.getName()).log(Level.SEVERE, null, ex);79* return false;80* }81*82* if (value < lo[i] && value > hi[i]) {83* // outside of filter constraints84* return false;85* }86* }87* // Within filter constraints88* return true;89* }90* }91* }</pre>92* <P>93* The example above implements a simple range predicate. Note, that94* implementations should but are not required to provide <code>String</code>95* and integer index based constructors to provide for JDBC RowSet Implementation96* applications that use both column identification conventions.97*98* @author Jonathan Bruce, Amit Handa99*100*/101102// <h3>3.0 FilteredRowSet Internals</h3>103// internalNext, Frist, Last. Discuss guidelines on how to approach this104// and cite examples in reference implementations.105public interface Predicate {106/**107* This method is typically called a <code>FilteredRowSet</code> object108* internal methods (not public) that control the <code>RowSet</code> object's109* cursor moving from row to the next. In addition, if this internal method110* moves the cursor onto a row that has been deleted, the internal method will111* continue to ove the cursor until a valid row is found.112* @param rs The {@code RowSet} to be evaluated113* @return <code>true</code> if there are more rows in the filter;114* <code>false</code> otherwise115*/116public boolean evaluate(RowSet rs);117118119/**120* This method is called by a <code>FilteredRowSet</code> object121* to check whether the value lies between the filtering criterion (or criteria122* if multiple constraints exist) set using the <code>setFilter()</code> method.123* <P>124* The <code>FilteredRowSet</code> object will use this method internally125* while inserting new rows to a <code>FilteredRowSet</code> instance.126*127* @param value An <code>Object</code> value which needs to be checked,128* whether it can be part of this <code>FilterRowSet</code> object.129* @param column a <code>int</code> object that must match the130* SQL index of a column in this <code>RowSet</code> object. This must131* have been passed to <code>Predicate</code> as one of the columns132* for filtering while initializing a <code>Predicate</code>133* @return <code>true</code> if row value lies within the filter;134* <code>false</code> otherwise135* @throws SQLException if the column is not part of filtering criteria136*/137public boolean evaluate(Object value, int column) throws SQLException;138139/**140* This method is called by the <code>FilteredRowSet</code> object141* to check whether the value lies between the filtering criteria set142* using the setFilter method.143* <P>144* The <code>FilteredRowSet</code> object will use this method internally145* while inserting new rows to a <code>FilteredRowSet</code> instance.146*147* @param value An <code>Object</code> value which needs to be checked,148* whether it can be part of this <code>FilterRowSet</code>.149*150* @param columnName a <code>String</code> object that must match the151* SQL name of a column in this <code>RowSet</code>, ignoring case. This must152* have been passed to <code>Predicate</code> as one of the columns for filtering153* while initializing a <code>Predicate</code>154*155* @return <code>true</code> if value lies within the filter; <code>false</code> otherwise156*157* @throws SQLException if the column is not part of filtering criteria158*/159public boolean evaluate(Object value, String columnName) throws SQLException;160161}162163164