use of herddb.model.GetResult 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());
}
use of herddb.model.GetResult 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());
}
use of herddb.model.GetResult in project herddb by diennea.
the class TmpMapImpl method executeContainsKey.
private boolean executeContainsKey(byte[] serializedKey, String tmpTableName) throws CollectionsException {
try {
GetStatement get = new GetStatement(TableSpace.DEFAULT, tmpTableName, Bytes.from_array(serializedKey), null, false);
GetResult getResult = (GetResult) tableSpaceManager.executeStatement(get, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), herddb.model.TransactionContext.NO_TRANSACTION);
return getResult.found();
} catch (HerdDBInternalException err) {
throw new CollectionsException(err);
}
}
use of herddb.model.GetResult in project herddb by diennea.
the class TmpMapImpl method executeGet.
private Object executeGet(byte[] serializedKey, String tmpTableName) throws CollectionsException {
try {
GetStatement get = new GetStatement(TableSpace.DEFAULT, tmpTableName, Bytes.from_array(serializedKey), null, false);
GetResult getResult = (GetResult) tableSpaceManager.executeStatement(get, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), herddb.model.TransactionContext.NO_TRANSACTION);
if (!getResult.found()) {
return null;
} else {
return valuesSerializer.deserialize(getResult.getRecord().value);
}
} catch (Exception err) {
throw new CollectionsException(err);
}
}
use of herddb.model.GetResult in project herddb by diennea.
the class ColumnTimestampTest method test2.
@Test
public void test2() throws Exception {
String tableName2 = "t2";
Table table2 = Table.builder().tablespace("tblspace1").name(tableName2).tablespace(tableSpace).column("id", ColumnTypes.STRING).column("name", ColumnTypes.STRING).column("ts1", ColumnTypes.TIMESTAMP).primaryKey("id").build();
CreateTableStatement st2 = new CreateTableStatement(table2);
manager.executeStatement(st2, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
java.sql.Timestamp ts1 = new java.sql.Timestamp(System.currentTimeMillis());
{
Map<String, Object> bean = new HashMap<>();
bean.put("id", "key1");
bean.put("ts1", ts1);
Record record = RecordSerializer.toRecord(bean, table2);
InsertStatement st = new InsertStatement(tableSpace, "t2", record);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
{
GetResult result = manager.get(new GetStatement(tableSpace, tableName2, Bytes.from_string("key1"), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertTrue(result.found());
Map<String, Object> resultbean = result.getRecord().toBean(table2);
assertEquals(Bytes.from_string("key1"), result.getRecord().key);
assertEquals(2, resultbean.entrySet().size());
assertEquals(RawString.of("key1"), resultbean.get("id"));
assertEquals(ts1, resultbean.get("ts1"));
}
{
Map<String, Object> bean = new HashMap<>();
bean.put("id", "key1");
bean.put("ts1", null);
Record record = RecordSerializer.toRecord(bean, table2);
UpdateStatement st = new UpdateStatement(tableSpace, tableName2, record, null);
assertEquals(1, manager.executeUpdate(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION).getUpdateCount());
}
{
GetResult result = manager.get(new GetStatement(tableSpace, tableName2, Bytes.from_string("key1"), null, false), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
assertTrue(result.found());
Map<String, Object> resultbean = result.getRecord().toBean(table2);
assertEquals(Bytes.from_string("key1"), result.getRecord().key);
assertEquals(1, resultbean.entrySet().size());
assertEquals(RawString.of("key1"), resultbean.get("id"));
assertEquals(null, resultbean.get("ts1"));
}
}
Aggregations