ResultSet to RecordList correct way?

  

Hello guys,

I've got into some issues trying to use RuntimePublic.Db API, can some one provide some examples on how to do bulk inserts/record updates, queries and bulk deletions using an extension?

To contextualize lets imagine that I have the following entitiy linked to a logical table/view "ENCommandEntity.java", "ENCommandEntityRecord"  and his related structures/records/recordlists.

I instantiate both:
dbaProvider = DatabaseAccess.forRunningApplication();

and
sqlHelper = dbaProvider.getSqlHelper();

and create a:
cmd = requestTransaction.createCommand(<some sql string using sqlHelper for keywords>);

If I do some insert/delete operation I know I can use:
cmd.executeNonQuery() - and this is ok...

But if I want to query some table and get the resultset directly to a "RLCommandRecordList", how do I accomplish that in the correct way?
I've found something related, but I don't know if it's the correct way:
OSResultSet rs = cmd.executeReader();
RLCommandRecordList rl = new RLCommandRecordList();
rl.setReader(cmd.executeReader());

Some examples for those operations would be nice.

Another question is if there is any possibility to adquire a dbConnection to run testcases in Eclipse instead of trying it in runtime in the dev environment.

Regards,
André

Solution

Well, I've done some tests and it works this way:

public static ActGetDocument mosGetDocument(int inParamId) throws SQLException {
ActGetDocument result = new ActGetDocument();
result.outParamDocument = new RLDocumentRecordList();

DatabaseProvider dbaProvider = DatabaseAccess.forRunningApplication();
SqlHelper sqlHelper = dbaProvider.getSqlHelper();
RequestTransaction requestTransaction = dbaProvider.getRequestTransaction();
Command cmd = requestTransaction.createCommand();
String sql = String.format("SELECT * FROM osusr_m9y_document WHERE %s = %s",
sqlHelper.escapeIdentifier("ID"),
sqlHelper.prefixParam("id"));
cmd.setCommandText(sql);
cmd.createParameter(sqlHelper.prefixParam("id"), DBDataType.INTEGER.getIntValue(), inParamId);
try {
result.outParamDocument.setReader(cmd.executeReader());
} catch (Exception e) {
e.printStackTrace();
}
return result;
}

Just a note, I'm working on Bali version (9.1) and in this version DbType class doesn't exist, I had to use DBDataType.


Best Regards,
André

Solution

I'm still missing a way to adquire a dbConnection to run testcases in Eclipse instead of trying it in runtime in the dev environment, any suggestions?