1 package com.quadcap.sql; 2 3 40 41 import java.util.Vector ; 42 43 import java.sql.SQLException ; 44 45 import com.quadcap.sql.types.Value; 46 import com.quadcap.sql.types.ValueBoolean; 47 import com.quadcap.sql.types.ValueUnknown; 48 49 import com.quadcap.util.Debug; 50 51 56 public class PredicateCursor extends FilterCursor { 57 Expression predicate = null; 58 Row row = null; 59 60 64 public PredicateCursor(Session session, Cursor cursor, 65 Expression predicate) throws SQLException { 66 super(session, cursor); 67 this.predicate = predicate; 68 } 69 70 73 public Row getRow() throws SQLException { 74 return row; 75 } 76 77 81 public boolean next() throws SQLException { 82 row = null; 83 while (row == null && cursor.next()) { 84 Value val = predicate.getValue(session, cursor); 85 if (Value.isTrue(val)) { 88 row = cursor.getRow(); 89 } 90 } 91 return row != null; 92 } 93 94 98 public boolean prev() throws SQLException { 99 row = null; 100 while (row == null && cursor.prev()) { 101 Value val = predicate.getValue(session, cursor); 102 if (Value.isTrue(val)) { 103 row = cursor.getRow(); 104 } 105 } 106 return row != null; 107 } 108 109 113 public boolean absolute(int row) throws SQLException { 114 if (row > 0) { 115 beforeFirst(); 116 while (row-- > 0) if (!next()) return false; 117 } else { 118 afterLast(); 119 while (row++ < 0) if (!prev()) return false; 120 } 121 return true; 122 } 123 124 125 public String toString() { 127 return "PredicateCursor: " + super.toString(); 128 } 129 131 } 132 | Popular Tags |