public Void execute(ISession session, SeConnection connection) throws SeException,
IOException {
SeInsert insert = new SeInsert(connection);
insert.intoTable(tableName, columns);
insert.setWriteMode(true);
SeRow row = insert.getRowToSet();
row.setInteger(0, Integer.valueOf(50));
row.setString(1, "inside transaction");
insert.execute();
// IMPORTANT to call close for the diff to take effect
insert.close();
return null;
}
});
final SeSqlConstruct sqlConstruct = new SeSqlConstruct(tableName);
final SeRow transRow = transSession.issue(new Command<SeRow>() {
@Override
public SeRow execute(ISession session, SeConnection connection) throws SeException,
IOException {
// the query over the transaction connection
SeQuery transQuery = new SeQuery(connection, columns, sqlConstruct);
// transaction is not committed, so transQuery should give
// the
// inserted
// record and query don't
transQuery.prepareQuery();
transQuery.execute();
SeRow transRow = transQuery.fetch();
// querying over a transaction in progress does give diff
// assertEquals(Integer.valueOf(50), transRow.getInteger(0))
transQuery.close();
return transRow;
}
});
assertNotNull(transRow);
// commit transaction
transSession.commitTransaction();
commited = true;
final SeRow noTransRow = session.issue(new Command<SeRow>() {
@Override
public SeRow execute(ISession session, SeConnection connection) throws SeException,
IOException {
SeQuery query = new SeQuery(connection, columns, sqlConstruct);
query.prepareQuery();
query.execute();
SeRow row = query.fetch();
query.close();
return row;
}
});