Relational Types to XML Schema Types

9-48 Oracle Fusion Middleware Users Guide for Technology Adapters ■ Section 9.4.1.3.1, Using Relationship Queries TopLink Default ■ Section 9.4.1.3.2, Twisting the Original Select TopLink Batch-Attribute Reading ■ Section 9.4.1.3.3, Returning a Single Result Set TopLink Joined-Attribute Reading ■ Section 9.4.1.3.4, Comparison of the Methods Used for Querying over Multiple Tables The following sections contain an outline of these three methods and their comparison. However, note that when selecting rows from a single table there are no issues as against selecting from multiple tables.

9.4.1.3.1 Using Relationship Queries TopLink Default

Having selected a Master row, TopLink can always query separately to get all the details belonging to that Master table. These hidden queries relationship queries are cached in the TopLink metadata and need to be prepared only once. Consider the SQL statement in following sample scenario: SELECT DIRECTOR, ..., VIEWER_RATING FROM MOVIES WHERE RATING = A; For each master, the SQL statement is as follows: SELECT CRITIC, ..., TITLE FROM MOVIE_REVIEWS WHERE TITLE = ? It enables you to bring in all the data with 1 + n query executions, where n is the number of master rows returned by the first query. This approach is safe but slow, as a large number of round trips to the database are required to pull in all the data. For configuring using the relationship Queries TopLink default approach, you must edit or_mappings.xml outside of JDeveloper. In addition, change the batch-reading elements value to false.

9.4.1.3.2 Twisting the Original Select TopLink Batch-Attribute Reading

This is a default feature that allows TopLink to alter the original SQL select statement to read all the details in a second select statement, as shown in the following example: SELECT DIRECTOR, ..., VIEWER_RATING FROM MOVIES WHERE RATING = A SELECT DISTINCT t0.CRITIC, ..., t0.TITLE FROM MOVIE_REVIEWS t0, MOVIES t1 WHERE t1.RATING = A AND t0.TITLE = t1.TITLE By considering the original select statement in pulling in the details, a total of two 1 + 1 = 2 query executions need to be performed. Advantages Batch attribute reading has the following advantages: ■ All data read in two round trips to database Oracle JCA Adapter for Database 9-49 ■ The is a default feature in the 10.1.2.0.2 release Disadvantages Batch attribute reading has the following disadvantages: ■ When using maxTransactionSize on polling receive or maxRows on invoke select to limit the number of rows loaded into memory at a time, these settings do not easily carry over to the batch attribute query. It is easier to work with a cursored result when there is only a single result set. Multiple cursors can be used with difficulty, if the original query has an order by clause. ■ TopLink can alter a SQL statement, only when it is in a format it can understand. If you use the hybrid SQL approach and set custom SQL for the root select, then TopLink will not be able to interpret that SQL to build the batch select. ■ The DISTINCT clause is used on the batch query, to avoid returning the same detail twice if two masters happen to both point to it. The DISTINCT clause cannot be used when returning LOBs in the resultset. Configuration Configuration is on a per 1-1 or 1-M mapping basis. By default, all such mappings since the 10.1.2.0.2 release have this property set. To configure, edit or_ mappings.xml outside JDeveloper and edit the batch-reading elements to true default or false.

9.4.1.3.3 Returning a Single Result Set TopLink Joined-Attribute Reading

The detail tables are outer-joined to the original SQL select statement, returning both master and detail in a single result set, as shown in the following example: SELECT DISTINCT t1.DIRECTOR, ..., t1.VIEWER_RATING, t0.CRITIC, ..., t0.TITLE FROM MOVIE_REVIEWS t0, MOVIES t1 WHERE t1.RATING = A AND t0.TITLE + = t1.TITLE This requires one query execution in total. Advantages The advantages include the following: ■ In case of using maxTransactionSize while polling, the benefits of dealing with a single cursor can be great. ■ When following the hybrid SQL route and entering custom SQL statements, you only have to deal with a single SQL statement, whereas TopLink normally uses a series of additional hidden SQL statements to bring in related rows. ■ read consistency: Enables you to read all related rows at the same time, and not at different instances in time for the different tables. ■ Performance can be ideal as only a single round trip to the database is required, whereas batch attribute reading requires one for each table queried. Disadvantages There are some drawbacks, however, namely the cost of returning duplicate data. For example, consider that you read the Master and Detail tables; Master has 100 columns in each row, and Detail has 2 columns in each row. Each row in the table, Master also, typically has 100 related Detail rows. With one query in each table, the result sets for the preceding example appears, as shown in the following example: