1. /*
  2. * @(#)FilteredRowSet.java 1.7 04/05/29
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.sql.rowset;
  8. import java.sql.*;
  9. import javax.sql.*;
  10. import javax.naming.*;
  11. import java.io.*;
  12. import java.math.*;
  13. /**
  14. * The standard interface that all standard implementations of
  15. * <code>FilteredRowSet</code> must implement. The <code>FilteredRowSetImpl</code> class
  16. * provides the reference implementation which may be extended if required.
  17. * Alternatively, a vendor is free to implement its own version
  18. * by implementing this interface.
  19. *
  20. * <h3>1.0 Background</h3>
  21. *
  22. * There are occasions when a <code>RowSet</code> object has a need to provide a degree
  23. * of filtering to its contents. One possible solution is to provide
  24. * a query language for all standard <code>RowSet</code> implementations; however,
  25. * this is an impractical approach for lightweight components such as disconnected
  26. * <code>RowSet</code>
  27. * objects. The <code>FilteredRowSet</code> interface seeks to address this need
  28. * without supplying a heavyweight query language along with the processing that
  29. * such a query language would require.
  30. * <p>
  31. * A JDBC <code>FilteredRowSet</code> standard implementation implements the
  32. * <code>RowSet</code> interfaces and extends the
  33. * <code>CachedRowSet</code><sup><font size=-2>TM</font></sup> class. The
  34. * <code>CachedRowSet</code> class provides a set of protected cursor manipulation
  35. * methods, which a <code>FilteredRowSet</code> implementation can override
  36. * to supply filtering support.
  37. *
  38. * <h3>2.0 Predicate Sharing</h3>
  39. *
  40. * If a <code>FilteredRowSet</code> implementation is shared using the
  41. * inherited <code>createShared</code> method in parent interfaces, the
  42. * <code>Predicate</code> should be shared without modification by all
  43. * <code>FilteredRowSet</code> instance clones.
  44. *
  45. * <h3>3.0 Usage</h3>
  46. * <p>
  47. * By implementing a <code>Predicate</code> (see example in <a href="Predicate.html">Predicate</a>
  48. * class JavaDoc), a <code>FilteredRowSet</code> could then be used as described
  49. * below.
  50. * <P>
  51. * <code>
  52. * <pre>
  53. * FilteredRowSet frs = new FilteredRowSetImpl();
  54. * frs.populate(rs);
  55. *
  56. * Range name = new Range("Alpha", "Bravo", "columnName");
  57. * frs.setFilter(name);
  58. *
  59. * frs.next() // only names from "Alpha" to "Bravo" will be returned
  60. * </pre>
  61. * </code>
  62. * In the example above, we initialize a <code>Range</code> object which
  63. * implements the <code>Predicate</code> interface. This object expresses
  64. * the following constraints: All rows outputted or modified from this
  65. * <code>FilteredRowSet</code> object must fall between the values 'Alpha' and
  66. * 'Bravo' both values inclusive, in the column 'columnName'. If a filter is
  67. * applied to a <code>FilteredRowSet</code> object that contains no data that
  68. * falls within the range of the filter, no rows are returned.
  69. * <p>
  70. * This framework allows multiple classes implementing predicates to be
  71. * used in combination to achieved the required filtering result with
  72. * out the need for query language processing.
  73. * <p>
  74. * <h3>4.0 Updating a <code>FilteredRowSet</code> Object</h3>
  75. * The predicate set on a <code>FilteredRowSet</code> object
  76. * applies a criterion on all rows in a
  77. * <code>RowSet</code> object to manage a subset of rows in a <code>RowSet</code>
  78. * object. This criterion governs the subset of rows that are visible and also
  79. * defines which rows can be modified, deleted or inserted.
  80. * <p>
  81. * Therefore, the predicate set on a <code>FilteredRowSet</code> object must be
  82. * considered as bi-directional and the set criterion as the gating mechanism
  83. * for all views and updates to the <code>FilteredRowSet</code> object. Any attempt
  84. * to update the <code>FilteredRowSet</code> that violates the criterion will
  85. * result in a <code>SQLException</code> object being thrown.
  86. * <p>
  87. * The <code>FilteredRowSet</code> range criterion can be modified by applying
  88. * a new <code>Predicate</code> object to the <code>FilteredRowSet</code>
  89. * instance at any time. This is possible if no additional references to the
  90. * <code>FilteredRowSet</code> object are detected. A new filter has has an
  91. * immediate effect on criterion enforcement within the
  92. * <code>FilteredRowSet</code> object, and all subsequent views and updates will be
  93. * subject to similar enforcement.
  94. * <p>
  95. * <h3>5.0 Behavior of Rows Outside the Filter</h3>
  96. * Rows that fall outside of the filter set on a <code>FilteredRowSet</code>
  97. * object cannot be modified until the filter is removed or a
  98. * new filter is applied.
  99. * <p>
  100. * Furthermore, only rows that fall within the bounds of a filter will be
  101. * synchronized with the data source.
  102. *
  103. * @author Jonathan Bruce
  104. */
  105. public interface FilteredRowSet extends WebRowSet {
  106. /**
  107. * Applies the given <code>Predicate</code> object to this
  108. * <code>FilteredRowSet</code>
  109. * object. The filter applies controls both to inbound and outbound views,
  110. * constraining which rows are visible and which
  111. * rows can be manipulated.
  112. * <p>
  113. * A new <code>Predicate</code> object may be set at any time. This has the
  114. * effect of changing constraints on the <code>RowSet</code> object's data.
  115. * In addition, modifying the filter at runtime presents issues whereby
  116. * multiple components may be operating on one <code>FilteredRowSet</code> object.
  117. * Application developers must take responsibility for managing multiple handles
  118. * to <code>FilteredRowSet</code> objects when their underling <code>Predicate</code>
  119. * objects change.
  120. *
  121. * @param p a <code>Predicate</code> object defining the filter for this
  122. * <code>FilteredRowSet</code> object. Setting a <b>null</b> value
  123. * will clear the predicate, allowing all rows to become visible.
  124. *
  125. * @throws SQLException if an error occurs when setting the
  126. * <code>Predicate</code> object
  127. */
  128. public void setFilter(Predicate p) throws SQLException;
  129. /**
  130. * Retrieves the active filter for this <code>FilteredRowSet</code> object.
  131. *
  132. * @return p the <code>Predicate</code> for this <code>FilteredRowSet</code>
  133. * object; <code>null</code> if no filter has been set.
  134. */
  135. public Predicate getFilter() ;
  136. }