Search in sources :

Example 91 with Record

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

the class SimpleTransactionTest method testRollbackUpdate2.

@Test
public void testRollbackUpdate2() throws Exception {
    Bytes key = Bytes.from_string("key1");
    Record record = new Record(key, Bytes.from_int(0));
    InsertStatement st_insert = new InsertStatement(tableSpace, tableName, record);
    assertEquals(1, manager.executeUpdate(st_insert, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
    long tx = beginTransaction();
    Record record2 = new Record(key, Bytes.from_int(1));
    UpdateStatement st_update = new UpdateStatement(tableSpace, tableName, record2, null);
    assertEquals(1, manager.executeUpdate(st_update, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx)).getUpdateCount());
    GetResult get_before_rollback = manager.get(new GetStatement(tableSpace, tableName, key, null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx));
    assertTrue(get_before_rollback.found());
    assertEquals(get_before_rollback.getRecord().value, record2.value);
    rollbackTransaction(tx);
    GetResult get_after_rollback = manager.get(new GetStatement(tableSpace, tableName, key, null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
    assertTrue(get_after_rollback.found());
    assertEquals(get_after_rollback.getRecord().value, record.value);
}
Also used : Bytes(herddb.utils.Bytes) UpdateStatement(herddb.model.commands.UpdateStatement) GetResult(herddb.model.GetResult) TransactionContext(herddb.model.TransactionContext) GetStatement(herddb.model.commands.GetStatement) Record(herddb.model.Record) InsertStatement(herddb.model.commands.InsertStatement) Test(org.junit.Test)

Example 92 with Record

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

the class SimpleTransactionTest method testRollbackInsertDelete.

@Test
public void testRollbackInsertDelete() throws Exception {
    long tx = beginTransaction();
    Bytes key = Bytes.from_string("key1");
    Record record = new Record(key, Bytes.from_int(0));
    InsertStatement st_insert = new InsertStatement(tableSpace, tableName, record);
    assertEquals(1, manager.executeUpdate(st_insert, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx)).getUpdateCount());
    // DELETE RETURNS update-count = 1 during the transaction
    DeleteStatement st_delete = new DeleteStatement(tableSpace, tableName, key, null);
    assertEquals(1, manager.executeUpdate(st_delete, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx)).getUpdateCount());
    rollbackTransaction(tx);
    GetResult get_after_rollback = manager.get(new GetStatement(tableSpace, tableName, key, null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
    assertFalse(get_after_rollback.found());
}
Also used : Bytes(herddb.utils.Bytes) GetResult(herddb.model.GetResult) TransactionContext(herddb.model.TransactionContext) GetStatement(herddb.model.commands.GetStatement) Record(herddb.model.Record) DeleteStatement(herddb.model.commands.DeleteStatement) InsertStatement(herddb.model.commands.InsertStatement) Test(org.junit.Test)

Example 93 with Record

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

the class SimpleTransactionTest method testRollbackDelete2.

@Test
public void testRollbackDelete2() throws Exception {
    Bytes key = Bytes.from_string("key1");
    {
        Record record = new Record(key, Bytes.from_int(0));
        InsertStatement st = new InsertStatement(tableSpace, tableName, record);
        assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
    }
    long tx = beginTransaction();
    DeleteStatement st = new DeleteStatement(tableSpace, tableName, key, null);
    assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx)).getUpdateCount());
    // inside the transaction the record will not be found any more
    {
        GetResult get = manager.get(new GetStatement(tableSpace, tableName, key, null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx));
        assertFalse(get.found());
    }
    rollbackTransaction(tx);
    GetResult get = manager.get(new GetStatement(tableSpace, tableName, key, null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
    assertTrue(get.found());
}
Also used : Bytes(herddb.utils.Bytes) GetResult(herddb.model.GetResult) TransactionContext(herddb.model.TransactionContext) GetStatement(herddb.model.commands.GetStatement) Record(herddb.model.Record) DeleteStatement(herddb.model.commands.DeleteStatement) InsertStatement(herddb.model.commands.InsertStatement) Test(org.junit.Test)

Example 94 with Record

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

the class SimpleTransactionTest method testRollbackDelete1.

@Test
public void testRollbackDelete1() throws Exception {
    Bytes key = Bytes.from_string("key1");
    {
        Record record = new Record(key, Bytes.from_int(0));
        InsertStatement st = new InsertStatement(tableSpace, tableName, record);
        assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
    }
    long tx = beginTransaction();
    DeleteStatement st = new DeleteStatement(tableSpace, tableName, key, null);
    assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx)).getUpdateCount());
    rollbackTransaction(tx);
    GetResult get = manager.get(new GetStatement(tableSpace, tableName, key, null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
    assertTrue(get.found());
}
Also used : Bytes(herddb.utils.Bytes) GetResult(herddb.model.GetResult) TransactionContext(herddb.model.TransactionContext) GetStatement(herddb.model.commands.GetStatement) Record(herddb.model.Record) DeleteStatement(herddb.model.commands.DeleteStatement) InsertStatement(herddb.model.commands.InsertStatement) Test(org.junit.Test)

Example 95 with Record

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

the class SimpleTransactionTest method testCommitMultiTable.

@Test
public void testCommitMultiTable() throws Exception {
    String tableName2 = "t2";
    Table table2 = Table.builder().tablespace("tblspace1").name(tableName2).column("id", ColumnTypes.STRING).column("name", ColumnTypes.STRING).primaryKey("id").build();
    CreateTableStatement st2 = new CreateTableStatement(table2);
    manager.executeStatement(st2, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
    long tx = beginTransaction();
    Bytes key = Bytes.from_string("key1");
    {
        Record record = new Record(key, Bytes.from_int(0));
        InsertStatement st = new InsertStatement(tableSpace, tableName, record);
        assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx)).getUpdateCount());
    }
    {
        Record record = new Record(key, Bytes.from_int(1));
        InsertStatement st = new InsertStatement(tableSpace, tableName2, record);
        assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx)).getUpdateCount());
    }
    commitTransaction(tx);
    GetResult get = manager.get(new GetStatement(tableSpace, tableName, key, null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
    assertTrue(get.found());
    assertEquals(Bytes.from_int(0), get.getRecord().value);
    GetResult get2 = manager.get(new GetStatement(tableSpace, tableName2, key, null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
    assertTrue(get2.found());
    assertEquals(Bytes.from_int(1), get2.getRecord().value);
}
Also used : Bytes(herddb.utils.Bytes) Table(herddb.model.Table) GetResult(herddb.model.GetResult) TransactionContext(herddb.model.TransactionContext) GetStatement(herddb.model.commands.GetStatement) CreateTableStatement(herddb.model.commands.CreateTableStatement) Record(herddb.model.Record) InsertStatement(herddb.model.commands.InsertStatement) Test(org.junit.Test)

Aggregations

Record (herddb.model.Record)96 InsertStatement (herddb.model.commands.InsertStatement)56 Test (org.junit.Test)56 Bytes (herddb.utils.Bytes)53 GetResult (herddb.model.GetResult)44 GetStatement (herddb.model.commands.GetStatement)43 Table (herddb.model.Table)36 TransactionContext (herddb.model.TransactionContext)34 CreateTableStatement (herddb.model.commands.CreateTableStatement)28 DeleteStatement (herddb.model.commands.DeleteStatement)23 CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)22 Path (java.nio.file.Path)22 HashMap (java.util.HashMap)21 TransactionResult (herddb.model.TransactionResult)20 FileDataStorageManager (herddb.file.FileDataStorageManager)19 BeginTransactionStatement (herddb.model.commands.BeginTransactionStatement)19 UpdateStatement (herddb.model.commands.UpdateStatement)19 FileCommitLogManager (herddb.file.FileCommitLogManager)18 FileMetadataStorageManager (herddb.file.FileMetadataStorageManager)18 DataStorageManagerException (herddb.storage.DataStorageManagerException)17