src/java.sql.rowset/share/classes/javax/sql/rowset/FilteredRowSet.java
author lancea
Wed, 13 Mar 2019 14:10:18 -0400
changeset 54106 9a90236ab64c
parent 47216 71c04702a3d5
permissions -rw-r--r--
8220253: Fix Headings in java.sql.rowset Reviewed-by: darcy
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 java.sql.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.sql.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.naming.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.math.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * The standard interface that all standard implementations of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <code>FilteredRowSet</code> must implement. The <code>FilteredRowSetImpl</code> class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * provides the reference implementation which may be extended if required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Alternatively, a vendor is free to implement its own version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * by implementing this interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
54106
9a90236ab64c 8220253: Fix Headings in java.sql.rowset
lancea
parents: 47216
diff changeset
    41
 * <h2>1.0 Background</h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * There are occasions when a <code>RowSet</code> object has a need to provide a degree
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * of filtering to its contents. One possible solution is to provide
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * a query language for all standard <code>RowSet</code> implementations; however,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * this is an impractical approach for lightweight components such as disconnected
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <code>RowSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * objects. The <code>FilteredRowSet</code> interface seeks to address this need
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * without supplying a heavyweight query language along with the processing that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * such a query language would require.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * A JDBC <code>FilteredRowSet</code> standard implementation implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <code>RowSet</code> interfaces and extends the
18564
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 5506
diff changeset
    54
 * <code>CachedRowSet</code>&trade; class. The
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <code>CachedRowSet</code> class provides a set of protected cursor manipulation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * methods, which a <code>FilteredRowSet</code> implementation can override
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * to supply filtering support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
54106
9a90236ab64c 8220253: Fix Headings in java.sql.rowset
lancea
parents: 47216
diff changeset
    59
 * <h2>2.0 Predicate Sharing</h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * If a <code>FilteredRowSet</code> implementation is shared using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * inherited <code>createShared</code> method in parent interfaces, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <code>Predicate</code> should be shared without modification by all
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <code>FilteredRowSet</code> instance clones.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
54106
9a90236ab64c 8220253: Fix Headings in java.sql.rowset
lancea
parents: 47216
diff changeset
    66
 * <h2>3.0 Usage</h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * By implementing a <code>Predicate</code> (see example in <a href="Predicate.html">Predicate</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * class JavaDoc), a <code>FilteredRowSet</code> could then be used as described
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * below.
20880
1b610151b316 8026812: doclint clean up for java.sql and javax.sql
lancea
parents: 18564
diff changeset
    71
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <pre>
18564
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 5506
diff changeset
    73
 * {@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *     FilteredRowSet frs = new FilteredRowSetImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *     frs.populate(rs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *     Range name = new Range("Alpha", "Bravo", "columnName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *     frs.setFilter(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *     frs.next() // only names from "Alpha" to "Bravo" will be returned
18564
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 5506
diff changeset
    81
 * }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * In the example above, we initialize a <code>Range</code> object which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * implements the <code>Predicate</code> interface. This object expresses
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * the following constraints: All rows outputted or modified from this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * <code>FilteredRowSet</code> object must fall between the values 'Alpha' and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * 'Bravo' both values inclusive, in the column 'columnName'. If a filter is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * applied to a <code>FilteredRowSet</code> object that contains no data that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * falls within the range of the filter, no rows are returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * This framework allows multiple classes implementing predicates to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * used in combination to achieved the required filtering result with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * out the need for query language processing.
20880
1b610151b316 8026812: doclint clean up for java.sql and javax.sql
lancea
parents: 18564
diff changeset
    94
 *
54106
9a90236ab64c 8220253: Fix Headings in java.sql.rowset
lancea
parents: 47216
diff changeset
    95
 * <h2>4.0 Updating a <code>FilteredRowSet</code> Object</h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * The predicate set on a <code>FilteredRowSet</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * applies a criterion on all rows in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * <code>RowSet</code> object to manage a subset of rows in a <code>RowSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * object. This criterion governs the subset of rows that are visible and also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * defines which rows can be modified, deleted or inserted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * Therefore, the predicate set on a <code>FilteredRowSet</code> object must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * considered as bi-directional and the set criterion as the gating mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * for all views and updates to the <code>FilteredRowSet</code> object. Any attempt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * to update the <code>FilteredRowSet</code> that violates the criterion will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * result in a <code>SQLException</code> object being thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * The <code>FilteredRowSet</code> range criterion can be modified by applying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * a new <code>Predicate</code> object to the <code>FilteredRowSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * instance at any time. This is  possible if no additional references to the
25976
4de01a56e3ee 8054555: javadoc cleanup for java.sql and javax.sql
lancea
parents: 24968
diff changeset
   111
 * <code>FilteredRowSet</code> object are detected. A new filter has an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * immediate effect on criterion enforcement within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * <code>FilteredRowSet</code> object, and all subsequent views and updates will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * subject to similar enforcement.
20880
1b610151b316 8026812: doclint clean up for java.sql and javax.sql
lancea
parents: 18564
diff changeset
   115
 *
54106
9a90236ab64c 8220253: Fix Headings in java.sql.rowset
lancea
parents: 47216
diff changeset
   116
 * <h2>5.0 Behavior of Rows Outside the Filter</h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * Rows that fall outside of the filter set on a <code>FilteredRowSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * object cannot be modified until the filter is removed or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * new filter is applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * Furthermore, only rows that fall within the bounds of a filter will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * synchronized with the data source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * @author Jonathan Bruce
24968
3308660aa3f2 8046389: Add missing @since tag under javax.sql.**
henryjen
parents: 20880
diff changeset
   125
 * @since 1.5
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
public interface FilteredRowSet extends WebRowSet {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    * Applies the given <code>Predicate</code> object to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    * <code>FilteredRowSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    * object. The filter applies controls both to inbound and outbound views,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    * constraining which rows are visible and which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    * rows can be manipulated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    * A new <code>Predicate</code> object may be set at any time. This has the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    * effect of changing constraints on the <code>RowSet</code> object's data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    * In addition, modifying the filter at runtime presents issues whereby
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    * multiple components may be operating on one <code>FilteredRowSet</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    * Application developers must take responsibility for managing multiple handles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    * to <code>FilteredRowSet</code> objects when their underling <code>Predicate</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    * objects change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    * @param p a <code>Predicate</code> object defining the filter for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    * <code>FilteredRowSet</code> object. Setting a <b>null</b> value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    * will clear the predicate, allowing all rows to become visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    * @throws SQLException if an error occurs when setting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    *     <code>Predicate</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public void setFilter(Predicate p) throws SQLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    * Retrieves the active filter for this <code>FilteredRowSet</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    * @return p the <code>Predicate</code> for this <code>FilteredRowSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    * object; <code>null</code> if no filter has been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public Predicate getFilter() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
}