You can dynamically define a new view object and add an instance of it
to an application module's data model at runtime by calling
createViewObjectFromQueryClauses()
on the application module.
Note: The view object instance you create will have exactly one entity usage and will not have an expert mode query. For more information, or to add an instance of a view object with zero or more that one entity usage, see the related topics list.
To add a view object instance with a new entity-based definition at runtime:
String
containing the name you want to give the
instance in the data model. For example, if this instance is to be
called OrdersForCustomer
, you would use the following
code:
String voInstanceName = "OrdersForCustomer";
String
containing the package-qualified name of
the entity object definition to be used. For example, if the view
object is to use an entity called Orders
and is in the
package orderentry.businessdomain
, you would use the
following code:
String eoDefName = "orderentry.businessdomain.Orders";
String
containing the SELECT clause of the SQL
query. Do not include the word "SELECT" in the String.
The clause must contain the same number of columns as the entity object has attributes (you will have a chance to add and remove view object attributes later). The columns in the clause are mapped to the entity attributes according to the order in which they appear in the entity object's XML file: The first column in the clause will map to the first entity attribute, the second column will map to the second, and so on. For example, if Orders has the following attributes:
then the following would be an acceptable SELECT clause:
String selectClause =
"ORDER_ID, ORDER_DATE, ORDER_MODE, CUSTOMER_ID, " +
"ORDER_STATUS, ORDER_TOTAL, SALES_REP_ID, PROMOTION_ID";
Warning: Be very careful to match up the order of
the query columns with the order of the appropriate entity object
attributes. Providing an incorrect order can lead to a
RowInconsistentException
or even corrupt data, as the data
retrieval mechanism of the view object and the data manipulation
mechanism of the entity object conflict.
String fromClause = "ORDERS";
String
containing the WHERE clause of the SQL
query. Do not include the word "WHERE". If you do not want al WHERE
clause, use null
. For example, either of the following
could be appropriate definitions:
String whereClause = "ORDER_TOTAL > 500";
String whereClause = null;
null
. For example, either of the following
could be appropriate definitions:
String orderByClause = "ORDER_TOTAL";
String whereClause = null;
ViewObjectFromQueryClauses()
passing in all of
these Strings:
viewObject ordVO = myAM.createViewObjectFromQueryClauses(
voInstanceName, eoDefName, selectClause, fromClause,
whereClause, orderByClause);
Note: If you create a view object using this method,
the query may be executed twice the first time you fetch data. The first
query collects data type and precision information, which is used in
subsequent queries to map data to the proper Java types and make the
query more efficient (by specifying precision where it is below the
maximum). For expensive queries, where executing twice causes a
performance problem, you may want to create the view object with a
"dummy" where clause that returns no rows, call
getAttributeCount()
on the view object to facilitate the metadata
query and attribute definition, and then call setQuery()
to
change the query to the one you want. This way, the initial query is a
trivial, and far less expensive, query on the same dataset.
Ways to Add a View Object
Member to the Data Model at Runtime
About View Object Attributes
About Oracle
ADF View Objects
About Oracle ADF
Application Modules
About View
Object and View Link Instances
Accessing a Root-Level Application Module
Finding View Object Instances in the Data Model
Adding a View Object Instance Based on a Predefined View Object at Runtime
Adding a View Object Instance with a New SQL-only Definition at Runtime
Copyright © 1997, 2004, Oracle. All rights reserved.