Application Modernization DB2 For i5OS
Application Modernization DB2 For i5OS
About the authors.................................................................................................................. 2 Introduction ........................................................................................................................... 3 Agenda.................................................................................................................................. 4 Why SQL?............................................................................................................................. 5 Approaches and options ....................................................................................................... 7 Approaches and options (continued) .................................................................................... 8 Modernizing definitions and objects ...................................................................................... 9 Modernizing database objects: Terminology....................................................................... 10 Modernizing database definitions and objects: Tables or physical files.............................. 11 Modernizing database definitions and objects: Indexes or logical files............................... 13 Modernizing database definitions and objects: Views or logical files (continued)............... 15 Modernizing database definitions and objects: DDS-to-SQL conversion tool..................... 16 Modernizing database definitions and objects: DDS-to-SQL conversion tool..................... 17 Modernizing database definitions and objects: SQL object management .......................... 18 Modernizing database definitions and objects: SQL object management .......................... 19 Modernizing database definitions and objects: SQL object management (continued) ....... 20 Modernizing database definitions and objects (continued) ................................................. 21 Modernizing definitions and objects: SQL and nonrelational data ...................................... 22 Modernizing definitions and objects: Moving business logic into DB2 (automatic key generation) .......................................................................................................................... 23 Modernizing definitions and objects: Moving business logic into DB2 (constraints) ........... 24 Modernizing definitions and objects: Moving business logic into DB2 (triggers)................. 25 Modernizing data access .................................................................................................... 26 Modernizing data access: Programming interfaces ............................................................ 27 Modernizing data access: Native I/O to SQL example........................................................ 28 Modernizing data access: Native I/O to SQL example (Joined Logical Files and Views) ... 29 Modernizing data access: Native I/O to SQL example (performance comparison) ............ 30 Modernizing data access: Comparing SQL and native performance.................................. 31 Modernizing data access: Native to SQL considerations.................................................... 32 Modernizing data Access: Using SQL to reuse and repurpose existing code .................... 34 Modernizing data access: Using SQL to reuse and repurpose existing code (UDFs) ........ 35 Modernizing data access: Using SQL to reuse and repurpose existing code (procedures) 36 Modernizing data access: DB2 and new application models (distributed transactions)...... 37 Modernizing data access: DB2 and new application models (Web services) ..................... 38 Modernizing data access: DB2 and new application models (XML and text mining).......... 40 Modernizing data access: Development tools..................................................................... 41 Modernizing data access: Development tools (continued).................................................. 42 Next steps ........................................................................................................................... 43 DB2 Family certifications..................................................................................................... 45 Summary............................................................................................................................. 46 Links.................................................................................................................................... 48 Trademarks and special notices ......................................................................................... 50
Page 1 of 50
Page 2 of 50
IBM System i
Mike Cain and Gene Cobb DB2 for i5/OS Technology Team ISV Business Strategy and Enablement - System i
Introduction
The IBM System i Developers Road Atlas (formerly called the iSeries Developer Roadmap) is one of the key initiatives from IBM in helping System i developers modernize their existing applications and toolsets. The SQL programming language and IBM DB2 for i5/OS are two modern tools that help programmers move toward more responsive, Web-enabled applications. This online course explains the modernization steps on the Road Atlas from an SQL and DB2 for i5/OS point of view.
Page 3 of 50
Agenda
Why modernize with SQL and DB2 for i5/OS? Approaches and options Modernizing database definitions Modernizing data access Next steps
Agenda
This course first discusses why you might want to modernize the DB2 aspects of your application and use SQL. Next, there is a discussion of the possible approaches and methodologies for DB2. Then, this course goes into detail on the two approaches to DB2 modernization: modernization of the database objects and their definitions (for example, moving from data-definition specifications [DDS] to SQL) and modernization of the dataaccess interfaces in application programs (for instance, moving from native I/O to SQL). This course concludes with some possible first steps you can take in modernizing applications from a DB2 and SQL perspective.
Page 4 of 50
Why SQL?
Portability of code and skills Strategic database interface for industry and i5/OS
SQE delivers faster performance (only available to SQL-based interfaces) SQL is required for certain functions and middleware
J2EE architecture based on SQL interfaces Data types: BLOB, CLOB, Datalink and others Auto-incrementing constructs: Sequence and identity column attribute Column-level triggers Encryption and decryption functions Encoded-vector indices others
Enables better positioning of System i as a database server As a programming language, SQL can reduce total lines of code DB2 symmetric multiprocessing (SMP): Parallel database processing
Why SQL?
Why should a System i developer consider using SQL? Obviously, the portability of SQL statements is one thing people latch onto, because that is the industry standard. System i DDS and native I/O interfaces are not supported on other platforms. A portability issue often overlooked is the portability of SQL programming skills. Many enterprises and application development organizations have switched to programming with SQL for this very reason it is easier to find a programmer with SQL skills than a programmer with RPG skills. Just like Java, using SQL to develop applications provides a bigger pool of programmers from which to hire. Almost all of the new solutions use SQL, which is one reason why IBM has made SQL the strategic interface for the System i platform and has put much of its research and development investment into enhancing SQL. The native (that is, non-SQL) interfaces are here to stay, but the functional improvements are primarily for SQL interfaces only. This graphic lists some SQL-only enhancements. In IBM OS/400 Version 5 Release 2, IBM delivered the SQL query engine (SQE). The improved performance offered by this new database engine is only available to SQL interfaces; native I/O interfaces receive no benefit now or in the future. Several functional capabilities also require the use of SQL. The Java 2, Enterprise Edition (J2EE) architecture obviously is based on SQL interfaces to data such as Java Database Connectivity (JDBC). The binary large object (BLOB) and character large object (CLOB) data types can only be used in SQLcreated tables. DB2 for i5/OS supports both SQL and external triggers, but only SQL triggers allow triggers to be defined at a column level. Encoded-vector indexes (EVI) are yet another example of a DB2 object that can only be created with SQL. An advantage of using SQL is that when you start incorporating more modern aspects of the DB2 for i5/OS database, it is easier to convince Microsoft and Java developers in your shop that using the System i platform as a database server is a viable option. Those developers are accustomed to using stored procedures, triggers and automatically generating columns. If those developers know that those capabilities exist
Page 5 of 50
in your DB2 for i5/OS databases, there is a greater likelihood they will write new applications or change existing applications to use your System i model as a data store. As a programming language, SQL can reduce the total lines of code that a developer has to write, because SQL is designed to work on a set of rows (or records) at a time. In comparison, native I/O works with one row at a time. A single SQL request can process multiple rows of data in one request; in the native I/O world, this takes multiple operations. DB2 Symmetric Multiprocessing (SMP) enables a single DB2 request to run in parallel across multiple processors. With SQL, parallel processing is essentially enabled by turning on the DB2 SMP feature. If you want to run parallel processing with the non-SQL interfaces, you basically have to physically change your application. The application has to be broken into partitions so each partition can run concurrently to benefit from a system with multiple processors.
Page 6 of 50
Network
Host server
Static
Compiled embedded statements
CLI, JDBC
Extended dynamic
Prepare once, then reference
Dynamic
Prepare every time
SQL Optimizer
Page 7 of 50
SQL-created objects
SQL programs
DDS-created objects
Native* programs
Page 8 of 50
Page 9 of 50
SQL
Schema or collection table view index row column log
i5/OS
library physical file logical file keyed logical file record field journal
Page 10 of 50
Disadvantages
Slower writes No DDM, but SQL can utilize DRDA connections Multimember files
SQL ALIAS provides the solution: CREATE ALIAS JanSales FOR SALES (JANUARY )
Page 11 of 50
If you want to use data modeling tools, you have a better chance of finding tools that support DB2 for i5/OS if you use SQL to create your database objects instead of DDS. One other behavioral difference is that DB2 automatically tries to journal SQL tables. As mentioned, SQL schemas are created with a journal. DB2 looks for that schema-created journal after every CREATE TABLE request. If a journal is found, DB2 automatically journals the newly-created table to that journal. If you want to use journaling to improve database recovery and availability, this automatic-journaling behavior is simpler. If you do not plan to journal DB2 objects, you need to be aware of this default behavior and modify it accordingly (disable journaling). There are a few things to be aware of when using SQL. Distributed Data Management (DDM) SQL tables do not exist because SQL has a different solution. Instead of having a DDM file (which is an object that redirects a request to a different system), SQL uses a Distributed Relational Database Architecture (DRDA) connection. The SQL Connect statement is used to redirect your database processing to a different system or server. The database request then references the table name on that remote DB2 server directly (as opposed to the indirect access offered by DDM files). As mentioned, SQL does not support multimember files. Table-partition support in i5/OS V5R3 offers similar capabilities, but that support is limited by some performance issues that must be CAREFULLY researched before creating partitioned tables. If you have multimember files, but want to access them from an SQL application, then SQL aliases must be used. An SQL alias is a one-time setup step in which you create an alias for each member in a physical file, as demonstrated at the bottom of this chart. Then, your applications that use SQL can reference this alias name anywhere on an SQL statement that allows table names. An SQL programmer does not have to be concerned that they are accessing the fifth member of a multimember file because they know they are using an alias that allows access to that particular data set.
Page 12 of 50
Disadvantages
8 KB logical-page size No support for Select/Omit filtering or Join logical files
Page 13 of 50
settings are shown in blue in this graphic; they can improve journal performance when dealing with the larger page size. SQL indexes can be opened as keyed logical files for native I/O; this gives you native capabilities after switching from keyed logical files to SQL indexes. The SQL index record description makes all columns available when an index is opened as a logical file. SQL indexes are limited by the fact that they do not have a way to subset the keys (as do DDS-created Select and Omit logical files). This enhancement for SQL indexes is on the list of possible future enhancements for DB2 for i5/OS.
Page 14 of 50
Disadvantages
Views cannot be keyed or ordered
Does that mean Views have slower performance? NO, assuming that the right set of indexes and statistics are in place for the query optimizer to use. View is used by SQL to transform data; the query optimzer's job is to find the best method to speed up selection or sorting. The fastest method might not be a keyed access method.
Page 15 of 50
Can convert a single object or a group of objects Output can be edited and saved directly into source-file members
Page 16 of 50
Page 17 of 50
SQL Table definitions can use Field Reference File CREATE TABLE customer AS (SELECT id cust_id, lname cust_lastname, fname cust_firstname, city cust_city FROM RefFile) WITH NO DATA
Page 18 of 50
SQL Column and Object names have maximum lengths of 30 and 128 (respectively). But, many i5/OS utilities, commands and interfaces only support a 10character length. How does that work?
System automatically generates a short 10 character name
First five characters with unique 5-digit number
CUSTOMER_MASTER >> CUSTO00001
Might be different each time a specific table is created, depending on creation order and what other objects share the same five-character prefix Use i5/OS SQL syntax to specify your own short name
RENAME TABLE (tables and views) and RENAME INDEX FOR COLUMN clause for columns SPECIFIC clause for procedures, functions
Page 19 of 50
If a long name specified on SQL Table definition, you can also add or control the short name after the table is created:
RENAME TABLE dbtest/customer_master TO SYSTEM NAME cusmst
Page 20 of 50
RENAME statement also controls the format and file name used by native programs
1. Specify the format name (cmfmt) when creating the table CREATE TABLE dbtest/cmfmt (customer_name FOR COLUMN cusnam CHAR(20), customer_city FOR COLUMN cuscty CHAR(40)) Use RENAME to specify the short file name (cusmst) for the table: RENAME TABLE dbtest/cmfmt TO cusmst Use RENAME to specify the long name for SQL interfaces RENAME TABLE dbtest/cusmst TO customer_master FOR SYSTEM NAME cusmst
2. 3.
i5/OS V5R4 simplifies control of the record-format name with a new SQL keyword
CREATE TABLE dbtest/customer_master (customer_name FOR COLUMN cusnam CHAR(20), customer_city FOR COLUMN cuscty CHAR(40)) RCDFMT cmfmt
Page 21 of 50
Datalinks
URL-based data type provides linkage to related objects in IFS Can establish Referential Integrity relationship between table row and IFS object
LOBs
Allows you to keep nonrelational data along with all the other business data
Page 22 of 50
Sequence object
Separate object that can be shared across multiple tables Generated value to be part of non-numeric keys CREATE SEQUENCE order_seq START WITH 10 INCREMENT BY 10 INSERT INTO orders(ordnum,custnum) VALUES( NEXT VALUE FOR order_seq, 123 )
Modernizing definitions and objects: Moving business logic into DB2 (automatic key generation)
One of the simplest pieces of business logic that can be embedded into your DB2 object definitions is key generation. Almost all solutions have code that generates a key value for invoice or customer number and then inserts that value into a database table for storage. Why not have DB2 generate that value for you as it inserts the row into the table? That is exactly the functionality that the Identity column attribute and Sequence object (new in i5/OS V5R3) can provide. Let DB2 handle the key generation, locking and serialization of that value, so you can concentrate on real business logic. Support for the sequence object was added because that DB2 object makes it easier to share a generated-key value across multiple tables. Not only can these DB2 capabilities help modernize your database definitions, they also reduce the total lines of application code that have to be written and maintained.
Page 23 of 50
Constraint types
Primary and unique key Referential-integrity constraints
Enforce parent and child as well as masterand detail relationships
Check constraints
Ensure that a column is only assigned legal values
CREATE TABLE orders( ordnum INTEGER PRIMARY KEY, ordqty INTEGER CHECK(ordqty>0 AND ordqty<999), ordamt DECIMAL(7,2), part_id CHAR(4), CONSTRAINT ordpart FOREIGN KEY(part_id) REFERENCES parts(PartID) ON DELETE RESTRICT ON UPDATE RESTRICT )
Modernizing definitions and objects: Moving business logic into DB2 (constraints)
By moving business rules into your database, you are assured that those requirements are enforced across all transactions and, more importantly, all interfaces. In contrast, business rules implemented in an application are enforced only when that application is used to change your database. Relying on application-enforced business rules opens up serious data-integrity issues when data corrections are made using SQL and Web-based application tools. DB2 constraints again provide a means for moving some of your simpler business logic into the DB2 objects themselves. Primary and unique key constraints prevent duplicate entries from being entered into the database for the same customer or order. Creating a primary key constraint on a table also provides equivalent functions with a uniquelykeyed physical file object. RI constraints allow DB2 to keep the master-detail relationship between related tables always in synchronization. For example, an RI constraint prevents an order from being inserted whenever that order does not reference a valid customer number. Check constraints allow the programmer to ensure that only a certain set of values are allowed into a column. The check constraint example here enforces that the order quantity amount is always greater than zero and less than 1000. As of i5/OS V5R3, the new SQE optimizer also has the ability to analyze the constraint definitions to see if they can be employed to make data retrieval more intelligent and faster. For example, if a query is run to search for all orders with a quantity greater than 1000, the optimizer can return an empty result set without looking at any of the data because it knows that the check-constraint definition prohibited any quantity value greater than 1000.
Page 24 of 50
Triggers initiate business policies and processes when new data comes in or existing data is changed
DB2 is responsible for always invoking the trigger program Execution is independent of the user interface Can be used to transform data before it gets into DB2
Modernizing definitions and objects: Moving business logic into DB2 (triggers)
Constraints provide great vehicles for defining simple-file and field-level rules. However, more complex business rules, such as checking inventory levels before accepting an order, might require program code that reads and processes data that spans multiple database tables. More complex processes and policies can be carried out in DB2 for i5/OS with triggers. A trigger is an SQL routine or i5/OS program object that is associated with a database table and set in motion (or triggered) by a change in data. DB2 for i5/OS triggers can be fired with the insertion, update or deletion of a row. When you define a trigger, you define which of these database events causes DB2 for i5/OS to call the trigger logic automatically. A DB2 for i5/OS trigger can easily be used to read data in other files. This helps the application determine whether the order must be accepted or not. The trigger can also initiate a batch job to order additional inventory whenever the trigger logic determines that inventory levels have dropped low enough to require back-order processing. Because triggers are just programs, they can perform nondatabase actions, as well. For example, each time you add a customer to the customer table, a trigger can send the customer information to a data queue. Then, another program can take the data off the queue and fax a welcome letter to the new customer. DB2 for i5/OS allows you to create triggers with or without SQL. For instance, external triggers can also be used.
Page 25 of 50
Page 26 of 50
**DB2 for i5/OS SQL Development Kit required only if using embedded SQL (and STRSQL)
Page 27 of 50
C Sea r ch Key C C ... C Tim es C Sea r ch Key C C Rd C C C C C DATE KE Y C C RowsRd C DATE KE Y C C C C PARTKE Y C C C C CU STKE Y C C C C SU P PKE Y C C C
Resu lt _Set TIME _DIML1 %FOU N D DOU RowsReq = Rows RE AD If TIME _DIML1 %E OF ITE MFACTL1 %FOU ND RowsReq =
RE ADE ITE MFACTL1 If %E OF Lea ve E n dif CH AIN PART_DIML1 If N ot %FOU N D It er E n dif CH AIN CU ST_DIML1 If N ot %FOU N D It er E n dif CH AIN SU PP_DIML1 If N ot %FOU N D It er E n dif ...
Page 28 of 50
Sea r ch Yea r
/F REE exec sql DE CLARE sql_jn CURSOR F OR SE LECT * FROM J oin View WHE RE yea r =1998 AND mont h =6; exec sql OPE N sql_jn ; exec sql FE TCH NE XT F ROM sql_jn F OR :RowsReq ROWS INTO :resu lt _set ; If SQLCOD = 0 a n d SQLER5 = 100 an d SQLER3 > 0; RowsRd = SQLER3; E ndif; /E ND-F RE E
Times
RowsRd = RowsRd + 1
Modernizing data access: Native I/O to SQL example (Joined Logical Files and Views)
A programmer who is accustomed to using the native I/O system might argue that the previous native I/O solution can be simplified by creating a Join logical file. That is true and is shown in this example. However, SQL can do the same thing by hiding the complex Join logic inside an SQL View. In this SQL example, the Join query from the previous page has been moved into an SQL View named sql_jn. SQL Views have an advantage over Join logical files because the join order is not fixed and more complex join types are available. The query optimizer has an opportunity to analyze the join request and modify the join order that is coded in the SQL View if a different join order performs better. With Join logical files, the burden is on the programmer to code the join order correctly and, in time, double-check that the coded join order is still optimal.
Page 29 of 50
1 100 Note: Tests run on Model 720 w/1600 CPW and 2 GB Memory - your performance1000 may vary results Native File Join Native JoinLF Native JoinLF w SQL - No IOA SQL IOA SQL SQE IOA 0.002512 0.002304 0.002400 0.145160 0.251168 0.013536 0.260248 0.362128 2.144288 0.489136 0.267208 0.019320 2.219504 2.544608 2.125032 3.166704 0.417800 0.250160
Page 30 of 50
RPG
Arrival sequence Keyed access Keyed access (memory-constrained) Pseudo-random Keyed access Direct-key access 202 000 131 000 8000 3950 5100
SQL
173 000 117 000 12 000 3440 4100
Page 31 of 50
Consider the impact of the SQL isolation level and journaling on native applications Critical performance success factors
Sound indexing and statistics strategy Reusable Open Data Paths (ODPs)
Prepare once, execute many Connection pooling Keep connections and jobs active as long as possible
Page 32 of 50
One key requirement is to have a sound indexing strategy to put indexes in place for the query optimizer to use for your most critical or frequently-run SQL statements. The white paper entitled Indexing and statistics strategies for DB2 for iSeries Version 3 provides more details. (See the Links section of this course for the URL.) Minimizing the number of Open Data Paths (ODPs) that are created is the next biggest factor for an indexing strategy that ensures a high-performing SQL application. For more details on ODPs, see the online course, DB2 for i5/OS: SQL Performance Basics. (The Links section of this course provides the URL.) Blocking of Fetches and Inserts are usually important to good SQL performance because it allows you to retrieve a block of rows from the table and then process those rows individually in your application program without having to go through all the DB2 engine layers for each row.
Page 33 of 50
OPNQRYF (SQL)
Retain set at a time processing but provide data using SQL
Stored procedures, functions and triggers provide vehicle for improving and changing the solutions architecture
Better modularity as the result of allowing code reuse by multiple interfaces and applications Better partitioning of logic (separation of presentation and database logic) Easy transition to multitier architectures because many interfaces exist for remote invocations
DB2 for i5/OS support provides maximum flexibility by supporting both SQL and external types
External support allows reuse of existing i5/OS application code and skills SQL Procedural Language (PSM) enables better portability of logic (and programming skills) to and from other platforms Data security can be enhanced and maintained with i5/OS Adopted Authority
Modernizing data Access: Using SQL to reuse and repurpose existing code
One way to modernize huge, monolithic programs is to improve the structure with subroutines and modules that perform specific business tasks. Stored procedures, UDFs (user-defined functions) and triggers are DB2 features that can actually help the modularity of your application code. All of these DB2 features make it easy for common business rules and processing tasks to be shared across a wide variety of interfaces and applications. The reason for this is that almost every programming language has an available SQL interface. Procedures, functions and triggers provide a great way of making your existing applications available to a new application model that uses a Web interface. Just because you are providing a Web-browser interface does not mean that all of the business logic has to be rewritten in Java. Instead, write the presentation layer in Java and then issue a simple JDBC statement to invoke the existing code from a stored procedure. DB2 for i5/OS provides maximum flexibility in this area by allowing these DB2 objects to be created either entirely in SQL or with any i5/OS high-level programming language. New programmers might use SQL, but a team of RPG or COBOL programmers do not have to throw out their existing trigger and stored procedure skills. Many System i programmers also prefer procedures, functions and triggers because these functions map to program objects. This means that i5/OS adopted authority can be used to limit the security exposure when making business functions available to new interfaces and applications.
Page 34 of 50
UDFs allow the database to invoke user-written functions during the processing of an SQL statement
Allows you to customize SQL to meet your business requirements Example: CREATE FUNCTION Euro(EuroAmt DECIMAL(11,2)) RETURNS DECIMAL(11,2) LANGUAGE SQL BEGIN DECLARE rate DECIMAL(9,5); SELECT conversion_rate INTO rate FROM ratetable WHERE ...; RETURN rate*EuroAmt; END SELECT item_name, Euro(item_price) FROM parts...
Modernizing data access: Using SQL to reuse and repurpose existing code (UDFs)
DB2 for i5/OS includes a set of built-in scalar functions (such as ABSVAL and SUBSTRING) to provide a basic suite of functions for mathematical and character processing. However, these functions do not always have the capabilities necessary for programmers to implement complex business calculations or processes such as the calculation of shipping costs, room yield or credit risk. The DB2 support for user-defined functions (UDFs) makes it easy to create and develop your own functions and have the ability to use these user-created functions just as you would the SQL built-in functions. This example shows a simple SQL function to convert a currency amount into its equivalent Euro currency value. As mentioned earlier, the System i platform supports both external and SQL UDFs. This support offers great flexibility. A Java programmer can code a JDBC request that invokes a UDF that internally uses a 10-year-old RPG program for the business calculation. To the Java programmer, the UDF call is the same as invoking a built-in SQL function, such as ABSVAL or SUBSTRING.
Page 35 of 50
Stored procedures are similar to UDFs, but are invoked with an SQL Call statement
More than just a remote program call
Supported by the majority of the application development tools and languages Result sets can improve performance by minimizing network trips
Procedures are most effective when performing multiple operations on a single procedure call Considerations for external procedures
Might have to make slight modifications to existing code to match stored-procedure parameter conventions or develop wrapper procedures Need to design process for installing and upgrading stored procedures
Modernizing data access: Using SQL to reuse and repurpose existing code (procedures)
As with UDFs, stored procedures are created with SQL or an external high-level language; but, the invocation of the two procedural objects differs. UDFs are effective when you want to call the function for each row or a subset of rows in a particular table. Stored procedures are called independently of any DB2 table or row. They are the SQL version of a remote program call. Stored procedures are called only when a particular business task needs to be performed. Stored procedures are a good way to modularize, or partition, a related set of database operations, possibly even an entire transaction. For example, the database changes that are necessary when transferring inventory from one warehouse location to another can be implemented as a stored procedure. Well-defined modular stored procedures can be shared across business transactions to improve code reusability. Stored procedures also provide performance savings in a multitier environment by letting you perform multiple database operations on a single server request from the client. DB2 external procedures make it easy to reuse existing programs as stored procedures. You might only need to adjust how DB2 passes input and output parameters based on the parameter style that is specified on the CREATE PROCEDURE statement. DB2 implements SQL stored procedures by generating a C program with embedded SQL. Because generated code is never as efficient as user-written code, you might consider using external stored procedures in situations where performance is extremely critical. That being said, many System i users are successfully using the SQL procedural language. This language is especially successful in porting triggers and procedures from Oracle and Microsoft SQL Server to DB2 for i5/OS. Stored-procedure calls done with an SQL CALL statement are always implemented as unbound calls. Thus, to get the best performance, the number of stored-procedure calls needs to be minimized by forcing the procedure to perform multiple tasks on a single call.
Page 36 of 50
Modernizing data access: DB2 and new application models (distributed transactions)
Many new application models incorporate the design point of having multiple connections (or jobs) working on a single transaction to improve the scalability and flexibility of the application. The XA transaction interface is the most commonly-used industry-standard interface in these types of solutions. The i5/OS operating system provides support for the XA standard and the Java equivalent, the Java Transaction API (JTA). Although the i5/OS support is designed for the SQL interfaces, existing native programs can participate in a distributed transaction if they are registered and called as external stored procedure or external functions.
Page 37 of 50
Create Document Access Definition eXtension (DADX) documents by using a simple text editor and deploy them in Websphere with minimal knowledge of XML or SQL Used through Websphere and SOAP
SQL Select, Update, Insert, Delete and other procedures XML extenders can also be used
Modernizing data access: DB2 and new application models (Web services)
Web services are becoming an established technology that provides a model for offering business or application services over the Internet as well as within an organization. The value of specific DB2 Web services is that they let a developer provide direct access to business data without any high-level language programming. DB2 Web services are a good choice when the Web service is data centric meaning that the invoking application looks for a set of data or needs to insert a new row of data. DB2 Web services can support these types of data-centric requirements by essentially coding an SQL statement in an XML document (assuming that the application runs on top of the WebSphere Application Server). The white paper DB2 UDB for iSeries and Web Services has the details on how the WebSphere Web services Object Runtime Framework (WORF) component handles the interfacing tasks with the Web service invoker and also performs the XML formatting of the results that are sent back to the invoker. This streamlined approach lets the developer concentrate on the SQL request (rather than worrying about coding the Javaapplication to establish a database connection and to package and deploy the Java code). DB2 Web services let the developer retrieve and change data on the System i platform, as well as invoke stored procedures.
Page 38 of 50
The example shown here is a simple DB2 Web service that accepts a zip code as an input parameter and returns a list of the city names with that specified zip code. You can learn more about using DB2 Web services by visiting the Web site listed on this chart (and provided in the Links section of this course).
Page 39 of 50
Reference: ibm.com/servers/enable/site/education/ibo/record.html?db2udbext
Modernizing data access: DB2 and new application models (XML and text mining)
These days, the ability to support XML is a requirement that almost all solutions are addressing. XML is the standard format when sharing data with partners or providing data to other companies. Many times, the data in that XML document needs to come from a DB2 database or must be stored in a DB2 database. That is where XML extenders come into play. They allow you to store XML data along with your business data in DB2 for i5/OS. By incorporating XML information and metainformation directly in the database, you can more efficiently obtain the XML results that other applications need. With the content of your structured XML documents in a DB2 database, you can combine structured XML information with traditional relational data. With the help of XML extenders, the XML documents can be stored entirely in a database column, or you can set up mapping so that XML documents can be decomposed into existing columns or generated from data in existing columns. If you choose to store the entire XML document in a DB2 column, then developers and users will want to search the contents of that large text column containing the XML document. That is where Text extenders come into play. They enable searches against character columns to be done very quickly. In addition, the text extenders provide advanced search capabilities against any character column, such as the ability to find matches (on the tenses of the search word) and searches (requiring the keywords to be in the same sentence or paragraph). Check out the online course DB2 UDB Extenders for iSeries - V5R2 Update for more details on the DB2 XML and text extenders. (See the Links section of this course for the URL.)
Page 40 of 50
RSE and Code/400 coexist with SQL PDM has basic SQL prompting support Visual Studio .NET plugins DB2 Information Integrator for non-DB2 data access
Reference: ibm.com/servers/enable/site/education/ibo/record.html?hetdata
Page 41 of 50
IBM Toolbox for Java graphical debugger for ILE and SQL source-level debugging (ibm.com/servers/enable/site/education/abstracts/sqldebug_abs.html) iSeries Navigator
Editors for procedure, functions, triggers SQL statement wizard for Insert, Select, Update, Delete Downloadable tutorials at: ibm.com/servers/enable/site/education/ibo/view.html?oc#db2
Visual Explain Database Monitor (STRDBMON CL command) PRTSQLINF DB2 SMP: licensed feature (i5/OS Option 26)
Page 42 of 50
Next steps
Education
Modernizing iSeries Application Data Access Redbook
www.redbooks.ibm.com/abstracts/sg246393.html?Open
Get help
eServer Custom Technology Center: www.ibm.com/ctc System i IBM Global Services team: [email protected]
Next steps
SQL is no different than any other programming language; you need education and experience to learn how to design a high-performing application. IBM highly recommends that you take advantage of the education available at the various Web sites listed on this chart. This education is important because the SQL performance tuning methods and tools are drastically different than performance considerations for native I/O processing. Depending only on trial-and-error experiences to build your experience level with SQL performance tuning takes too long. Education is needed first and then hands-on experience with SQL performance tuning is needed to solidify these new skills. The referenced iSeries SQL Performance Workshop provides both lecture and lab to give you opportunities in both areas. Portions of the SQL Performance Workshop lab materials are available online. (You can also see the Links section of this course for the URL.) As with any new venture, it is recommended that you start small and then build on that small success. It is not recommended that your first project be the rewrite of an entire native program to SQL. Instead, look for a new project that requires the creation of a new program or module that can use SQL in just the new code you are writing. Similarly, you might look at an existing component or routine in your application that can be rewritten using SQL. The reporting function for an existing application might be a good candidate.
Page 43 of 50
Some System i programmers have been forced into using SQL when they port an application that was written by PC programmers for another database (such as Microsoft SQL Server). Many times, the driving reason for porting the solution to the System i platform is to resolve scalability issues that are inherent with on the other platform and database. A conversion of an application from another database product requires the use of SQL to complete the conversion in a timely manner. IBM eServer Custom Technology Center and the IBM eServer iSeries Global Services Team are available to help with SQL modernization and performance tuning. Some solution providers might also qualify for assistance from the DB2 team in the IBM ISV Business Strategy and Enablement organization.
Page 44 of 50
Sample tests: certify.torolab.ibm.com/ice Exams are refreshed and updated for DB2 for i5/OS
Page 45 of 50
Summary
SQL is everywhere DB2 for i5/OS supports both native and SQL-based interfaces. DDS objects can be converted to SQL through the use of the i5/OS QSQGNDDL API. SQL on the System i platform supports relational and nonrelational data objects. SQL supports moving business logic into the the DB2 engine.
Better modularization and isolation of data and business logic
SQL and DB2 for i5/OS support Java, XML and Web services. There are many development tools for SQL and DB2 for i5/OS.
Summary
SQL offers many advantages for System i developers as they move toward modernizing their existing RPG and C-based applications. One significant reason is that SQL is ubiquitous it is widely available, as are the programming skills needed to use this standards-based database interface. SQL can reduce the total lines of code, and it supports parallel database processing, which can yield better throughput for I/Ointensive applications. DB2 for i5/OS supports a number of native and SQL-based interface types into the data, each of which can be mixed and matched with other interfaces. The approach that you take depends on where you start and what you need to accomplish it is not an inflexible process. The SQL interface options include: static SQL, dynamic SQL and extended-dynamic SQL The QSQGNDDL i5/OS API is a tool that helps you convert existing DDS objects into SQL. You can conveniently access this tool from iSeries Navigator so that you can do these conversions through a graphical interface, which makes your job even easier. The decision to move to SQL as a database interface is easier because, since OS/400 V5R2, SQL on the System i platform now supports nonrelational objects (as well as its long-supported relational objects). This support was added through user-defined table functions (UDTFs). SQL also makes it easier to move business logic into the DB2 engine. A prime example of this is its ability to support automatic key generation. Developers no longer have to include this logic in code that should be more focused on core business tasks. Even some data tasks that are related to business logic can be handled by SQL and DB2 (for example, referential-integrity constraints and triggers). In addition to providing more efficient and better-performing database-access code, SQL also supports your need to reuse and repurpose existing code as you move to restructure your huge, monolithic programs. Stored procedures, UDFs (user-defined functions) and triggers are DB2 features that can actually help the modularity of your application code. SQL and DB2 for i5/OS also support new Java-based application development for todays Web-driven environments. This support is provided through the XA standard and
Page 46 of 50
its Java equivalent, the Java Transaction API (JTA). Web services, XML, and text mining are also easily achievable with SQL. Finally, there is a wealth of development tools to assist you in working with SQL and your existing code (see the Links section of this course).
Page 47 of 50
Links
White papers and articles: Indexing and statistics strategies for DB2 UDB for iSeries - Version 3.0 ibm.com/servers/enable/site/education/abstracts/indxng_abs.html DB2 UDB for iSeries and Web Services ibm.com/servers/enable/site/education/abstracts/db2web_abs.html DB2 Information Integrator for non-DB2 data access ibm.com/servers/enable/site/education/ibo/record.html?hetdata
Online courses: DB2 UDB for iSeries: SQL Performance Basics ibm.com/servers/enable/site/education/abstracts/db2sql_abs.html DB2 UDB Extenders for iSeries - V5R2 Update ibm.com/servers/enable/site/education/ibo/record.html?db2udbext IBM Toolbox for Java graphical debugger for ILE and SQL source-level debugger ibm.com/servers/enable/site/education/abstracts/sqldebug_abs.html iSeries Navigator DB2 interfaces (several online courses) ibm.com/servers/enable/site/education/ibo/view.html?oc#db2 Other courses ibm.com/eserver/iseries/db2/db2educ_m.htm
IBM Redbooks: ibm.com/redbooks Stored Procedures and Triggers on DB2 UDB for iSeries (SG24-6503) DB2 UDB for AS/400 Object Relational Support (SG24-5409) Advanced Functions and Administration on DB2 UDB for iSeries (SG24-4249) Workshops: DB2 for i5/OS SQL Performance ibm.com/servers/eserver/iseries/service/igs/db2performance.html Other DB2 workshops ibm.com/servers/enable/site/education/ibo/view.html?oc#db2
Page 48 of 50
DB2 for i5/OS Family certifications: Certified Database Associate - DB2 for i5/OS Family (Test 700) ibm.com/certify/certs/dbdaudv81.shtml Study resources ibm.com/certify/tests/edu700.shtml Tutorials www7b.boulder.ibm.com/dmdd/library/tutorials/db2cert/db2cert_V8_tut.html Certified Application Developer - DB2 for i5/OS Family (Test 703) ibm.com/certify/certs/dbapudv81.shtml Study resources ibm.com/certify/tests/edu703.shtml Sample tests certify.torolab.ibm.com/ice Other helpful Web sites: IBM eServer Custom Technology Center ibm.com/ctc DB2 for i5/OS home page ibm.com/eserver/iseries/db2 DB2 online manuals ibm.com/eserver/iseries/db2/books.htm DB2 porting help ibm.com/servers/enable/site/db2/porting.html Book: SQL/400 Developer's Guide by Paul Conte and Mike Cravitz http://as400network.com/str/books/Uniquebook2.cfm?NextBook=183
Newsgroups: USENET newsgroup comp.sys.ibm.as400.misc, comp.databases.ibm-db2 iSeries Network (NEWS/400 Magazine) SQL and DB2 Forum www.iseriesnetwork.com/Forums/main.cfm?CFApp=59
Page 49 of 50
Page 50 of 50