Chapter 10. Structured Query Language for Java (SQLJ) 421
Figure 10-21 Java code generated by the SQLJ translator
To summarize, in this example, the following actions occurred:
򐂰 Defined an iterator
򐂰 Established a JDBC connection
򐂰 Set the DefaultContext class
򐂰 Loaded a group of records into the instance of the iterator using SQLJ
򐂰 Using the generated getter methods, the data members were fetched from the iterator and
written to the display
10.5 Order Entry client application
This section uses the client side of the Order Entry application that was discussed Chapter 8,
Migrating the user interface to the Java client on page 321, and converts the use of JDBC
stored procedures to use SQLJ. In addition, we convert access to the ITEM file from DDM
record-level access to SQLJ. This involves changing three programs:
򐂰 OrderEntryWdw
򐂰 SltCustWdw
򐂰 SltItemWdw
/*@lineinfo:generated-code*//*@lineinfo:41^2*/
// ************************************************************
// #sql cCursor = { Select CID as"id",
// CFIRST as "firstname",
// CLAST as "lastname",
// CCITY as "city",
// CSTATE as "state"
// from CSTMR };
// ************************************************************
{
sqlj.runtime.ConnectionContext __sJT_connCtx =
sqlj.runtime.ref.DefaultContext.getDefaultContext();
if (__sJT_connCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_CONN_CTX();
sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();
if (__sJT_execCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();
synchronized (__sJT_execCtx) {
sqlj.runtime.profile.RTStatement __sJT_stmt =
__sJT_execCtx.registerStatement(__sJT_connCtx, CstmrList_SJProfileKeys.getKey(0), 0);
try
{
sqlj.runtime.profile.RTResultSet __sJT_result = __sJT_execCtx.executeQuery();
cCursor = new CustCursor(__sJT_result);
}
finally
{
__sJT_execCtx.releaseStatement();
}
}
}
// ************************************************************
/*@lineinfo:user-code*//*@lineinfo:46^40*/
422 Building Java Applications for the iSeries Server with VisualAge for Java 3.5
Figure 10-22 shows the new application design.
Figure 10-22 Order Entry client using SQLJ
Figure 10-23 shows the main Order Entry window and the interfaces used.
Figure 10-23 Order Entry client interfaces
Data
Entry
Order
Process
Order
Print
Order
D
a
t
a
Q
u
e
u
e
ORDENTR
RPG
PRTORDERP
RPG
Java
Client
S
Q
LJ
Distributed
Program Call
Client
Server
Item
S
Q
L
J
Cstmr
SQLJ
(PopulateCustbox)
SQLJ
(populateItembox)
SQLJ
(addOrderItem)
Distributed
Program Call
(retrieveOrderInfo)

Get Building Java Applications for the iSeries Server with VisualAge for Java 3.5 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.