EGL/Web Project QuickStart – 1 of 4 – Creating the Data Access Layer
description
Transcript of EGL/Web Project QuickStart – 1 of 4 – Creating the Data Access Layer
®
IBM Software Group
© 2006 IBM Corporation
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.
2
Course
RBD and Course Setup
RBD Workbench
EGL/Web QuickStartEGL/Web QuickStart Programming in EGL
Database and File Access
EGL and Services (SOA)
Calling External Languages From EGL
EGL and Batch Applications
Appendices
Units:
RBD/EGL ProgrammingRBD/EGL Programming
3
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 web-pages, 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)
4
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 AccessLibraries
Data AccessRecords
EGL DataItems
5
Unit Objectives – Pages and SiteMap
And you will use generated back-end 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)
6
UNIT
Development Model – Terms and ConceptsDevelopment Model – Terms and Concepts
Importing Database Schema
Creating Custom Business Logic
Creating the U.I. Model
Creating Dynamic Content Web Pages
Topics:
EGL/Web QuickStartEGL/Web QuickStart
7
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:
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.
2. Custom Business Logic
1. Data Access Model1. Data Access Model
3. U.I. Model
4. Page Development
8
UNIT
Development Model – Terms and Concepts
Importing Database SchemaImporting Database Schema
Creating Custom Business Logic
Creating the U.I. Model
Creating Dynamic Content Web Pages
Topics:
EGL/Web QuickStartEGL/Web QuickStart
9
Data Access WizardData 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.
Table schema Table schema in yourin your
Database CatalogDatabase Catalog
Data AccessData AccessWizardWizard
sqlRecordssqlRecords
Data AccessData AccessFunctionsFunctions
10
Data Access Application Wizard – Steps for the Upcoming WorkshopData 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
NoteNote: Because Derby is a single-threaded database, before you start the wizard you will probably need to stop the Application Server.stop the Application Server. Do this now, before continuing. While you do this, run the Viewlet on the next slide.
11
Launch the EGL Data Access Application WizardLaunch the EGL Data Access Application WizardLike creating all new resources, you start from
Project Explorer:
Right-click over \EGLSourceEGLSource\ and select:
New New OtherOther
Scroll down to, and expand the EGLEGL folder and select:
EGL Data Access ApplicationEGL Data Access Application
Click Next >Next >
12
Define a Connection to Your Database – 1 of 2Define a Connection to Your Database – 1 of 2The 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-boxOpen the combo-box and select the Project Name:
EGLWebEGLWeb
Click New…Click New…
13
Define a Connection to Your Database – 2 of 2Define a Connection to Your Database – 2 of 2In 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.0Derby 10.0
2. The Database location (folder) of the Derby database – this should be:
C:\databases\EGLDerbyR7C:\databases\EGLDerbyR7
3** The Class location of the JDBC Driver Class derby.jarderby.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)
5. Click Next >
D:\<RBDInstallDir>\runtimes\base_v61\derby\lib\derby.jarD:\<RBDInstallDir>\runtimes\base_v61\derby\lib\derby.jar
**3. See Notes on the location of the RBD software. Or do a My Computer, find on: derby.jar
2.
1.
4.3.
5.
14
Specify Table FilteringSpecify 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: SelectionSelection
2.2. Check: EGLEGL
3.3. Click: FinishFinish
15
Select Tables for ImportSelect Tables for Import** You can select individual – or all tables shown through this connection’s filter
for Import
1. Click: Select AllSelect All
2. Click Next >
** You may get warning boxes to login or previously created model. Click OK to both
16
Verify Table Search KeysVerify 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_IDChoose: SiteUser_ID
Click: Next >Next >
17
Qualify Table NamesQualify Table Names For this workshop you will qualify the
table name with the table’s schema-name (the schema-name is usually the authorization-id of the table “owner” – like a DBA, for example).
1. Check: Qualify table names with schemaQualify table names with schema
2. Click: Next >Next >
18
GenerateGenerate 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: FinishFinish
19
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
4. EGL DataItems – in DataDefinitions.eglDataDefinitions.egl. This file contains default type definitions for each column in each imported table. See notes for more on DataItems
Control Records
Data AccessLibraries
Data AccessRecords
EGL DataItems
20
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)…
Control Records
Data AccessLibraries
Data AccessRecords
EGL DataItems
21
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\\EGLSource\eglderbyr7.primitivetypes.data\1.1. OpenOpen DataDefinitions.egl DataDefinitions.egl in the Content Area2. Do a global replace (Ctrl/FCtrl/F) of the datatype
DecimalDecimal MoneyMoney
3. Save your changes With your mouse clicked in the file, press Ctrl/SCtrl/S)
Note – if you get any red X’s in the source file you’ve made a typo. Correct all typos.
22
Customize the Default-Generated Code – 2 of 3In \EGLSource\eglderbyr7.access\ Open OrdersLib.egl and find the
function: GetOrdersListAllGetOrdersListAll
Click your mouse between the word getget and ordersArray;ordersArray;
Right-click Right-click and select:
SQL Statement SQL Statement Add 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)
23
Customize the Default-Generated Code – 3 of 3 Change the order byorder by
clause to sort the results of this SQL statement by the order_statusorder_status field. Note – type carefully.
Press Ctrl/SCtrl/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 NotesSee 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)
24
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
25
Test the Customized SQL Statement – 2 of 2 Optional Exercise: Click your
mouse inside the selectselect statement. Right-click and select:
SQL Statement Validate
Click OKOK 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 host-variables, you will find out when you save (Ctrl/SCtrl/S)
If you are not familiar with the term, EGL “host variables” are covered later in this course.
26
Generate the Code Changes
(From Project Explorer) Right-click over EGLWebEGLWeb Select GenerateGenerate
This will generate new Java code for your changes to the default code created by the Database Access Application Wizard
27
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.
Topic Summary
Summary