Search in sources :

Example 1 with IndexDoesNotExistException

use of herddb.model.IndexDoesNotExistException in project herddb by diennea.

the class TableSpaceManager method dropIndex.

private StatementExecutionResult dropIndex(DropIndexStatement statement, Transaction transaction) throws StatementExecutionException {
    generalLock.writeLock().lock();
    try {
        if (!indexes.containsKey(statement.getIndexName())) {
            if (statement.isIfExists()) {
                return new DDLStatementExecutionResult(transaction != null ? transaction.transactionId : 0);
            }
            throw new IndexDoesNotExistException("index " + statement.getIndexName() + " does not exist " + statement.getIndexName() + " on tableSpace " + statement.getTableSpace());
        }
        if (transaction != null && transaction.isIndexDropped(statement.getIndexName())) {
            if (statement.isIfExists()) {
                return new DDLStatementExecutionResult(transaction.transactionId);
            }
            throw new IndexDoesNotExistException("index does not exist " + statement.getIndexName() + " on tableSpace " + statement.getTableSpace());
        }
        LogEntry entry = LogEntryFactory.dropIndex(statement.getIndexName(), transaction);
        CommitLogResult pos;
        try {
            pos = log.log(entry, entry.transactionId <= 0);
        } catch (LogNotAvailableException ex) {
            throw new StatementExecutionException(ex);
        }
        apply(pos, entry, false);
        return new DDLStatementExecutionResult(entry.transactionId);
    } catch (DataStorageManagerException err) {
        throw new StatementExecutionException(err);
    } finally {
        generalLock.writeLock().unlock();
    }
}
Also used : DataStorageManagerException(herddb.storage.DataStorageManagerException) IndexDoesNotExistException(herddb.model.IndexDoesNotExistException) DDLStatementExecutionResult(herddb.model.DDLStatementExecutionResult) CommitLogResult(herddb.log.CommitLogResult) LogEntry(herddb.log.LogEntry) DumpedLogEntry(herddb.backup.DumpedLogEntry) StatementExecutionException(herddb.model.StatementExecutionException) LogNotAvailableException(herddb.log.LogNotAvailableException)

Example 2 with IndexDoesNotExistException

use of herddb.model.IndexDoesNotExistException in project herddb by diennea.

the class RawSQLTest method createDropIndexTest.

@Test
public void createDropIndexTest() throws Exception {
    String nodeId = "localhost";
    try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
        manager.start();
        CreateTableSpaceStatement st1 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
        manager.executeStatement(st1, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        manager.waitForTablespace("tblspace1", 10000);
        execute(manager, "CREATE TABLE tblspace1.tsql (k1 string primary key,n1 int,s1 string)", Collections.emptyList());
        execute(manager, "CREATE INDEX ix1 ON tblspace1.tsql(n1)", Collections.emptyList());
        try {
            execute(manager, "CREATE INDEX ix1 ON tblspace1.tsql(n1)", Collections.emptyList());
            fail();
        } catch (IndexAlreadyExistsException ok) {
        }
        execute(manager, "DROP INDEX tblspace1.ix1", Collections.emptyList());
        execute(manager, "CREATE INDEX ix1 ON tblspace1.tsql(n1)", Collections.emptyList());
        execute(manager, "CREATE HASH INDEX ix_hash ON tblspace1.tsql(n1)", Collections.emptyList());
        try {
            execute(manager, "CREATE BADTYPE INDEX ix_bad ON tblspace1.tsql(n1)", Collections.emptyList());
            fail();
        } catch (StatementExecutionException ok) {
            assertTrue(ok.getMessage().contains("badtype"));
        }
        try {
            execute(manager, "DROP INDEX tblspace1.ix2", Collections.emptyList());
            fail();
        } catch (IndexDoesNotExistException ok) {
        }
        try {
            execute(manager, "DROP INDEX ix1", Collections.emptyList());
            fail();
        } catch (IndexDoesNotExistException ok) {
        }
        try {
            execute(manager, "CREATE INDEX ix2 ON tsql(n1)", Collections.emptyList());
            fail();
        } catch (TableDoesNotExistException ok) {
        }
        try {
            execute(manager, "CREATE INDEX duplicatecolumn ON tblspace1.tsql(n1,n1)", Collections.emptyList());
            fail();
        } catch (StatementExecutionException ok) {
        }
    }
}
Also used : TableDoesNotExistException(herddb.model.TableDoesNotExistException) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) IndexAlreadyExistsException(herddb.model.IndexAlreadyExistsException) IndexDoesNotExistException(herddb.model.IndexDoesNotExistException) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) RawString(herddb.utils.RawString) StatementExecutionException(herddb.model.StatementExecutionException) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Aggregations

IndexDoesNotExistException (herddb.model.IndexDoesNotExistException)2 StatementExecutionException (herddb.model.StatementExecutionException)2 DumpedLogEntry (herddb.backup.DumpedLogEntry)1 CommitLogResult (herddb.log.CommitLogResult)1 LogEntry (herddb.log.LogEntry)1 LogNotAvailableException (herddb.log.LogNotAvailableException)1 MemoryCommitLogManager (herddb.mem.MemoryCommitLogManager)1 MemoryDataStorageManager (herddb.mem.MemoryDataStorageManager)1 MemoryMetadataStorageManager (herddb.mem.MemoryMetadataStorageManager)1 DDLStatementExecutionResult (herddb.model.DDLStatementExecutionResult)1 IndexAlreadyExistsException (herddb.model.IndexAlreadyExistsException)1 TableDoesNotExistException (herddb.model.TableDoesNotExistException)1 CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)1 DataStorageManagerException (herddb.storage.DataStorageManagerException)1 RawString (herddb.utils.RawString)1 Test (org.junit.Test)1