Search This Blog

Thursday, September 29, 2011

OAF - Calling Database sequence

Calling a Database sequence.
Traditional way of calling a sequence was to create a View object with a "select sequence.nextval as seqvalue from dual" and call something like below.

OAViewObject vo = (OAViewObject)am.findViewObject("sequencename");
OARow row = (OARow) vo.first();
Number seqvalue = row.getAttribute("seqvalue"));

But instead oracle provides a direct API to get the value of the sequence and can be used as below.

// Calling from within an Application Module.
OADBTransaction trx = getOADBTransaction();
Number seqnum = transaction.getSequenceValue("sequencename");

//Calling from controller
OAApplicationModule am = (OAApplicationModule)pageContext.getApplicationModule(webBean);
OADBTransaction transaction = (OADBTransaction)am.getOADBTransaction();
Number seqvalue= transaction.getSequenceValue("sequencename");

No comments:

Post a Comment