コード例 #1
0
ファイル: SqlJetSchema.java プロジェクト: AslanUOM/sqljet
 /**
  * @param schemaTable
  * @param tableDef
  * @throws SqlJetException
  */
 private void dropTableIndexes(SqlJetTableDef tableDef) throws SqlJetException {
   final String tableName = tableDef.getName();
   final Iterator<Map.Entry<String, ISqlJetIndexDef>> iterator = indexDefs.entrySet().iterator();
   while (iterator.hasNext()) {
     final Map.Entry<String, ISqlJetIndexDef> indexDefEntry = iterator.next();
     final String indexName = indexDefEntry.getKey();
     final ISqlJetIndexDef indexDef = indexDefEntry.getValue();
     if (indexDef.getTableName().equals(tableName)) {
       if (doDropIndex(indexName, true, false)) {
         iterator.remove();
       }
     }
   }
 }
コード例 #2
0
ファイル: SqlJetSchema.java プロジェクト: AslanUOM/sqljet
 public Set<ISqlJetIndexDef> getIndexes(String tableName) throws SqlJetException {
   db.getMutex().enter();
   try {
     Set<ISqlJetIndexDef> result = new HashSet<ISqlJetIndexDef>();
     for (ISqlJetIndexDef index : indexDefs.values()) {
       if (index.getTableName().equals(tableName)) {
         result.add(index);
       }
     }
     return Collections.unmodifiableSet(result);
   } finally {
     db.getMutex().leave();
   }
 }
コード例 #3
0
ファイル: SqlJetSchema.java プロジェクト: AslanUOM/sqljet
 @Override
 public String toString() {
   db.getMutex().enter();
   try {
     StringBuffer buffer = new StringBuffer();
     buffer.append("Tables:\n");
     for (ISqlJetTableDef tableDef : tableDefs.values()) {
       buffer.append(tableDef.toString());
       buffer.append('\n');
     }
     buffer.append("Indexes:\n");
     for (ISqlJetIndexDef indexDef : indexDefs.values()) {
       buffer.append(indexDef.toString());
       buffer.append('\n');
     }
     return buffer.toString();
   } finally {
     db.getMutex().leave();
   }
 }
コード例 #4
0
ファイル: SqlJetSchema.java プロジェクト: AslanUOM/sqljet
  /**
   * @param schemaTable
   * @param newTableName
   * @param tableName
   * @param string
   * @throws SqlJetException
   */
  private void renameTablesIndices(
      final ISqlJetBtreeSchemaTable schemaTable,
      String tableName,
      String newTableName,
      String alterTableName)
      throws SqlJetException {

    final Set<ISqlJetIndexDef> indexes = getIndexes(tableName);
    if (null == indexes || 0 == indexes.size()) {
      return;
    }

    int i = 0;
    for (final ISqlJetIndexDef index : indexes) {
      if (index instanceof SqlJetBaseIndexDef) {

        final SqlJetBaseIndexDef indexDef = (SqlJetBaseIndexDef) index;
        final String indexName = indexDef.getName();
        final long rowId = indexDef.getRowId();
        final int page = indexDef.getPage();

        if (!schemaTable.goToRow(rowId)) {
          throw new SqlJetException(SqlJetErrorCode.CORRUPT);
        }

        final String typeField = schemaTable.getTypeField();
        final String nameField = schemaTable.getNameField();
        final String tableField = schemaTable.getTableField();
        final int pageField = schemaTable.getPageField();

        if (null == typeField || !INDEX_TYPE.equals(typeField)) {
          throw new SqlJetException(SqlJetErrorCode.CORRUPT);
        }
        if (null == nameField || !indexName.equals(nameField)) {
          throw new SqlJetException(SqlJetErrorCode.CORRUPT);
        }
        if (null == tableField || !tableName.equals(tableField)) {
          throw new SqlJetException(SqlJetErrorCode.CORRUPT);
        }
        if (0 == pageField || pageField != page) {
          throw new SqlJetException(SqlJetErrorCode.CORRUPT);
        }

        indexDef.setTableName(newTableName);

        String newIndexName = indexName;
        String alteredIndexSql = null;

        if (index.isImplicit()) {
          newIndexName = generateAutoIndexName(tableName, ++i);
          indexDef.setName(newIndexName);
          indexDefs.remove(indexName);
          indexDefs.put(newIndexName, indexDef);
        } else {
          alteredIndexSql = getAlteredIndexSql(schemaTable.getSqlField(), alterTableName);
        }

        schemaTable.insertRecord(INDEX_TYPE, newIndexName, newTableName, page, alteredIndexSql);

      } else {
        throw new SqlJetException(SqlJetErrorCode.INTERNAL);
      }
    }
  }