use of herddb.model.commands.GetStatement in project herddb by diennea.
the class SimpleTransactionTest method testInsertDelete.
@Test
public void testInsertDelete() 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());
}
{
Record record = new Record(key, Bytes.from_int(1));
InsertStatement st = new InsertStatement(tableSpace, tableName, 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(1), get.getRecord().value);
}
use of herddb.model.commands.GetStatement in project herddb by diennea.
the class SimpleTransactionTest method testRollbackUpdate1.
@Test
public void testRollbackUpdate1() 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());
rollbackTransaction(tx);
GetResult get = manager.get(new GetStatement(tableSpace, tableName, key, null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertTrue(get.found());
assertEquals(get.getRecord().value, record.value);
}
use of herddb.model.commands.GetStatement in project herddb by diennea.
the class SimpleTransactionTest method testCommit.
@Test
public void testCommit() 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());
}
commitTransaction(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 testRollbackInsertUpdateDelete.
@Test
public void testRollbackInsertUpdateDelete() 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));
// UPDATE
UpdateStatement st_update = new UpdateStatement(tableSpace, tableName, record2, null);
assertEquals(1, manager.executeUpdate(st_update, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx)).getUpdateCount());
// DELETE
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);
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 rollbackCreateTable.
@Test
public void rollbackCreateTable() throws Exception {
Bytes key = Bytes.from_int(1234);
Bytes value = Bytes.from_long(8888);
Table transacted_table = Table.builder().tablespace(tableSpace).name("t2").column("id", ColumnTypes.STRING).column("name", ColumnTypes.STRING).primaryKey("id").build();
long tx = beginTransaction();
CreateTableStatement st_create = new CreateTableStatement(transacted_table);
manager.executeStatement(st_create, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx));
InsertStatement insert = new InsertStatement(tableSpace, "t2", new Record(key, value));
assertEquals(1, manager.executeUpdate(insert, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx)).getUpdateCount());
GetStatement get = new GetStatement(tableSpace, "t2", key, null, false);
GetResult result = manager.get(get, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), new TransactionContext(tx));
assertTrue(result.found());
assertEquals(key, result.getRecord().key);
assertEquals(value, result.getRecord().value);
RollbackTransactionStatement rollback = new RollbackTransactionStatement(tableSpace, tx);
manager.executeStatement(rollback, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
try {
manager.get(new GetStatement(tableSpace, "t2", key, null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
fail();
} catch (TableDoesNotExistException error) {
}
}
Aggregations