1 5 package org.h2.index; 6 7 import java.sql.SQLException ; 8 9 import org.h2.engine.Session; 10 import org.h2.message.Message; 11 import org.h2.result.Row; 12 import org.h2.result.SearchRow; 13 import org.h2.table.Column; 14 import org.h2.table.RangeTable; 15 import org.h2.value.Value; 16 import org.h2.value.ValueLong; 17 18 public class RangeIndex extends Index { 19 20 private long min, max; 21 22 public RangeIndex(RangeTable table, Column[] columns, long min, long max) { 23 super(table, 0, "RANGE_INDEX", columns, IndexType.createNonUnique(true)); 24 this.min = min; 25 this.max = max; 26 } 27 28 public void close(Session session) throws SQLException { 29 } 30 31 public void add(Session session, Row row) throws SQLException { 32 throw Message.getUnsupportedException(); 33 } 34 35 public void remove(Session session, Row row) throws SQLException { 36 throw Message.getUnsupportedException(); 37 } 38 39 public Cursor find(Session session, SearchRow first, SearchRow last) throws SQLException { 40 long start = Math.max(min, first==null ? min : first.getValue(0).getLong()); 41 long end = Math.min(max, last==null ? max : last.getValue(0).getLong()); 42 return new RangeCursor(start, end); 43 } 44 45 public int getCost(int[] masks) throws SQLException { 46 return 1; 47 } 48 49 public String getCreateSQL() { 50 return null; 51 } 52 53 public void remove(Session session) throws SQLException { 54 throw Message.getUnsupportedException(); 55 } 56 57 public void truncate(Session session) throws SQLException { 58 throw Message.getUnsupportedException(); 59 } 60 61 public boolean needRebuild() { 62 return false; 63 } 64 65 public void checkRename() throws SQLException { 66 throw Message.getUnsupportedException(); 67 } 68 69 public boolean canGetFirstOrLast(boolean first) { 70 return true; 71 } 72 73 public Value findFirstOrLast(Session session, boolean first) throws SQLException { 74 return ValueLong.get(first ? min : max); 75 } 76 77 } 78 | Popular Tags |