src/java.sql.rowset/share/classes/javax/sql/rowset/Predicate.java
author pliden
Wed, 20 Nov 2019 10:37:46 +0100
changeset 59152 59272e9e0635
parent 54106 9a90236ab64c
permissions -rw-r--r--
8234383: Test TestBiasedLockRevocationEvents.java assumes -XX:UseBiasedLocking is enabled Reviewed-by: mgronlun, tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
54106
9a90236ab64c 8220253: Fix Headings in java.sql.rowset
lancea
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.sql.rowset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.sql.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.sql.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * The standard interface that provides the framework for all
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * <code>FilteredRowSet</code> objects to describe their filters.
20880
1b610151b316 8026812: doclint clean up for java.sql and javax.sql
lancea
parents: 19868
diff changeset
    34
 *
54106
9a90236ab64c 8220253: Fix Headings in java.sql.rowset
lancea
parents: 47216
diff changeset
    35
 * <h2>1.0 Background</h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * The <code>Predicate</code> interface is a standard interface that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * applications can implement to define the filter they wish to apply to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * a <code>FilteredRowSet</code> object. A <code>FilteredRowSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * object consumes implementations of this interface and enforces the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * constraints defined in the implementation of the method <code>evaluate</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * A <code>FilteredRowSet</code> object enforces the filter constraints in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * bi-directional manner: It outputs only rows that are within
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * the constraints of the filter; and conversely, it inserts, modifies, or updates
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * only rows that are within the constraints of the filter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
54106
9a90236ab64c 8220253: Fix Headings in java.sql.rowset
lancea
parents: 47216
diff changeset
    46
 * <h2>2.0 Implementation Guidelines</h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * In order to supply a predicate for the <code>FilteredRowSet</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * this interface must be implemented.  At this time, the JDBC RowSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Implementations (JSR-114) does not specify any standard filters definitions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * By specifying a standard means and mechanism for a range of filters to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * defined and deployed with both the reference and vendor implementations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * of the <code>FilteredRowSet</code> interface, this allows for a flexible
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * and application motivated implementations of <code>Predicate</code> to emerge.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * A sample implementation would look something like this:
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 5506
diff changeset
    56
 * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *    public class Range implements Predicate {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
19868
37b6dcade23a 7097386: Correct error in Predicate javadoc example
lancea
parents: 18564
diff changeset
    59
 *       private int[] lo;
37b6dcade23a 7097386: Correct error in Predicate javadoc example
lancea
parents: 18564
diff changeset
    60
 *       private int[] hi;
37b6dcade23a 7097386: Correct error in Predicate javadoc example
lancea
parents: 18564
diff changeset
    61
 *       private int[] idx;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *
19868
37b6dcade23a 7097386: Correct error in Predicate javadoc example
lancea
parents: 18564
diff changeset
    63
 *       public Range(int[] lo, int[] hi, int[] idx) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *          this.lo = lo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *          this.hi = hi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *          this.idx = idx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *      public boolean evaluate(RowSet rs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *          // Check the present row determine if it lies
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *          // within the filtering criteria.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *          for (int i = 0; i < idx.length; i++) {
19868
37b6dcade23a 7097386: Correct error in Predicate javadoc example
lancea
parents: 18564
diff changeset
    75
 *             int value;
37b6dcade23a 7097386: Correct error in Predicate javadoc example
lancea
parents: 18564
diff changeset
    76
 *             try {
37b6dcade23a 7097386: Correct error in Predicate javadoc example
lancea
parents: 18564
diff changeset
    77
 *                 value = (Integer) rs.getObject(idx[i]);
37b6dcade23a 7097386: Correct error in Predicate javadoc example
lancea
parents: 18564
diff changeset
    78
 *             } catch (SQLException ex) {
37b6dcade23a 7097386: Correct error in Predicate javadoc example
lancea
parents: 18564
diff changeset
    79
 *                 Logger.getLogger(Range.class.getName()).log(Level.SEVERE, null, ex);
37b6dcade23a 7097386: Correct error in Predicate javadoc example
lancea
parents: 18564
diff changeset
    80
 *                 return false;
37b6dcade23a 7097386: Correct error in Predicate javadoc example
lancea
parents: 18564
diff changeset
    81
 *             }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *
19868
37b6dcade23a 7097386: Correct error in Predicate javadoc example
lancea
parents: 18564
diff changeset
    83
 *             if (value < lo[i] && value > hi[i]) {
37b6dcade23a 7097386: Correct error in Predicate javadoc example
lancea
parents: 18564
diff changeset
    84
 *                 // outside of filter constraints
37b6dcade23a 7097386: Correct error in Predicate javadoc example
lancea
parents: 18564
diff changeset
    85
 *                 return false;
37b6dcade23a 7097386: Correct error in Predicate javadoc example
lancea
parents: 18564
diff changeset
    86
 *             }
37b6dcade23a 7097386: Correct error in Predicate javadoc example
lancea
parents: 18564
diff changeset
    87
 *         }
37b6dcade23a 7097386: Correct error in Predicate javadoc example
lancea
parents: 18564
diff changeset
    88
 *         // Within filter constraints
37b6dcade23a 7097386: Correct error in Predicate javadoc example
lancea
parents: 18564
diff changeset
    89
 *        return true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *      }
19868
37b6dcade23a 7097386: Correct error in Predicate javadoc example
lancea
parents: 18564
diff changeset
    91
 *   }
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 5506
diff changeset
    92
 * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * The example above implements a simple range predicate. Note, that
19868
37b6dcade23a 7097386: Correct error in Predicate javadoc example
lancea
parents: 18564
diff changeset
    95
 * implementations should but are not required to provide <code>String</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * and integer index based constructors to provide for JDBC RowSet Implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * applications that use both column identification conventions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * @author Jonathan Bruce, Amit Handa
24968
3308660aa3f2 8046389: Add missing @since tag under javax.sql.**
henryjen
parents: 21278
diff changeset
   100
 * @since 1.5
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
54106
9a90236ab64c 8220253: Fix Headings in java.sql.rowset
lancea
parents: 47216
diff changeset
   104
 // <h2>3.0 FilteredRowSet Internals</h2>
25976
4de01a56e3ee 8054555: javadoc cleanup for java.sql and javax.sql
lancea
parents: 24968
diff changeset
   105
 // internalNext, First, Last. Discuss guidelines on how to approach this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 // and cite examples in reference implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
public interface Predicate {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * This method is typically called a <code>FilteredRowSet</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * internal methods (not public) that control the <code>RowSet</code> object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * cursor moving  from row to the next. In addition, if this internal method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * moves the cursor onto a row that has been deleted, the internal method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * continue to ove the cursor until a valid row is found.
18564
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18156
diff changeset
   114
     * @param rs The {@code RowSet} to be evaluated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @return <code>true</code> if there are more rows in the filter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *     <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public boolean evaluate(RowSet rs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * This method is called by a <code>FilteredRowSet</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * to check whether the value lies between the filtering criterion (or criteria
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * if multiple constraints exist) set using the <code>setFilter()</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * The <code>FilteredRowSet</code> object will use this method internally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * while inserting new rows to a <code>FilteredRowSet</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @param value An <code>Object</code> value which needs to be checked,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *        whether it can be part of this <code>FilterRowSet</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @param column a <code>int</code> object that must match the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *        SQL index of a column in this <code>RowSet</code> object. This must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *        have been passed to <code>Predicate</code> as one of the columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *        for filtering while initializing a <code>Predicate</code>
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20880
diff changeset
   135
     * @return <code>true</code> if row value lies within the filter;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *     <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @throws SQLException if the column is not part of filtering criteria
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public boolean evaluate(Object value, int column) throws SQLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * This method is called by the <code>FilteredRowSet</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * to check whether the value lies between the filtering criteria set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * using the setFilter method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * The <code>FilteredRowSet</code> object will use this method internally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * while inserting new rows to a <code>FilteredRowSet</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @param value An <code>Object</code> value which needs to be checked,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * whether it can be part of this <code>FilterRowSet</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @param columnName a <code>String</code> object that must match the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *        SQL name of a column in this <code>RowSet</code>, ignoring case. This must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *        have been passed to <code>Predicate</code> as one of the columns for filtering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *        while initializing a <code>Predicate</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @return <code>true</code> if value lies within the filter; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @throws SQLException if the column is not part of filtering criteria
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public boolean evaluate(Object value, String columnName) throws SQLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
}