Data Access Records
Download
Report
Transcript Data Access Records
®
IBM Software Group
EGL/Web Project QuickStart – 1 of 4 – Creating the Data Access Layer
These slides walk you through the process of creating a simple C.R.U.D. (Create,
Read, Update and Delete) dynamic data content web application. This Section shows
you how to use the EGL Data Access Application Wizard to generate a default data
access layer for your project.
© 2006 IBM Corporation
Course
RBD/EGL Programming
Units:
RBD and Course Setup
RBD Workbench
EGL/Web QuickStart
Programming in EGL
Database and File Access
EGL and Services (SOA)
Calling External Languages From EGL
EGL and Batch Applications
Appendices
2
Unit Objectives
At the end of this unit, you will be able to:
Describe the general principles and generic
steps in the EGL application development
approach
Import database schema into EGL records,
functions and DataItems
Create a small web site-map and define
global templates for your pages
Create simple dynamic data-content webpages, such as:
Read/Only list pages with scrolling,
categorization and hyper-links to
Detail pages that allow database update and
delete
Write functions calls to imported data access
functions from JSFHandlers
Code simple EGL business logic (conditional
statements)
3
Unit Objectives – Back-end Data and Process Logic
Using the automated tooling of RBD, you will generate the following
database access business logic:
Control Records
Data Access
Libraries
Data Access
Records
EGL DataItems
4
Unit Objectives – Pages and SiteMap
And you will use generated backend data structures and
functions along with other RBD
tooling, to create these four
dynamic content web pages:
Menu:
Customer List
Customer Update
Orders List
Order Update (optional)
5
UNIT
EGL/Web QuickStart
Topics:
Development Model – Terms and Concepts
Importing Database Schema
Creating Custom Business Logic
Creating the U.I. Model
Creating Dynamic Content Web Pages
6
The EGL Project Model – 10,000 Foot View
EGL and RBD are about increasing development productivity. You gain
productivity in software through raising the level of abstraction at which you
work. That and – whenever possible - using tools to do things - as
opposed to manually writing, testing and maintaining code.
For a simple EGL Web application you can use the following development
model:
1. Data Access Model
2. Custom Business Logic
3. U.I. Model
4. Page Development
Every production project will be different. Each will offer unique challenges AND
require different amounts of time spent on each of the above lifecycle phases. For
a simple EGL web application let’s see how things go.
7
UNIT
EGL/Web QuickStart
Topics:
Development Model – Terms and Concepts
Importing Database Schema
Creating Custom Business Logic
Creating the U.I. Model
Creating Dynamic Content Web Pages
8
Data Access Wizard
To simplify data access EGL provides custom record types, with “properties”
that enable generation of native database and file I/O call APIs. You can
write these custom records – or – allow RBD’s tooling to build or derive
them from the relational tables and views you want to access.
To get you jump-started on your EGL/SQL statements, the RBD tooling
creates design pattern functions, for reading and writing to your database.
You can create your own custom EGL data access records, design
patterns, functions and SQL statements. But for this simple web
application, let’s see how far the wizard-generated code gets us.
sqlRecords
Table schema
in your
Database Catalog
Data Access
Wizard
Data Access
Functions
9
Data Access Application Wizard – Steps for the Upcoming Workshop
These steps are what you WILL be doing, to import your database:
Stop the Application Server (for Derby and CloudScape databases)
Launch the EGL Data Access Application Wizard
Define a connection to your database
Specify any table filtering
Select the tables you want to import
Verify/Specify search keys
Specify statement qualification
Generate
View Results
Customize Results
Note: Because Derby is a single-threaded database, before you start the
wizard you will probably need to stop the Application Server. Do this
now, before continuing. While you do this, run the Viewlet on the next
slide.
10
Launch the EGL Data Access Application Wizard
Like creating all new resources, you start from
Project Explorer:
Right-click over \EGLSource\ and select:
New
Other
Scroll down to, and expand the EGL
folder and select:
EGL Data Access Application
Click Next >
11
Define a Connection to Your Database – 1 of 2
The next step in the import process is to specify which project to import the EGL definitions into.
In this lab, you will import them into your EGLWeb project
Open the combo-box
and select the Project Name:
EGLWeb
Click New…
12
Define a Connection to Your Database – 2 of 2
In order to retrieve your tables’
schema, you will connect to your
relational database. This will
vary by which database you use.
To connect to Derby:
1. Select: Derby 10.0
2. The Database location (folder) of
the Derby database – this
should be:
C:\databases\EGLDerbyR7
3** The Class location of the JDBC
Driver Class derby.jar file. This
file can be found under your
product installation directory, as
shown here.
4. Click Test Connection (for
Derby, you do not need a
Password)
2.
1.
D:\<RBDInstallDir>\runtimes\base_v61\derby\lib\derby.jar
3.
4.
5. Click Next >
5.
**3. See Notes on the location of the RBD software. Or do a My Computer, find on: derby.jar
13
Specify Table Filtering
In our small test database
you might be able to get
away without filtering, but in
your production applications
you will most likely want to
filter out certain tables –
examples:
System tables
Other tables in a
database you do not
want to import at this
time.
Steps:
1. Click: Selection
2. Check: EGL
3. Click: Finish
14
Select Tables for Import
** You can select individual – or all tables shown through this connection’s filter
for Import
1. Click: Select All
2. Click Next >
** You may get warning boxes to login or previously created model.
15
Click OK to both
Verify Table Search Keys
If a selected table does not have a
Primary Key specified for it in the
database catalog, you will be
prompted to select a key field for it.
This key field is used in the EGL SQL
statement generation.
It might be the case that SiteUser
needs you to choose a key field.
Choose: SiteUser_ID
Click: Next >
16
Qualify Table Names
For this workshop you will qualify the
table name with the table’s schemaname (the schema-name is usually
the authorization-id of the table
“owner” – like a DBA, for example).
1. Check:
Qualify table names with schema
2. Click: Next >
17
Generate
Finally, a summary screen is
shown, which shows your Data
Access import options.
You can expand and look at them,
go back, or just:
Click: Finish
18
What Just Happened?
The Data Access Wizard created the following
four sets of resources:
1. Control Records – used in the default Data Access
Library SQL statements
2. Data Access Libraries – which contain EGL data
access statements (basic data access design
patterns), that generate to SQL statements and
routines
3. Data Access Records – EGL records of type
sqlRecord, which participate in the Java and SQL
generation, allowing you to code at a high-level of
abstraction
Control Records
Data Access
Libraries
Data Access
Records
EGL DataItems
4. EGL DataItems – in DataDefinitions.egl. This file
contains default type definitions for each column in
each imported table. See notes for more on
DataItems
19
View Results – See What Was Produced by the Wizard
Expand the four new folders under EGLSource named:
eglderbyr7.<something>
Open a few of the files produced by the wizard in the
Content Area (Double-click: CustomerLib.egl,
Customer.egl, DataDefinitions.egl, etc.)
and view the code that was generated.
Since we will be covering EGL in an upcoming unit of
this course it is not expected that you understand all –
of what was produced from Data Access import.
However the default data access code is:
A nice starting point for doing and learning about
database programming in EGL
Nice to have been generated (as opposed to hand-coding
yourself)
Let’s do a few specific things to some of these files
(steps begin on the next slide)…
20
Control Records
Data Access
Libraries
Data Access
Records
EGL DataItems
Customize the Default-Generated Code – 1 of 3
As discussed, the default SQL data access code
generated is a good start, on the road to EGL/SQL
database programming, but it’s only a start. You will
definitely be adding to, and modifying the default code
produced by the data access wizard.
This next workshop will give sense of this
customization – you will change:
DataItems
An SQL Function
(From Project Explorer)
From \EGLSource\eglderbyr7.primitivetypes.data\
1. Open DataDefinitions.egl in the Content Area
2. Do a global replace (Ctrl/F) of the datatype
Decimal Money
3. Save your changes
With your mouse clicked in the file, press Ctrl/S)
Note – if you get any red X’s in the source file
you’ve made a typo. Correct all typos.
21
Customize the Default-Generated Code – 2 of 3
In \EGLSource\eglderbyr7.access\
Open OrdersLib.egl and find the
function: GetOrdersListAll
Click your mouse between the
word get and ordersArray;
Right-click and select:
SQL Statement
Add
This causes RBD to insert the
SQL statement it would generate,
inline in your function, allowing
you to customize the data access
code (see next slide)
22
Customize the Default-Generated Code – 3 of 3
Change the
order by
clause to sort the results
of this SQL statement by
the order_status
field.
Note – type carefully.
Press Ctrl/S to save
In doing EGL/Java
development, most SQL
statement typos are not
caught at compile time, but at
run-time, making them a
royal pain to debug.
See Notes
But the tooling can catch
these (as we’ll see in an
upcoming section) – want a
hint? (see Optional Exercise
on the next slide)
23
Test the Customized SQL Statement – 1 of 2 (Set Preferences)
Optional Exercise: From Window, Preferences, open EGL, SQL Database Connections, and select (from
the ComboBox) your EGLDerbyR7 connection
24
Test the Customized SQL Statement – 2 of 2
Optional Exercise: Click your mouse
inside the select statement.
Right-click and select:
SQL Statement
Validate
Click OK at the SQL User ID/Password
prompt.
If there are SQL problems, you will
find out now upon Validating your
statement.
If there are EGL “host variables” in
your statement, and there are
problems with your EGL hostvariables, you will find out when you
save (Ctrl/S)
If you are not familiar with the term,
EGL “host variables” are covered
later in this course.
25
Generate the Code Changes
(From Project Explorer)
Right-click over EGLWeb
Select Generate
This will generate new Java code for your changes
to the default code created by the Database
Access Application Wizard
26
Topic Summary
Now that you have completed this topic, you should have:
Used the EGL Data Access wizard to import – from your Derby
database:
Data Access Libraries
Data Access Records
DataItems (an operational data dictionary)
SQL call control records
Customized:
The DataItems
A Data Access Library Function
Successfully re-generated all of the Data Access import wizard code.
Summary
27