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();
}
}
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) {
}
}
}
Aggregations