Search in sources :

Example 26 with TableDoesNotExistException

use of herddb.model.TableDoesNotExistException 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) {
        }
        execute(manager, "CREATE UNIQUE INDEX ixu1 ON tblspace1.tsql(n1)", Collections.emptyList());
        Map<String, AbstractIndexManager> indexesOnTable = manager.getTableSpaceManager("tblspace1").getIndexesOnTable("tsql");
        assertTrue(indexesOnTable.values().stream().anyMatch(s -> s.getIndexName().equals("ixu1") && s.isUnique()));
    }
}
Also used : Arrays(java.util.Arrays) RuntimeProjectedDataAccessor(herddb.model.planner.ProjectOp.ZeroCopyProjection.RuntimeProjectedDataAccessor) CommitTransactionStatement(herddb.model.commands.CommitTransactionStatement) Date(java.util.Date) Assert.assertNotSame(org.junit.Assert.assertNotSame) RollbackTransactionStatement(herddb.model.commands.RollbackTransactionStatement) Table(herddb.model.Table) TransactionResult(herddb.model.TransactionResult) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) DuplicatePrimaryKeyException(herddb.model.DuplicatePrimaryKeyException) IndexAlreadyExistsException(herddb.model.IndexAlreadyExistsException) TestUtils.scan(herddb.core.TestUtils.scan) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) DMLStatementExecutionResult(herddb.model.DMLStatementExecutionResult) MapUtils(herddb.utils.MapUtils) RawString(herddb.utils.RawString) Index(herddb.model.Index) ScanResult(herddb.model.ScanResult) DataAccessor(herddb.utils.DataAccessor) DataAccessorForFullRecord(herddb.codec.DataAccessorForFullRecord) TableDoesNotExistException(herddb.model.TableDoesNotExistException) DataScanner(herddb.model.DataScanner) StatementExecutionException(herddb.model.StatementExecutionException) TimeZone(java.util.TimeZone) Timestamp(java.sql.Timestamp) RecordSerializer(herddb.codec.RecordSerializer) ScanStatement(herddb.model.commands.ScanStatement) List(java.util.List) MissingJDBCParameterException(herddb.model.MissingJDBCParameterException) Assert.assertFalse(org.junit.Assert.assertFalse) GetStatement(herddb.model.commands.GetStatement) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) Assume.assumeTrue(org.junit.Assume.assumeTrue) TableSpace(herddb.model.TableSpace) Bytes(herddb.utils.Bytes) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) GetResult(herddb.model.GetResult) SimpleDateFormat(java.text.SimpleDateFormat) PrimaryIndexSeek(herddb.index.PrimaryIndexSeek) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) Assert.assertSame(org.junit.Assert.assertSame) TestUtils(herddb.core.TestUtils) Calendar(java.util.Calendar) TransactionContext(herddb.model.TransactionContext) Transaction(herddb.model.Transaction) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) TestUtils.scanKeepReadLocks(herddb.core.TestUtils.scanKeepReadLocks) TestUtils.commitTransaction(herddb.core.TestUtils.commitTransaction) IndexDoesNotExistException(herddb.model.IndexDoesNotExistException) TestUtils.executeUpdate(herddb.core.TestUtils.executeUpdate) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) DBManager(herddb.core.DBManager) Assert.assertNull(org.junit.Assert.assertNull) StatementEvaluationContext(herddb.model.StatementEvaluationContext) AbstractIndexManager(herddb.core.AbstractIndexManager) TestUtils.execute(herddb.core.TestUtils.execute) Assert(org.junit.Assert) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) AbstractIndexManager(herddb.core.AbstractIndexManager) IndexDoesNotExistException(herddb.model.IndexDoesNotExistException) RawString(herddb.utils.RawString) StatementExecutionException(herddb.model.StatementExecutionException) TableDoesNotExistException(herddb.model.TableDoesNotExistException) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DBManager(herddb.core.DBManager) IndexAlreadyExistsException(herddb.model.IndexAlreadyExistsException) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) Test(org.junit.Test)

Aggregations

TableDoesNotExistException (herddb.model.TableDoesNotExistException)26 StatementExecutionException (herddb.model.StatementExecutionException)16 Table (herddb.model.Table)11 Test (org.junit.Test)10 AbstractTableManager (herddb.core.AbstractTableManager)7 DataScanner (herddb.model.DataScanner)7 TableSpaceDoesNotExistException (herddb.model.TableSpaceDoesNotExistException)7 CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)7 DataStorageManagerException (herddb.storage.DataStorageManagerException)7 DumpedLogEntry (herddb.backup.DumpedLogEntry)6 CommitLogResult (herddb.log.CommitLogResult)6 LogEntry (herddb.log.LogEntry)6 LogNotAvailableException (herddb.log.LogNotAvailableException)6 MemoryCommitLogManager (herddb.mem.MemoryCommitLogManager)6 MemoryMetadataStorageManager (herddb.mem.MemoryMetadataStorageManager)6 DDLStatementExecutionResult (herddb.model.DDLStatementExecutionResult)6 IndexAlreadyExistsException (herddb.model.IndexAlreadyExistsException)6 IndexDoesNotExistException (herddb.model.IndexDoesNotExistException)6 TransactionContext (herddb.model.TransactionContext)6 Bytes (herddb.utils.Bytes)6