示例#1
0
  private void readShema(ISqlJetBtreeSchemaTable table) throws SqlJetException {
    for (table.first(); !table.eof(); table.next()) {
      final String type = table.getTypeField();
      if (null == type) {
        continue;
      }
      final String name = table.getNameField();
      if (null == name) {
        continue;
      }
      final int page = table.getPageField();

      if (TABLE_TYPE.equals(type)) {
        String sql = table.getSqlField();
        // System.err.println(sql);
        final CommonTree ast = (CommonTree) parseTable(sql).getTree();
        if (!isCreateVirtualTable(ast)) {
          final SqlJetTableDef tableDef = new SqlJetTableDef(ast, page);
          if (!name.equals(tableDef.getName())) {
            throw new SqlJetException(SqlJetErrorCode.CORRUPT);
          }
          tableDef.setRowId(table.getRowId());
          tableDefs.put(name, tableDef);
        } else {
          final SqlJetVirtualTableDef virtualTableDef = new SqlJetVirtualTableDef(ast, page);
          if (!name.equals(virtualTableDef.getTableName())) {
            throw new SqlJetException(SqlJetErrorCode.CORRUPT);
          }
          virtualTableDef.setRowId(table.getRowId());
          virtualTableDefs.put(name, virtualTableDef);
        }
      } else if (INDEX_TYPE.equals(type)) {
        final String tableName = table.getTableField();
        final String sql = table.getSqlField();
        if (null != sql) {
          // System.err.println(sql);
          final CommonTree ast = (CommonTree) parseIndex(sql).getTree();
          final SqlJetIndexDef indexDef = new SqlJetIndexDef(ast, page);
          if (!name.equals(indexDef.getName())) {
            throw new SqlJetException(SqlJetErrorCode.CORRUPT);
          }
          if (!tableName.equals(indexDef.getTableName())) {
            throw new SqlJetException(SqlJetErrorCode.CORRUPT);
          }
          indexDef.setRowId(table.getRowId());
          indexDefs.put(name, indexDef);
        } else {
          SqlJetBaseIndexDef indexDef = new SqlJetBaseIndexDef(name, tableName, page);
          indexDef.setRowId(table.getRowId());
          indexDefs.put(name, indexDef);
        }
      }
    }
    bindIndexes();
  }
示例#2
0
  /**
   * @param page
   * @param moved
   * @throws SqlJetException
   */
  private void movePage(final int page, final int moved) throws SqlJetException {
    final ISqlJetBtreeSchemaTable schemaTable = openSchemaTable(true);
    try {
      schemaTable.lock();
      try {
        for (schemaTable.first(); !schemaTable.eof(); schemaTable.next()) {
          final long pageField = schemaTable.getPageField();
          if (pageField == moved) {
            final String nameField = schemaTable.getNameField();
            schemaTable.updateRecord(
                schemaTable.getRowId(),
                schemaTable.getTypeField(),
                nameField,
                schemaTable.getTableField(),
                page,
                schemaTable.getSqlField());
            final ISqlJetIndexDef index = getIndex(nameField);
            if (index != null) {
              if (index instanceof SqlJetBaseIndexDef) {
                ((SqlJetBaseIndexDef) index).setPage(page);
              }
            } else {
              final ISqlJetTableDef table = getTable(nameField);
              if (table != null) {
                if (table instanceof SqlJetTableDef) {
                  ((SqlJetTableDef) table).setPage(page);
                }
              }
            }
            return;
          }
        }
      } finally {
        schemaTable.unlock();
      }

    } finally {
      schemaTable.close();
    }
  }