use of herddb.model.commands.GetStatement 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());
}
use of herddb.model.commands.GetStatement in project herddb by diennea.
the class SimpleTransactionTest method testRollbackInsert.
@Test
public void testRollbackInsert() throws Exception {
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());
}
rollbackTransaction(tx);
GetResult get = manager.get(new GetStatement(tableSpace, tableName, key, null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertFalse(get.found());
}
use of herddb.model.commands.GetStatement 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);
}
use of herddb.model.commands.GetStatement in project herddb by diennea.
the class SimpleTransactionTest method testCommitMultiTable.
@Test
public void testCommitMultiTable() throws Exception {
String tableName2 = "t2";
Table table2 = Table.builder().tablespace(tableSpace).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);
}
use of herddb.model.commands.GetStatement 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());
}
Aggregations