Sunday 14 September 2008

JDev 11g ADF BC – New feature "Declarative View Objects"

Following on from my Property Sets post, another new feature in ADF Business Components for JDeveloper 11g is the "Declarative View Object".

To create a Declarative View Object, you need a View Object based on an Entity Object, and under the Query page of the View Object Wizard or Editor, you set the SQL Mode to Declarative:


On switching a View Object to the Declarative SQL Mode option you'll notice the Wizard/Editor hides the SQL Query from you, instead providing an interface to modify the Where clause by selecting and/or constructing View Criteria, and selecting View Object attributes to participate in the Order By clause.


The key to Declarative View Object is they calculate the SQL statement to execute at runtime from the underlying Entity Object's database table and attribute database columns. With the previous Normal and Expert modes, the SQL query was effectively defined at design time by the programmer. The Declarative VO approach reminds me of how Oracle Forms works, in the fact that Oracle Forms uses the Block-table and Item-column mappings to construct the SQL statement at runtime; there is no complete SQL query you can look at design time in Forms.

The main advantage of Declarative mode is it removes the need to understand SQL queries, including the Where and Order By clauses. The query is now effectively hidden from the programmer.

I can hear a million Oracle programmers asking "why would we want to do that?" Taking the broad idea that not all programmers are born equal, and not all programmers know SQL, moving to a Declarative approach will assist such non-SQL-savvy programmers, as well as beginners or business users in working with ADF.

Another advantage is this approach uses the new 11g VO View Criteria feature in specifying the filtering Where clause. The View Criteria feature is a powerful one as it allows the programmer to name each Where clause essentially, and reuse that Where clause throughout the program, potentially in combination with other named View Criteria. For an example of this reuse have a look at how the new LOV controls in ADF Faces Rich Client support the defined View Criteria.

Obviously Declarative View Objects aren't for everyone, but they provide an interesting new feature extending the declarative programming concept in JDeveloper. Soon there wont be much programming left to actually do!

One caveat I need to state with this post, and I forgot previously with the Property Sets post, is this feature is currently available in the JDev 11g Drop 6 release (and potentially TP4) that the Oracle ACE Directors have access to. There's the possibility it wont be in the production release, but maybe we'll know for sure in a week or so.

1 comment:

Steve Muench said...

Chris, another interesting feature of the runtime-SQL-generation capability of declarative SQLMode view objects is that their runtime SQL can be informed by some new API calls about which view attributes are needed by the current use case and consequently prune the generated SQL based on this knowledge. The ADFm data binding layer makes automatic use of this new API so that the ADFm/ADFbc combination (when using declarative SQLMode VO's) just works out of the box. Of course you can call the API programmatically, too. See the ApplicationModule.prepareViewObject() API. Internally, it turns around and calls some ViewObjectImpl API's that set the list of selected attributes on each VO that is prepared in this way.