use of herddb.model.IndexAlreadyExistsException in project herddb by diennea.
the class TableSpaceManager method createIndex.
private StatementExecutionResult createIndex(CreateIndexStatement statement, Transaction transaction) throws StatementExecutionException {
generalLock.writeLock().lock();
try {
if (indexes.containsKey(statement.getIndexefinition().name)) {
throw new IndexAlreadyExistsException(statement.getIndexefinition().name);
}
LogEntry entry = LogEntryFactory.createIndex(statement.getIndexefinition(), 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.IndexAlreadyExistsException in project herddb by diennea.
the class TableSpaceManager method createTable.
private StatementExecutionResult createTable(CreateTableStatement statement, Transaction transaction) throws StatementExecutionException {
generalLock.writeLock().lock();
try {
if (tables.containsKey(statement.getTableDefinition().name)) {
throw new TableAlreadyExistsException(statement.getTableDefinition().name);
}
for (Index additionalIndex : statement.getAdditionalIndexes()) {
if (indexes.containsKey(additionalIndex.name)) {
throw new IndexAlreadyExistsException(additionalIndex.name);
}
}
LogEntry entry = LogEntryFactory.createTable(statement.getTableDefinition(), transaction);
CommitLogResult pos = log.log(entry, entry.transactionId <= 0);
apply(pos, entry, false);
for (Index additionalIndex : statement.getAdditionalIndexes()) {
LogEntry index_entry = LogEntryFactory.createIndex(additionalIndex, transaction);
CommitLogResult index_pos = log.log(index_entry, index_entry.transactionId <= 0);
apply(index_pos, index_entry, false);
}
return new DDLStatementExecutionResult(entry.transactionId);
} catch (DataStorageManagerException | LogNotAvailableException err) {
throw new StatementExecutionException(err);
} finally {
generalLock.writeLock().unlock();
}
}
use of herddb.model.IndexAlreadyExistsException 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