270 likes | 418 Views
EGL/Web Project QuickStart – 1 of 4 – Creating the Data Access Layer.
E N D
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.
RBD/EGL Programming Course 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
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)
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
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)
EGL/Web QuickStart UNIT Topics: • Development Model – Terms and Concepts • Importing Database Schema • Creating Custom Business Logic • Creating the U.I. Model • Creating Dynamic Content Web Pages
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. 1. Data Access Model 2. Custom Business Logic 3. U.I. Model 4. Page Development
EGL/Web QuickStart UNIT Topics: • Development Model – Terms and Concepts • Importing Database Schema • Creating Custom Business Logic • Creating the U.I. Model • Creating Dynamic Content Web Pages
Table schema in your Database Catalog 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 Data Access Wizard Data Access Functions
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.
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 >
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…
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) 5. Click Next > 2. 1. D:\<RBDInstallDir>\runtimes\base_v61\derby\lib\derby.jar 3. 4. 5. **3.See Notes on the location of the RBD software. Or do a My Computer, find on: derby.jar
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
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. 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 >
Qualify 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 schema 2. Click: Next >
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
What Just Happened? The Data Access Wizard created the following four sets of resources: • Control Records – used in the default Data Access Library SQL statements • Data Access Libraries – which contain EGL data access statements (basic data access design patterns), that generate to SQL statements and routines • 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 • EGL DataItems – in DataDefinitions.egl. This file contains default type definitions for each column in each imported table. See notes for more on DataItems Control Records Data Access Libraries Data Access Records EGL DataItems
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 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. OpenDataDefinitions.egl in the Content Area 2. Do a global replace (Ctrl/F) of the datatype DecimalMoney 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.
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)
Customize the Default-Generated Code – 3 of 3 Change theorder byclause to sort the results of this SQL statement by theorder_statusfield. • 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)
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
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 host-variables, 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.
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
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