Using the Editors |
Table views and links are widgets used to provide Panther with the information it needs to support database access, specifically for the transaction manager in database applications. A table view is a group of widgets on a screen, generally from the same database table. If there is more than one table view on the screen, links define the relationships between two table views.
This chapter describes using and creating table views and links, and how their property settings are used by Panther's transaction manager to effect automatic SQL generation. Refer to Chapter 33, "Using Automated SQL Generation," in Application Development Guide for details on automated SQL generation.
To use the transaction manager:
The table views and links on your application screens provide the transaction manager with the information it needs to access your database.
Using Table Views |
A table view—since it is a group widget—is not visible on the screen in the screen editor or at runtime; however, the widgets that make up the table view are visible. The table view is a set of related widgets, usually associated with and named for a single database table. The table view must be present on the screen if you want to use the transaction manager to provide automatic database access.
A table view is automatically created on each repository entry when you import a database table into a repository. When you copy a database-derived widget from a repository entry, Panther creates a table view on the destination screen, provided the copied widget belonged to a table view in the repository entry.
You can also include additional members (widgets) in a table view that are not a part of the database table in order to display derived data.
To access a table view's properties, do any of the following:
The Properties window displays the properties associated with the selected table view.
The transaction manager uses table view properties (and link properties, discussed later in this chapter) to execute its commands. Table views are identified by the following properties, many of which are automatically defined through the import process. Refer to "Populating a Repository with Database Objects" for information on the import process.
The following properties define the name of the table view and its source of inheritance, and provide for additional comments and programming use.
Identity Properties
tview
followed by a number. Table views are numbered sequentially. Rename manually created table views to something more descriptive and useful for your development needs.
repositoryEntry!repositoryTable View Name
. This value is provided automatically when a table view is copied from a repository entry.
memo1...memo9
) for additional comments or for entering string expressions to use programmatically.
The following properties define how the selected table view is used by the transaction manager:
INSERT
, UPDATE
, and DELETE
statements during automatic SQL generation. The possible settings are:
You can specify a transaction model in the Model property under Transaction at the following levels:
The Table, Columns and Primary Key properties define how the selected table view is defined in the database; they are automatically set when a database table or view is imported. The Insert Handling, Update Handling and Delete Handling categories determine how processing occurs for these operations.
FROM
clause of the SQL statement.
WHERE
clause of the SQL UPDATE
and DELETE
statements generated for the selected table view.
The following properties define how the server view fetches data. A server view is either a single table view or a group of table views connected with server links. The setting for the Method property determines which sub-properties are displayed.
ASC
, for ascending (default), and DESC
, for descending, and are case insensitive.
The SQL generator uses the widget name to determine the associated column or select expression to be sorted when generating a SQL SELECT
statement.
DISTINCT
keyword in the automated SQL SELECT
statement. This eliminates duplicate rows in the results.
Refer to "Eliminating Duplicate Rows in a Result Set" in Application Development Guide for more information.
fetch_directions
)
(For JetNet/Oracle Tuxedo only) The following properties define the type of transaction manager command that a service implements in a three-tier architecture. These Service properties are automatically set for the root table view on client screens and selection screens (if any) when you use the screen wizard to generate your screens.
If you specify these properties in the editor, they must only be set for the root table view. Check that the service component contains all needed widgets from the client screen for all server views.
Panther's SQL generator uses properties found under Database and Server View in the Properties window to generate SQL statements. Panther's transaction manager—via the SQL generator—can construct SELECT
, INSERT
, UPDATE
, and DELETE
statements using the property specifications for table views on the screen. To control or change the generated SQL, you can change the Database or Server View properties for widgets representing database columns, table views, or server views.
When you copy widgets from a repository entry that was created as the result of the import process, most of the properties that the SQL generator needs are set automatically. If you want to modify the SQL, you can change the property specifications. For more information about automatically generated SQL statements, refer to Chapter 33, "Using Automated SQL Generation," in Application Development Guide.
When you populate a screen with widgets from a repository that was created as the result of the import process, a table view is automatically copied to your application screen as well. You can have multiple table views on a screen—each representing a different database table.
However, you can create table views manually if you want to:
How to Create a New Table View
Note: If any widget in your selection set is currently a member of another table view, it will be removed from that table view and added to the new one. In other words, a widget cannot be a member of two different table views.
The table view is created and currently selected. It is given a default name, tview#
.
To display or identify those widgets that compose a table view on your screen, you can use either of two methods: select the table view or select one member of the table view.
You can add members to an existing table view to:
How to Add Widgets to a Table View
If you omitted a widget that was originally a table view member, it will no longer be a part of any table view. Repeat the procedure to update the table view's membership.
The root table view determines the basis of the event processing occurring on a screen. In most cases, the transaction manager sets the root table view automatically. A root table specification must be set (to Default or to a table view name) if you want the transaction manager to perform the screen's transaction processing.
If the transaction manager is unable to determine the root table view for the screen, either because the Root property is set to None, or Default and the transaction manager is unable to determine the root table view, the following error message is displayed: "Root table view name not supplied or not valid." Make sure the Root property under Transaction for the screen specifies the correct table view.
In a master-detail screen, the database table which is the master would be the root table view.
Root table view name not supplied or not valid
and Transaction unspecified or unavailable
. Specify the root table view by name instead.
Using Links |
A link defines the relationship between two table views. If a screen contains more than one table view, you need to have a link describing the relationship between the two tables.
When you import a database table to the repository, the import process automatically creates links on the repository entry that correspond to the foreign key definitions for that database table. When you copy database-derived widgets to your application screens, you can copy the links directly from the repository entry or create links on your screen.
If a link does not exist for a pair of table views on your screen, you need to create it manually. The ability to join information from multiple database tables is based on the premise that a relationship exists between each of the represented tables on your screen. Therefore, for every pair of table views on your screen that will participate in a join operation with each other, you need a link widget to define the relationship. Links have their own properties—you can define the type of link as well as the parent-child relationship of the table views.
Use the DB Interactions window to display a graphical representation of the relationships between multiple tables on your screen. The link properties defined for a screen apply only to a single screen. Therefore, on other application screens, you can rearrange the relationship between the tables.
You cannot have a cycle appearing in the link specifications. For example, if link1
declares the customers
table to be the parent and the rentals
table to be the child, link2
cannot have the rentals
table be the parent and the customers
be the child.
To access and edit link properties, select the link widget on your screen by doing any of the following:
The following properties define the name of the link, the link's source of inheritance, and a location for additional comments as well as programmatic use:
Identity Properties
K#table_name
. For example, the repository entry titles
has a link widget named K1titles
. If there was a second link on the entry, its name would be K2titles
.
repositoryEntry!linkName
. This value is provided automatically when a link is copied from a repository entry.
memo1...memo9
) for additional comments or for entering string expressions to use programmatically.
The transaction manager uses the following properties to tell the SQL generator to build the appropriate SQL statement. Most of these properties obtain their values automatically via the import process.
SELECT
statements. The SELECT
for the parent table view is performed first, followed by the SELECT
statement for the child table view. The joining of the two table views occurs because the results from the first SELECT
statement provide the information needed by the second SELECT
statement. Refer to "How to Join Two Tables with a One-to-Many Relationship" for details on creating a sequential join.
For example, to find all the video rentals for a customer, you would specify a Sequential link type between the customers
and rentals
tables. One row in the customers
table has the potential of having several associated rows in the rentals
table. The processing for the customers
table is done first, followed by the processing for the rentals
table.
SELECT
statement. Server links are possible when there is a one-to-one relationship between the rows in each of the table views. Refer to "How to Join Two Tables Using a One-to-One Relationship" for details on creating a server join.
For example, to find the title for each video rented by a customer, you would specify a Server link type between the If the Type property is set to Server, there is a subcategory called Join Type which lets you take advantage of SQL join facilities. You can use this to control the join operation of any rentals
and titles
tables. For every rented video, there is an associated title; there is a one-to-one relationship between the title_id
in the rentals
table and the title_id
in the titles
table.
SELECT
statement which combines information from two database tables. The four choices are:
PV_INNER
—Fetches all possible pairs, but excludes those rows that do not meet the matching column condition for the join.
PV_FULL_OUTER
—Fetches rows from both tables even if when there is no (NULL) match.
For an example using the various join types, refer to "Specifying the Join Type" in Application Development Guide.
In addition to defining the join condition in a WHERE
clause, you can also define a lookup specification whereby the data entered by the user at runtime can be used to fetch database column information when new or updated records are added to the database (refer to "How to Define a Lookup Specification for Either Link Type").
INSERT
statement first: Parent First (default) or Child First. SQL statements are generated for both the parent table and the child table.
UPDATE
statement first, Parent First or Child First (default). SQL statements are generated for both the parent table and the child table.
DELETE
statement first, Parent First or Child First (default). SQL statements are generated for both the parent table and the child table.
(JetNet/Oracle Tuxedo only) The following property defines which service the transaction manager uses to implement a Validation operation (in a three-tier architecture). This property is automatically set for link widgets on client screens when you use the screen wizard to generate your screens.
In general, joins are built by comparing pairs of columns from two joined tables by testing the data from both columns for equality or other comparisons. Sometimes these joins have a one-to-one relationship while others have a one-to-many relationship. Most common multi-table queries use parent/child relationships created by primary keys and foreign keys. Panther lets you define these relationships by letting you define the join type and the relationship between table views.
Joining two tables with a one-to-many relationship creates a sequential join:
When the SQL statement is generated, the WHERE
clause associated with the Child table's column uses the value in the Parent table's column.
+0
):
::widget_name
[+0]
join
—in the Rel (center) column of the Relations dialog box. The only relationship that can be specified for a join is the word join
.
For each join relation specified, the WHERE
clause will include one expression of the form:
widget_data_in_parent_tableview
=child_table.child_column
Joining two tables with a one-to-one relationship creates a server join, which displays multiple records using a single condition.
The columns you specify are used to build the SQL join condition in a WHERE
clause.
join
—in the Rel (center) column of the Relations dialog box. The only relationship that can be specified for joins is the word join
.
For each join relation specified, the WHERE
clause will include one expression of the form:
parent_table.parent_column
=child_table.child_column
Figure 22-1 The Relations dialog box lists the parent and child relationships for the selected link.
If there are multiple joined columns, then the expressions are connected by the keyword AND
. If more than one table view in the server join represents the same database table, the SQL generator automatically supplies table alias names as needed. Therefore, self-join expressions are automatically handled.
Optionally, you can look up a Child column in the database based on a value the user enters into the widget associated with the Parent column. The lookup is based on the specified join relationship that you defined in steps 3 and 4 for server or sequential joins.
Note: Lookup specifications are used only when adding (inserting) and updating records.
If the parent column is represented on the screen by two different widgets, enter the widget's name instead using the following format (including the square brackets and the literal +0
):
::widget_name
[+0]
lookup
in the center column of the Relations dialog box.
Figure 22-2 This specification takes the customer id entered by the user to find the corresponding last name in the database table.
The links that are defined for a screen can be used to specify validation links. When a validation link exists, you can enter a value in a field, in either New or Update mode, and the transaction manager looks up that value in the linked database table. If the value exists, it displays data for any widgets in the child table view. If the value does not exist, it displays the error Invalid Entry
.
The parent table view in the link contains the text widget. The database table associated with the child table view contains the pre-existing values.
Validation link processing is only performed in New and Update modes, as part of the NEW
, COPY
or SELECT
commands, when you are entering or updating data. Since the data in the child table view should already be entered in the database, set the child table view in a validation link to be non-updatable.