Search in sources :

Example 1 with RegularTable

use of org.h2.table.RegularTable in project h2database by h2database.

the class PageStore method openMetaIndex.

private void openMetaIndex() {
    CreateTableData data = new CreateTableData();
    ArrayList<Column> cols = data.columns;
    cols.add(new Column("ID", Value.INT));
    cols.add(new Column("TYPE", Value.INT));
    cols.add(new Column("PARENT", Value.INT));
    cols.add(new Column("HEAD", Value.INT));
    cols.add(new Column("OPTIONS", Value.STRING));
    cols.add(new Column("COLUMNS", Value.STRING));
    metaSchema = new Schema(database, 0, "", null, true);
    data.schema = metaSchema;
    data.tableName = "PAGE_INDEX";
    data.id = META_TABLE_ID;
    data.temporary = false;
    data.persistData = true;
    data.persistIndexes = true;
    data.create = false;
    data.session = pageStoreSession;
    metaTable = new RegularTable(data);
    metaIndex = (PageDataIndex) metaTable.getScanIndex(pageStoreSession);
    metaObjects.clear();
    metaObjects.put(-1, metaIndex);
}
Also used : IndexColumn(org.h2.table.IndexColumn) Column(org.h2.table.Column) Schema(org.h2.schema.Schema) RegularTable(org.h2.table.RegularTable) CreateTableData(org.h2.command.ddl.CreateTableData)

Example 2 with RegularTable

use of org.h2.table.RegularTable in project h2database by h2database.

the class PageStore method addMeta.

private void addMeta(Row row, Session session, boolean redo) {
    int id = row.getValue(0).getInt();
    int type = row.getValue(1).getInt();
    int parent = row.getValue(2).getInt();
    int rootPageId = row.getValue(3).getInt();
    String[] options = StringUtils.arraySplit(row.getValue(4).getString(), ',', false);
    String columnList = row.getValue(5).getString();
    String[] columns = StringUtils.arraySplit(columnList, ',', false);
    Index meta;
    if (trace.isDebugEnabled()) {
        trace.debug("addMeta id=" + id + " type=" + type + " root=" + rootPageId + " parent=" + parent + " columns=" + columnList);
    }
    if (redo && rootPageId != 0) {
        // ensure the page is empty, but not used by regular data
        writePage(rootPageId, createData());
        allocatePage(rootPageId);
    }
    metaRootPageId.put(id, rootPageId);
    if (type == META_TYPE_DATA_INDEX) {
        CreateTableData data = new CreateTableData();
        if (SysProperties.CHECK) {
            if (columns == null) {
                throw DbException.throwInternalError(row.toString());
            }
        }
        for (int i = 0, len = columns.length; i < len; i++) {
            Column col = new Column("C" + i, Value.INT);
            data.columns.add(col);
        }
        data.schema = metaSchema;
        data.tableName = "T" + id;
        data.id = id;
        data.temporary = options[2].equals("temp");
        data.persistData = true;
        data.persistIndexes = true;
        data.create = false;
        data.session = session;
        RegularTable table = new RegularTable(data);
        boolean binaryUnsigned = SysProperties.SORT_BINARY_UNSIGNED;
        if (options.length > 3) {
            binaryUnsigned = Boolean.parseBoolean(options[3]);
        }
        CompareMode mode = CompareMode.getInstance(options[0], Integer.parseInt(options[1]), binaryUnsigned);
        table.setCompareMode(mode);
        meta = table.getScanIndex(session);
    } else {
        Index p = metaObjects.get(parent);
        if (p == null) {
            throw DbException.get(ErrorCode.FILE_CORRUPTED_1, "Table not found:" + parent + " for " + row + " meta:" + metaObjects);
        }
        RegularTable table = (RegularTable) p.getTable();
        Column[] tableCols = table.getColumns();
        int len = columns.length;
        IndexColumn[] cols = new IndexColumn[len];
        for (int i = 0; i < len; i++) {
            String c = columns[i];
            IndexColumn ic = new IndexColumn();
            int idx = c.indexOf('/');
            if (idx >= 0) {
                String s = c.substring(idx + 1);
                ic.sortType = Integer.parseInt(s);
                c = c.substring(0, idx);
            }
            ic.column = tableCols[Integer.parseInt(c)];
            cols[i] = ic;
        }
        IndexType indexType;
        if (options[3].equals("d")) {
            indexType = IndexType.createPrimaryKey(true, false);
            Column[] tableColumns = table.getColumns();
            for (IndexColumn indexColumn : cols) {
                tableColumns[indexColumn.column.getColumnId()].setNullable(false);
            }
        } else {
            indexType = IndexType.createNonUnique(true);
        }
        meta = table.addIndex(session, "I" + id, id, cols, indexType, false, null);
    }
    PageIndex index;
    if (meta instanceof MultiVersionIndex) {
        index = (PageIndex) ((MultiVersionIndex) meta).getBaseIndex();
    } else {
        index = (PageIndex) meta;
    }
    metaObjects.put(id, index);
}
Also used : Index(org.h2.index.Index) PageIndex(org.h2.index.PageIndex) PageDelegateIndex(org.h2.index.PageDelegateIndex) MultiVersionIndex(org.h2.index.MultiVersionIndex) PageBtreeIndex(org.h2.index.PageBtreeIndex) PageDataIndex(org.h2.index.PageDataIndex) ValueString(org.h2.value.ValueString) PageIndex(org.h2.index.PageIndex) CreateTableData(org.h2.command.ddl.CreateTableData) IndexColumn(org.h2.table.IndexColumn) IndexColumn(org.h2.table.IndexColumn) Column(org.h2.table.Column) MultiVersionIndex(org.h2.index.MultiVersionIndex) RegularTable(org.h2.table.RegularTable) CompareMode(org.h2.value.CompareMode) IndexType(org.h2.index.IndexType)

Example 3 with RegularTable

use of org.h2.table.RegularTable in project h2database by h2database.

the class RegularTable method getDeadlockDetails.

private static String getDeadlockDetails(ArrayList<Session> sessions, boolean exclusive) {
    // We add the thread details here to make it easier for customers to
    // match up these error messages with their own logs.
    StringBuilder buff = new StringBuilder();
    for (Session s : sessions) {
        Table lock = s.getWaitForLock();
        Thread thread = s.getWaitForLockThread();
        buff.append("\nSession ").append(s.toString()).append(" on thread ").append(thread.getName()).append(" is waiting to lock ").append(lock.toString()).append(exclusive ? " (exclusive)" : " (shared)").append(" while locking ");
        int i = 0;
        for (Table t : s.getLocks()) {
            if (i++ > 0) {
                buff.append(", ");
            }
            buff.append(t.toString());
            if (t instanceof RegularTable) {
                if (((RegularTable) t).lockExclusiveSession == s) {
                    buff.append(" (exclusive)");
                } else {
                    buff.append(" (shared)");
                }
            }
        }
        buff.append('.');
    }
    return buff.toString();
}
Also used : Constraint(org.h2.constraint.Constraint) Session(org.h2.engine.Session)

Aggregations

CreateTableData (org.h2.command.ddl.CreateTableData)2 Column (org.h2.table.Column)2 IndexColumn (org.h2.table.IndexColumn)2 RegularTable (org.h2.table.RegularTable)2 Constraint (org.h2.constraint.Constraint)1 Session (org.h2.engine.Session)1 Index (org.h2.index.Index)1 IndexType (org.h2.index.IndexType)1 MultiVersionIndex (org.h2.index.MultiVersionIndex)1 PageBtreeIndex (org.h2.index.PageBtreeIndex)1 PageDataIndex (org.h2.index.PageDataIndex)1 PageDelegateIndex (org.h2.index.PageDelegateIndex)1 PageIndex (org.h2.index.PageIndex)1 Schema (org.h2.schema.Schema)1 CompareMode (org.h2.value.CompareMode)1 ValueString (org.h2.value.ValueString)1