KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > index > RangeIndex


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.index;
6
7 import java.sql.SQLException JavaDoc;
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 JavaDoc {
29     }
30
31     public void add(Session session, Row row) throws SQLException JavaDoc {
32         throw Message.getUnsupportedException();
33     }
34
35     public void remove(Session session, Row row) throws SQLException JavaDoc {
36         throw Message.getUnsupportedException();
37     }
38
39     public Cursor find(Session session, SearchRow first, SearchRow last) throws SQLException JavaDoc {
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 JavaDoc {
46         return 1;
47     }
48     
49     public String JavaDoc getCreateSQL() {
50         return null;
51     }
52
53     public void remove(Session session) throws SQLException JavaDoc {
54         throw Message.getUnsupportedException();
55     }
56
57     public void truncate(Session session) throws SQLException JavaDoc {
58         throw Message.getUnsupportedException();
59     }
60
61     public boolean needRebuild() {
62         return false;
63     }
64
65     public void checkRename() throws SQLException JavaDoc {
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 JavaDoc {
74         return ValueLong.get(first ? min : max);
75     }
76
77 }
78
Popular Tags