You can create default view objects for your entity objects in the Entity Object Wizard, but these view objects are very simple in their definition. The View Object Wizard lets you create view objects that can be tailored for your needs. Use the View Object Wizard if you want to create a view object which uses:
A subset of an entity object's attributes
More than one entity object
Special calculated or transient attributes
Non-default storage and updateability features
A view object joins, filters, and sorts business data, shaping it for presentation. view objects encapsulate SQL code and metadata that maps columns in a SELECT statement to attributes of one or more entity objects. View objects provide clients with rowsets they can scroll through and update without concern for or knowledge of the underlying entity objects.
To create a view object, you must first have an open business project. If you already have a business project which contains objects, you have two options:
Select File | New, choose the Business Components tab, and double-click the View Object icon.
In the Navigation pane, right click a package in your business project and choose Create View Object from the context menu.
In either case, the View Object Wizard opens:
If the Welcome screen appears, click Next to continue.
Replace the default in the Name field with an view object name that will be meaningful to your client applications. In the Package field you can accept the default package where the object will reside, or you can choose another package by clicking Browse. When you are finished with the Name page, click Next.
Note: The Extends field lets you extend the functionality of an existing view object without having to modify the source code. See Extending Java and XML for Business Components for details.
In the Entity Objects page, select the entity objects from the Available list that you want to be referenced by the view object. Use the right-arrow to move selected entity objects to the Selected list. You can provide an alternate name for the selected entity objects in the Alias field.
If you select the Read Only checkbox, attributes from the corresponding entity object cannot be edited from this view object. By default, when you move entity objects to the Selected list, the first entity object is updateable; subsequent entity objects are read-only. You can change the updateability of any entity object in the Selected list by selecting the entity object, then selecting or clearing the Read Only checkbox. The ability of a view object to have multiple updateable entity objects enables one of the key features of Business Components for Java: a single view object can update multiple entity objects.
If you select the Reference checkbox, attribute values for the entity object are dynamically fetched from the entity cache when a controlling key attribute changes.
When you are finished with this page, click Next.
In the Attributes page, choose the entity object attributes that you want included in the view object. Click New to create a calculated or transient attribute. When you are finished with this page click Next.
In the Attribute Settings page choose storage and update properties for the view object attributes you select in the Select Attribute dropdown list.
Attribute group:
Mapped - When this option is selected, the selected attribute will be mapped to the corresponding column in the Query Column pane.
Mandatory - When this option is selected, each view object row must have a non-null value for the selected attribute. If it does have a null value, the row is considered to be invalid.
Persistent - When this option is selected, the attribute will be saved in persistent storage. Transient or calculated fields are not persistent. It is important to understand that data from non-persistent fields that you introduce into the view object will not automatically be generated in the database. If you want to save your data, you must use forward generation; otherwise, you should avoid introducing transient attributes.
Always Updateable - This option is selected by default. The attribute value can be updated or changed even after it has been committed to the database.
While New - When this option is selected, the attribute can be updated or changed only before it is part of a new, uncommitted view object. After it is committed to the database, the value cannot be changed.
Never Updateable - When this option is selected, the selected attribute cannot be updated using the framework. For example, you would probably want to select this option when the attribute value is calculated by the database, a transient attribute, or if the value represents a part of a sequence or a unique ID.
Query Column group:
Alias - By default, this field displays the name of the database column corresponding to the attribute name chosen in the Select Attribute field. You can change this name if you want. The alias will be used in the AS clause of the generated SQL statement. For example, if you enter myEname as the alias for the Ename attribute, the generated SQL will display the clause Emp.Ename AS myEname.
Expression - This field displays an expression if you selected a calculated or transient attribute in the Select Attribute field. You can use this field to edit the expression.
Queriable - When this option is selected, the selected attribute can participate in a query condition. If this checkbox is not selected the information cannot be queried. For example, it cannot participate in a query form. Whether an attribute is queriable is also a function of its datatype. For example, BLOBs are not queriable. In this case, if you selected an attribute of BLOB datatype, the Queriable checkbox would not be selectable.
When you are finished with this page, click Next.
In the Query page, you have the opportunity to view and edit the WHERE and ORDERBY clauses of the SQL statement used to query the database. In the OrderBy field, you can click Browse to choose attributes by which to order the query results. The page also offers a convenient Test button where you can test that your SQL is syntactically valid.
If you want to use bind parameters in any of your SQL clauses, select Use ? style parameters when you want to use the question mark (?) parameter style instead of the colon (:) style. You will need to use the same style in the View Link query definition.
If you need even more flexibility in specifying your query statement, select the Expert Mode option. The contents of the Query page changes, giving you an editable area where you can edit the entire query, or paste a query from another source. There are no limits on the length or complexity of the query you can enter. Like normal mode, you can browse for OrderBy attributes and test the validity of your SQL code.
You also have the option of entering your custom SQL query directly into the generated XML file. For more information see Pasting a Custom Query in a View Object XML File.
Note: If you make changes to the query in Expert Mode, then clear the checkbox to return to normal mode, your query edits will be discarded.
When you are finished with this page, click Next. If you click Next in Expert Mode, the Attribute Mappings page opens. If you click Next in normal mode the Java page opens.
The Attribute Mappings page gives you the opportunity to re-map query columns to object attributes if you deleted, added, or switched positions of columns in your custom SQL statement. To change the mapping, click an attribute in the right side of the grid. A dropdown list lets you select another attribute to map to the query column. You can also remove the mapping for a particular query column. Query columns that are not mapped cannot be updated. When you are finished with this page, click Next.
The Java page provides options that let you generate classes (that is, *Impl classes) for the view object and the View Rows. After the framework creates these classes, you can edit them to customize the view object's behavior:
Select Generate Java file to generate a class that extends (inherits from) the *ViewObjectImpl class. If you want to extend a different class, click Extends to view the Framework Base Classes dialog box. Click Browse to search for superclasses using the Find Superclass dialog box. You can edit the generated class if you want to customize the view object's methods.
Select Generate Java file for the View Row Class to generate a class that extends (inherits from) the *ViewRowImpl class. If you want to extend a different class, click Extends to view the Framework Base Classes dialog box. Click Browse to search for superclasses using the Find Superclass dialog box. By default the Generate accessors checkbox appears selected and generates get and set methods. You can edit the generated class if you want to customize the View Row's behavior.
When you are finished with this page click Next.
If you selected the Generate Java file option, the Business Component for Java framework generates a .java and .xml file for your view object and displays their names in the Navigation pane. If you did not select the Generate Java file option, the framework generates only an XML file.