001: /*
002: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
003: * (http://h2database.com/html/license.html).
004: * Initial Developer: H2 Group
005: */
006: package org.h2.table;
007:
008: import java.sql.SQLException;
009:
010: import org.h2.engine.Session;
011: import org.h2.index.Index;
012: import org.h2.index.IndexType;
013: import org.h2.index.RangeIndex;
014: import org.h2.message.Message;
015: import org.h2.result.Row;
016: import org.h2.schema.Schema;
017: import org.h2.util.ObjectArray;
018: import org.h2.value.Value;
019:
020: /**
021: * The table SYSTEM_RANGE is a virtual table that generates incrementing numbers
022: * with a given start end end point.
023: */
024: public class RangeTable extends Table {
025:
026: public static final String NAME = "SYSTEM_RANGE";
027: private final long min, max;
028:
029: public RangeTable(Schema schema, long min, long max)
030: throws SQLException {
031: super (schema, 0, NAME, true);
032: Column[] cols = new Column[] { new Column("X", Value.LONG) };
033: this .min = min;
034: this .max = max;
035: setColumns(cols);
036: }
037:
038: public String getDropSQL() {
039: return null;
040: }
041:
042: public String getCreateSQL() {
043: return null;
044: }
045:
046: public String getSQL() {
047: return NAME + "(" + min + ", " + max + ")";
048: }
049:
050: public void lock(Session session, boolean exclusive, boolean force)
051: throws SQLException {
052: }
053:
054: public void close(Session session) throws SQLException {
055: }
056:
057: public void unlock(Session s) {
058: }
059:
060: public boolean isLockedExclusively() {
061: return false;
062: }
063:
064: public Index addIndex(Session session, String indexName,
065: int indexId, IndexColumn[] cols, IndexType indexType,
066: int headPos, String comment) throws SQLException {
067: throw Message.getUnsupportedException();
068: }
069:
070: public void removeRow(Session session, Row row) throws SQLException {
071: throw Message.getUnsupportedException();
072: }
073:
074: public void addRow(Session session, Row row) throws SQLException {
075: throw Message.getUnsupportedException();
076: }
077:
078: public void checkSupportAlter() throws SQLException {
079: throw Message.getUnsupportedException();
080: }
081:
082: public void checkRename() throws SQLException {
083: throw Message.getUnsupportedException();
084: }
085:
086: public boolean canGetRowCount() {
087: return true;
088: }
089:
090: public boolean canDrop() {
091: return false;
092: }
093:
094: public long getRowCount(Session session) throws SQLException {
095: return max - min;
096: }
097:
098: public String getTableType() {
099: throw Message.getInternalError();
100: }
101:
102: public Index getScanIndex(Session session) throws SQLException {
103: return new RangeIndex(this , IndexColumn.wrap(columns), min, max);
104: }
105:
106: public ObjectArray getIndexes() {
107: return null;
108: }
109:
110: public void truncate(Session session) throws SQLException {
111: throw Message.getUnsupportedException();
112: }
113:
114: public long getMaxDataModificationId() {
115: return 0;
116: }
117:
118: public Index getUniqueIndex() {
119: return null;
120: }
121:
122: }
|