author | coleenp |
Wed, 28 Jun 2017 19:12:58 -0400 | |
changeset 46589 | f1c04490ded1 |
parent 25991 | e48157b42439 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
25976
4de01a56e3ee
8054555: javadoc cleanup for java.sql and javax.sql
lancea
parents:
24968
diff
changeset
|
2 |
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package javax.sql.rowset; |
|
27 |
||
28 |
import javax.sql.*; |
|
29 |
import java.sql.*; |
|
30 |
||
31 |
/** |
|
32 |
* The standard interface that provides the framework for all |
|
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 |
* |
2 | 35 |
* <h3>1.0 Background</h3> |
36 |
* The <code>Predicate</code> interface is a standard interface that |
|
37 |
* applications can implement to define the filter they wish to apply to a |
|
38 |
* a <code>FilteredRowSet</code> object. A <code>FilteredRowSet</code> |
|
39 |
* object consumes implementations of this interface and enforces the |
|
40 |
* constraints defined in the implementation of the method <code>evaluate</code>. |
|
41 |
* A <code>FilteredRowSet</code> object enforces the filter constraints in a |
|
42 |
* bi-directional manner: It outputs only rows that are within |
|
43 |
* the constraints of the filter; and conversely, it inserts, modifies, or updates |
|
44 |
* only rows that are within the constraints of the filter. |
|
45 |
* |
|
46 |
* <h3>2.0 Implementation Guidelines</h3> |
|
47 |
* In order to supply a predicate for the <code>FilteredRowSet</code>. |
|
48 |
* this interface must be implemented. At this time, the JDBC RowSet |
|
49 |
* Implementations (JSR-114) does not specify any standard filters definitions. |
|
50 |
* By specifying a standard means and mechanism for a range of filters to be |
|
51 |
* defined and deployed with both the reference and vendor implementations |
|
52 |
* of the <code>FilteredRowSet</code> interface, this allows for a flexible |
|
53 |
* and application motivated implementations of <code>Predicate</code> to emerge. |
|
54 |
* <p> |
|
55 |
* A sample implementation would look something like this: |
|
18156 | 56 |
* <pre>{@code |
2 | 57 |
* public class Range implements Predicate { |
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 | 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 | 64 |
* this.lo = lo; |
65 |
* this.hi = hi; |
|
66 |
* this.idx = idx; |
|
67 |
* } |
|
68 |
* |
|
69 |
* public boolean evaluate(RowSet rs) { |
|
70 |
* |
|
71 |
* // Check the present row determine if it lies |
|
72 |
* // within the filtering criteria. |
|
73 |
* |
|
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 | 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 | 90 |
* } |
19868
37b6dcade23a
7097386: Correct error in Predicate javadoc example
lancea
parents:
18564
diff
changeset
|
91 |
* } |
18156 | 92 |
* }</pre> |
2 | 93 |
* <P> |
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 | 96 |
* and integer index based constructors to provide for JDBC RowSet Implementation |
97 |
* applications that use both column identification conventions. |
|
98 |
* |
|
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 | 101 |
* |
102 |
*/ |
|
103 |
||
104 |
// <h3>3.0 FilteredRowSet Internals</h3> |
|
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 | 106 |
// and cite examples in reference implementations. |
107 |
public interface Predicate { |
|
108 |
/** |
|
109 |
* This method is typically called a <code>FilteredRowSet</code> object |
|
110 |
* internal methods (not public) that control the <code>RowSet</code> object's |
|
111 |
* cursor moving from row to the next. In addition, if this internal method |
|
112 |
* moves the cursor onto a row that has been deleted, the internal method will |
|
113 |
* continue to ove the cursor until a valid row is found. |
|
18564 | 114 |
* @param rs The {@code RowSet} to be evaluated |
2 | 115 |
* @return <code>true</code> if there are more rows in the filter; |
116 |
* <code>false</code> otherwise |
|
117 |
*/ |
|
118 |
public boolean evaluate(RowSet rs); |
|
119 |
||
120 |
||
121 |
/** |
|
122 |
* This method is called by a <code>FilteredRowSet</code> object |
|
123 |
* to check whether the value lies between the filtering criterion (or criteria |
|
124 |
* if multiple constraints exist) set using the <code>setFilter()</code> method. |
|
125 |
* <P> |
|
126 |
* The <code>FilteredRowSet</code> object will use this method internally |
|
127 |
* while inserting new rows to a <code>FilteredRowSet</code> instance. |
|
128 |
* |
|
129 |
* @param value An <code>Object</code> value which needs to be checked, |
|
130 |
* whether it can be part of this <code>FilterRowSet</code> object. |
|
131 |
* @param column a <code>int</code> object that must match the |
|
132 |
* SQL index of a column in this <code>RowSet</code> object. This must |
|
133 |
* have been passed to <code>Predicate</code> as one of the columns |
|
134 |
* for filtering while initializing a <code>Predicate</code> |
|
21278 | 135 |
* @return <code>true</code> if row value lies within the filter; |
2 | 136 |
* <code>false</code> otherwise |
137 |
* @throws SQLException if the column is not part of filtering criteria |
|
138 |
*/ |
|
139 |
public boolean evaluate(Object value, int column) throws SQLException; |
|
140 |
||
141 |
/** |
|
142 |
* This method is called by the <code>FilteredRowSet</code> object |
|
143 |
* to check whether the value lies between the filtering criteria set |
|
144 |
* using the setFilter method. |
|
145 |
* <P> |
|
146 |
* The <code>FilteredRowSet</code> object will use this method internally |
|
147 |
* while inserting new rows to a <code>FilteredRowSet</code> instance. |
|
148 |
* |
|
149 |
* @param value An <code>Object</code> value which needs to be checked, |
|
150 |
* whether it can be part of this <code>FilterRowSet</code>. |
|
151 |
* |
|
152 |
* @param columnName a <code>String</code> object that must match the |
|
153 |
* SQL name of a column in this <code>RowSet</code>, ignoring case. This must |
|
154 |
* have been passed to <code>Predicate</code> as one of the columns for filtering |
|
155 |
* while initializing a <code>Predicate</code> |
|
156 |
* |
|
157 |
* @return <code>true</code> if value lies within the filter; <code>false</code> otherwise |
|
158 |
* |
|
159 |
* @throws SQLException if the column is not part of filtering criteria |
|
160 |
*/ |
|
161 |
public boolean evaluate(Object value, String columnName) throws SQLException; |
|
162 |
||
163 |
} |