Posts Tagged ‘application module’

Detecting if there is an open transaction somewhere in the application is needed in a lot of cases. Below is the code I have used to detect a dirty transaction in my Fusion Web Application and ROLLBACK if dirty is true.

try {
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest)context.getExternalContext().getRequest();
BindingContext bctx = DCUtil.getBindingContext(request);
DCDataControl dc = bctx.findDataControl(“MyAppModuleDataControl”);
MyAppModuleImpl am = (MyAppModuleImpl )dc.getDataProvider();

if (am.getTransaction().isDirty()) {
am.getTransaction().rollback();
}
} catch (Exception e) {
e.printStackTrace();
}

Committing through java code in your managed bean:

DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
OperationBinding operationBinding = bindings.getOperationBinding(“Commit”);
operationBinding.execute();

Rollback transaction through java code in your managed bean:

DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
OperationBinding operationBinding = bindings.getOperationBinding(“Rollback”);
operationBinding.execute();

Pay attention to the operation binding names, if you have CRUD operations from different application modules within the same page, those names will differ (generally: Commit1, Rollback1 etc)

There are several different methods on getting ViewObjects in ADF programmatically. It is possible to create a method within the Application Module Impl or your view object Impl class and then call that method through your managed bean or you can even call it directly within your managed bean but the first method is suitable.

1- Within the application module

ViewObjectImpl vo = getYourViewObject();
ViewCriteria vc = vo.getViewCriteria(“MyCriteria”);
vo.applyViewCriteria(vc);
vo.setNamedWhereClauseParam(“some_param”, anyParam);
vo.executeQuery();
Row row = vo.getCurrentRow();

2- Within your View Object

ViewCriteria vc = getViewCriteria(“MyCriteria”);
applyViewCriteria(vc);
setNamedWhereClauseParam(“some_param”, anyParam);
executeQuery();

3- Within your Managed Bean

AppModuleImpl am = new AppModuleImpl();
ViewObjectImpl vo = am.getYourViewObject();
ViewCriteria vc = getViewCriteria(“MyCriteria”);
vo.applyViewCriteria(vc);
vo.setNamedWhereClauseParam(“some_param”, anyParam);
vo.executeQuery();