Tuesday, February 9, 2010

A sample ADF BC application based on StoredProcedure

Sometimes you may need to use stored procedures/functions to read/write data from underlying tables. You can still leverage the benefits of ADF persistence layer by smartly wrapping the stored procedures using ViewObjects and EnityObjects.
I’m sharing a sample ADF BC application that uses stored procedures for reading and writing to the table.

Solution is simple and straight forward...
1. Create an EntityObject and override the below methods
   protected void doSelect(boolean lock)
   protected void doDML(int operation, TransactionEvent e)
Please refer the below topic in Fusion Developer's Guide to learn more …
38.5 Basing an Entity Object on a PL/SQL Package API

2. Define a ViewObject based on the above EntityObject. Override the below 'life cycle methods' to inject your custom code(for populating data form a REF CURSOR).
  protected void create()
  protected void executeQueryForCollection(Object qc, Object[] params, int numUserParams) 
  protected ViewRowImpl createRowFromResultSet(Object qc, ResultSet rs)
  protected boolean hasNextForCollection(Object qc)
  protected ViewRowImpl createRowFromResultSet(Object qc, ResultSet rs)
  protected void releaseUserDataForCollection(Object qc, Object rs)

Please refer the below topic in Fusion Developer's Guide to learn more…
39.8 Using Programmatic View Objects for Alternative Data Sources

You can download the sample workspace from here.
[Runs with Oracle JDeveloper 11g R1 PS1]
PS: Unzip the attachment and run the script(StoredProcedureExample/script) to set up the required DB objects for running this demo

Learn More ...

There are a lot more points like this. If  you are curious to learn the internals of the ADF Business Components and ADF Binding Layer,  the following book is for you - Oracle ADF Real World Developer’s Guide.
More details about this book can be found in this post- http://jobinesh.blogspot.in/2012/07/pre-order-your-copy-of-oracle-adf-real.html

4 comments:

JCFlack said...

You and your readers might also want to check out the PL/SQL API extension to ADF BC that was originally written by Avrom Roy-Faderman. It is in the Oracle Samplecode repository site at: https://database-api-based-adf-bc.samplecode.oracle.com/. You'll need an oracle.com id and registration in the samplecode site to see it, but this is free.

Jobinesh said...

Great news JCFlack. Thanks for sharing this information! Seems very promising. Will explore the project in detail, later this week.

Martin said...

Nice working sample, thank you. But I can't sort columns in table based on stored procedure. Is is possible to implement sorting for columns in such a table? Thanks

Jobinesh said...

Martin,
Sure, its possible. Will try to upload a working sample ASAP