Search in sources :

Example 1 with IndexAlreadyExistsException

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();
    }
}
Also used : DataStorageManagerException(herddb.storage.DataStorageManagerException) IndexAlreadyExistsException(herddb.model.IndexAlreadyExistsException) CommitLogResult(herddb.log.CommitLogResult) DDLStatementExecutionResult(herddb.model.DDLStatementExecutionResult) LogEntry(herddb.log.LogEntry) DumpedLogEntry(herddb.backup.DumpedLogEntry) StatementExecutionException(herddb.model.StatementExecutionException) LogNotAvailableException(herddb.log.LogNotAvailableException)

Example 2 with IndexAlreadyExistsException

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();
    }
}
Also used : TableAlreadyExistsException(herddb.model.TableAlreadyExistsException) DataStorageManagerException(herddb.storage.DataStorageManagerException) IndexAlreadyExistsException(herddb.model.IndexAlreadyExistsException) Index(herddb.model.Index) CommitLogResult(herddb.log.CommitLogResult) DDLStatementExecutionResult(herddb.model.DDLStatementExecutionResult) LogEntry(herddb.log.LogEntry) DumpedLogEntry(herddb.backup.DumpedLogEntry) StatementExecutionException(herddb.model.StatementExecutionException) LogNotAvailableException(herddb.log.LogNotAvailableException)

Example 3 with IndexAlreadyExistsException

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) {
        }
    }
}
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

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