jdk/src/share/classes/javax/sql/rowset/Predicate.java
changeset 19868 37b6dcade23a
parent 18564 f9db68ff2cbb
child 20880 1b610151b316
equal deleted inserted replaced
19867:9918d2d14f78 19868:37b6dcade23a
    54  * <p>
    54  * <p>
    55  * A sample implementation would look something like this:
    55  * A sample implementation would look something like this:
    56  * <pre>{@code
    56  * <pre>{@code
    57  *    public class Range implements Predicate {
    57  *    public class Range implements Predicate {
    58  *
    58  *
    59  *       private Object lo[];
    59  *       private int[] lo;
    60  *       private Object hi[];
    60  *       private int[] hi;
    61  *       private int idx[];
    61  *       private int[] idx;
    62  *
    62  *
    63  *       public Range(Object[] lo, Object[] hi, int[] idx) {
    63  *       public Range(int[] lo, int[] hi, int[] idx) {
    64  *          this.lo = lo;
    64  *          this.lo = lo;
    65  *          this.hi = hi;
    65  *          this.hi = hi;
    66  *          this.idx = idx;
    66  *          this.idx = idx;
    67  *       }
    67  *       }
    68  *
    68  *
    69  *      public boolean evaluate(RowSet rs) {
    69  *      public boolean evaluate(RowSet rs) {
    70  *          CachedRowSet crs = (CachedRowSet)rs;
       
    71  *          boolean bool1,bool2;
       
    72  *
    70  *
    73  *          // Check the present row determine if it lies
    71  *          // Check the present row determine if it lies
    74  *          // within the filtering criteria.
    72  *          // within the filtering criteria.
    75  *
    73  *
    76  *          for (int i = 0; i < idx.length; i++) {
    74  *          for (int i = 0; i < idx.length; i++) {
       
    75  *             int value;
       
    76  *             try {
       
    77  *                 value = (Integer) rs.getObject(idx[i]);
       
    78  *             } catch (SQLException ex) {
       
    79  *                 Logger.getLogger(Range.class.getName()).log(Level.SEVERE, null, ex);
       
    80  *                 return false;
       
    81  *             }
    77  *
    82  *
    78  *              if ((rs.getObject(idx[i]) >= lo[i]) &&
    83  *             if (value < lo[i] && value > hi[i]) {
    79  *                  (rs.getObject(idx[i]) >= hi[i]) {
    84  *                 // outside of filter constraints
    80  *                  bool1 = true; // within filter constraints
    85  *                 return false;
    81  *              } else {
    86  *             }
    82  *                  bool2 = true; // outside of filter constraints
    87  *         }
    83  *              }
    88  *         // Within filter constraints
    84  *          }
    89  *        return true;
    85  *
       
    86  *          if (bool2) {
       
    87  *             return false;
       
    88  *          } else {
       
    89  *             return true;
       
    90  *          }
       
    91  *      }
    90  *      }
    92  *  }
    91  *   }
    93  * }</pre>
    92  * }</pre>
    94  * <P>
    93  * <P>
    95  * The example above implements a simple range predicate. Note, that
    94  * The example above implements a simple range predicate. Note, that
    96  * implementations should but are not required to provider <code>String</code>
    95  * implementations should but are not required to provide <code>String</code>
    97  * and integer index based constructors to provide for JDBC RowSet Implementation
    96  * and integer index based constructors to provide for JDBC RowSet Implementation
    98  * applications that use both column identification conventions.
    97  * applications that use both column identification conventions.
    99  *
    98  *
   100  * @author Jonathan Bruce, Amit Handa
    99  * @author Jonathan Bruce, Amit Handa
   101  *
   100  *