Creating Updateable, Multi-Entity View Object Definitions Dynamically

Send me a mail
 Dive into Oracle ADF   Click to see the XML version of this web page.   (Updated: 2/3/2008; 9:24:48 PM.)
Tips and tricks from Steve Muench on Oracle ADF Framework and JDeveloper IDE

Creating Updateable, Multi-Entity View Object Definitions Dynamically

Of course, if you know the query and the relationships between entities at design time, it's preferable and simpler to use the View Object wizard to create your view object definition at design time. But, if you have an application that is dynamic to the point that you could not know the view definition information until runtime, it's possible to create a new view definition programmatically. This downloadable example, DynamicMultiEntityViewDef.zip, illustrates how to do it.

The API's to create a new View Definition live in the oracle.jbo.server package, so they are not intended to by used directly by clients. Instead, you should write code in your application module impl class (as illustrated in the sample) to construct a new ViewDefImpl instance, and proceed to call appropriate methods on the ViewDefImpl object to setup the various aspects of its definition.

As the createDynamicMultiEntityViewDefinition() in TestModuleImpl.java shows, you pass a fully-qualified view definition name like my.dynamic.EmpDeptView into the ViewDefImpl contructor. Then you proceed to invoke methods on the object to add the entity usages (indicating which entities particpate in the view object and with what "alias" names). Finally, you call methods to add each view object attribute definition. The example illustrates adding entity mapped attributes, SQL-calculated attributes, as well as transient attributes.

To make things easier to follow, I've created some private helper methods to clarify what's going on and have included comments to explain each one.

Finally, the TestClient.java client driver program illustrates working with the dynamically created view object, and illustrates that it is updateable.

Hope the example helps understand why it's so much simpler to define things at design time.



© Copyright 2008 Steve Muench. Click here to send an email to the editor of this weblog.
Last update: 2/3/2008; 9:24:48 PM.