Wednesday, October 3, 2012
ADF Custom SQL Builders
ADF allows us to create and configure custom SQL builders. Since ADF’s SQL builders don’t support all the SQL Flavors, there might be a need to create your own SQL Builder and configure it.
1. Create a SQL Builder Class.
You can create a custom builder class by extending one of the following classes
oracle.jbo.server.SQL92SQLBuilderImpl
oracle.jbo.server.BaseSQLBuilderImpl
or to extend current functionality of existing builders you can also extend
oracle.jbo.server.SQLServerSQLBuilderImpl
oracle.jbo.server.DB2SQLBuilderImpl
oracle.jbo.server.OracleSQLBuilderImpl
Below is a simple example to override query to get time from the database
package a.b.c.extn;
import oracle.jbo.server.SQLBuilder;
import oracle.jbo.server.SQL92SQLBuilderImpl;
public class MySQLBuilder extends SQL92SQLBuilderImpl
{
public MySQLBuilder () {
super();
}
public static SQLBuilder getInterface()
{
return new MySQLBuilder ();
}
/* (non-Javadoc)
* @see oracle.jbo.server.BaseSQLBuilderImpl#getDbTimeQuery()
*/
public String getDbTimeQuery()
{
return "select getdate()";
}
}
2. Configuring the Custom SQL builder in the application
In the adf-config.xml, go to Business Components Tab.
Change the SQL Flavor to Custom and in the SQL Builder Class, give the class name as shown below
<adf-adfm-config xmlns="http://xmlns.oracle.com/adfm/config">
<defaults/>
<startup>
<amconfig-overrides>
<config:Database jbo.SQLBuilder="Custom"
jbo.SQLBuilderClass="a.b.c.extn.MySQLBuilder" jbo.locking.mode="optimistic"/>
</amconfig-overrides>
</startup>
ADF - How to submit/post values changes to database immediately in ADF UI components
When you want to persist changes to a database as soon as a user changes the value in any of the UI Components. you can use the below technique.
1. Add a value change listener to your UI Component and also make Auto Submit to true.
<af:selectOneChoice value="{row.bindings.reasonCode.inputValue}"
label="#{row.bindings.reasonCode.label}" id="soc1" autoSubmit="true"
valueChangeListener="#{failures.reasoncodeChange}">
<f:selectItems value="#{row.bindings.reasonCode.items}" id="si1"/>
</af:selectOneChoice>
2. In the Backing bean value change listener method
valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());
Calling the the above line will do all the model updates. refer the link
public void reasoncodeChange(ValueChangeEvent valueChangeEvent) {
valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());BindingContainer bindings = getBindings();
OperationBinding operationBinding =bindings.getOperationBinding("Commit");
operationBinding.execute();
}
Subscribe to:
Posts (Atom)