Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EDT:Tutorial: RUI With DataBase Lesson 2"

(New page: Access a database with EGL Rich UI {| style="float: right" |< Previous | [[EDT:Tutori...)
 
 
(50 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[EDT:Tutorial: Access a database with EGL Rich UI|Access a database with EGL Rich UI]]
+
[[EDT:Tutorial: Access a database with EGL Rich UI|Access a database with EGL Rich UI]]  
  
 
+
{| style="float: right;"
{| style="float: right"
+
|-
|[[EDT:Tutorial: RUI With DataBase Lesson 1|&lt; Previous]] | [[EDT:Tutorial: RUI With DataBase Lesson 3|Next >]]
+
| [[EDT:Tutorial: RUI With DataBase Lesson 1|&lt; Previous]] &#124; [[EDT:Tutorial: RUI With DataBase Lesson 3|Next &gt;]]
 
|}
 
|}
= Lesson 2: Connect to a new Derby database =
 
  
Use the Derby open source database manager to handle the
+
= Lesson 2: Set up the projects  =
data store for the application.
+
  
This tutorial uses the open source Derby database. In
+
An EGL application is organized in one or more ''projects'', each of which is a physical folder in the workspace. A project contains an EGL source folder that is provided for you, and that folder contains one or more ''packages'', which in turn contain EGL source files. This hierarchy is basic to your work in EGL: a project, then an EGL source folder, then a package with EGL source files.  
this chapter, you connect to a Derby database and create the table
+
to be accessed. Alternatively, you can connect to a database of one
+
of the following kinds: Cloudscape, DB2&reg; UDB, Informix&reg;, Oracle, or SQL Server.
+
If you prefer to use one of those databases, review the following
+
help topic: <span class="ph">[../../com.ibm.egl.pg.doc/topics/pegl_sql_db_connect_tsk.html Creating an SQL database connection]</span>.
+
In any case, create the table described in this lesson.
+
  
Follow
+
The EGL source files include EGL <span style="font-style: italic;">custom type</span>''s'', which are type definitions that you create. For example, a Service type contains logic, and a Record type can be the basis of a variable that you declare in your Service type.
these steps to set up the Derby database:
+
  
<ol><li>Create an SQL database connection through the EGL Preferences.
+
Packages are important because they separate types into different contexts, or ''namespaces'':
<li>Use the Data perspective to create and connect to the database.
+
<li>Write an SQL script to create a table within the database.
+
<li>Disconnect from the database, as is necessary because Derby allows
+
only one connection, which you will need during code development.
+
</ol>
+
  
 +
*A type name might be duplicated in two different packages, and any EGL source code can reference each type precisely. The main benefit of namespaces is that different teams can develop different EGL types without causing name collisions.
 +
*Each type name in a given package is unique within that package:
 +
**A type in one package can easily reference another type in the same package by specifying the type name. For example, here is a declaration of a record that is based on the Record type named '''MyRecordType''': myRecord MyRecordType{};
 +
**A type in one package can also reference a type in a second package by giving the package name and type name, or by a shortcut that involves importing the type.
  
== Create an SQL database connection ==
+
One project can reference the types in a second project, but only if the EGL build path of the referencing project identifies the referenced project. Again, this tutorial gives examples. However, in all cases, avoid using the same package name in different projects, as that usage can cause problems in name resolution.
  
 +
Your next task in this tutorial is to create the following projects:<br>
  
 +
;PaymentService
 +
:Holds an EGL Service type and related definitions
 +
;PaymentClient
 +
:Holds the Rich UI Handler types and related definitions
 +
;PaymentShared
 +
:Holds types used both on the Web client (the browser) by the handlers and on the Web application server by the EGL services.
  
<ol><li>In the top menu of the EGL workbench, click '''Window''' and
+
You can include all your code in a single project, but the separation shown here lets you easily deploy the two kinds of code in different ways.  
then click '''Preferences''' &gt; '''EGL''' &gt; '''SQL Database Connections'''.
+
<li>Next to the list of connection details, click '''New'''.
+
<li>In the Connection Profile window,
+
complete these steps:
+
  
<ol><li>Under '''Connection Profile Types''',
+
Types in one project can use types in a different project. EGL uses a ''build path'' to search for unresolved references. Later in this lesson, you will add the service project to the build path for the client project and the shared project to the build path for both the service and client projects.
click '''Derby'''.
+
<li>In the '''Name''' field, type the following
+
string:
+
  
Derby Database Connection
+
== Create the PaymentShared project  ==
  
<li>Click '''Next'''.
+
To create the project that contains shared types:
</ol>
+
  
<li>In the Specify a Driver and Connection Details window,
+
#If you have been working with EGL in the current workspace, click '''File &gt; New''' '''&gt; EGL Project'''. If you have not been working with EGL, you might need to click '''File &gt; New''' '''&gt; Other''' and then expend '''EGL''' and click '''EGL Project'''. <br>  
specify the following information:
+
#On the '''EGL Project''' window, enter project name '''PaymentShared''', click template '''Basic''', and click '''Next'''.<br>[[Image:EDT Tutorial edt richui sql02 create shared project.jpg|Create PaymentShared EGL project]]
 +
#On the '''EGL Settings''' window, accept the default values and click '''Finish'''.<br>[[Image:EDT Tutorial edt richui sql02 shared project settings.jpg|PaymentShared project EGL settings]]
  
<ol><li>From the '''Drivers''' list, select '''Derby
+
EGL creates a project named '''PaymentShared'''. Note the folders inside the directory:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [[Image:EDT Tutorial edt richui sql03 service explore.jpg|The Project Explorer view shows the new project and folders.]]
Embedded JDBC Driver 10.1 Default'''.
+
<li>For the '''Database location''' field,
+
enter a simple path:
+
  
C:\databases\PaymentDB
+
;EGLSource
The
+
:Put your packages and source files here.
final element in the path is the name of a folder that does not yet
+
;EDT System Libraries
exist.
+
:Access the read-only type definitions that are already provided.
<li>Specify generic login information:  
+
;src
 +
:Put any custom Java source files here. These files are not overwritten during the generation process.  
 +
;JRE System Library
 +
:EGL uses this folder for JAR files that support the Java Runtime Environment.
  
<ul><li>In the '''User name''' field, enter <tt>admin</tt>
+
Once you add your first EGL program, the following additional directories will be added automatically:
<li>In the '''Password''' field, also enter <tt>admin</tt>
+
</ul>
+
  
<li>Select the '''Create database (if required)''' check
+
;generatedJava
box.
+
:EGL places the Java files it generates here.  
<li>Select the '''Save password''' check
+
;EDT Java runtime
box. When you work with live data, you might prefer not
+
:EGL uses this folder for JAR files that support the EDT Java Runtime Environment.
to select this option, but it simplifies the tutorial.
+
<li>Make sure that '''Connect when the wizard completes''' is
+
selected and that '''Connect every time the workbench is started''' is
+
cleared. [[Image:EDT_Tutorial_edt_richui_sql02_specify_driver.jpg|EDT_Tutorial_edt_richui_sql02_specify_driver.jpg]]
+
  
<li>Click '''Test Connection'''. You should see a message that says &quot;œPing succeeded!&quot;? Click '''OK''' to
+
<br>  
close the message window. If the test failed, get more information
+
by clicking '''Details''' on the failure message.
+
<li>Click '''Finish'''.
+
</ol>
+
  
<li>In the Preferences window, make sure
+
== Create the PaymentService project  ==
that '''Derby Database Connection''' is highlighted,
+
then click '''OK'''.
+
</ol>
+
  
== Switch to the Data perspective ==
+
To create an EGL service project:
  
 +
#Click '''File &gt; New''' '''&gt; EGL Project'''.
 +
#On the '''EGL Project''' window, enter project name '''PaymentService''', click template <span style="font-weight: bold;">B</span>'''asic''' and then '''Next'''.<br>
 +
#On the '''EGL Settings''' window, check '''Override Generation Settings''', uncheck '''JavaScript Generator''', and click '''Next'''.<br>[[Image:EDT Tutorial edt richui sql02 service project settings.jpg|PaymentService project EGL settings]]
 +
#On the '''EGL BuildPath''' window, check '''PaymentShared''' (the service project uses types in the shared project) <br>and click '''Finish'''.<br>[[Image:EDT Tutorial edt richui sql02 service project EGL path.jpg|PaymentService project EGL build path]]
 +
#Change In the '''Java Build Path''', add PaymentShared as the required project. <br>[[Image:EDT Tutorial edt richui sql02 service project Java build path.JPG|PaymentService project Java build path]]
  
 +
::<br>This step ensures that the output generated for PaymentService will be able to access the output generated for PaymentShared.
  
To set up the Derby database for your application, use
+
== Create the PaymentClient project  ==
the Data perspective, which is a workbench perspective and different
+
from the EGL Data view.
+
  
To connect to the database:
+
An EGL Rich UI project includes many shortcuts to speed the development of a user interface for the web.
  
 +
To create an EGL Rich UI project:
  
<ol><li>Change to the Data perspective as follows:
+
#Click '''File &gt; New''' '''&gt; EGL Project'''.
 +
#On the '''EGL Project''' window, enter project name '''PaymentClient''', click template '''Web 2.0 client application''', <br>and click '''Next'''.<br>[[Image:EDT Tutorial edt richui sql02 create client project.jpg|Create PaymentClient EGL project]]
 +
#On the '''Web 2.0 Client Application Settings''' window, accept the default values and click '''Next'''.[[Image:EDT Tutorial edt richui sql02 client project web settings.jpg|PaymentClient project Web settings]]
 +
#On the '''EGL BuildPath''' window, check '''PaymentShared''' and '''PaymentService''' (the client project uses types in the shared and service projects) and left click on '''Finish'''.<br>[[Image:EDT Tutorial edt richui sql02 service project EGL path(new).JPG|PaymentClient project EGL build path]]
 +
#Configure the '''Java Build Path''' of the project by adding the required service project.
  
<ol><li>Click the Open Perspective button, which is located
+
    [[Image:EDT Tutorial edt richui sql02 service project Java build path2.JPG|Configure Java Build Path]]  
by default in the right side of the navigation bar. [[Image:EDT_Tutorial_edt_richui_sql02_open_perspective.jpg|The Open Perspective button]]
+
  
<li>If the Data perspective is not shown on the menu, click '''Other'''.
+
EGL creates a project named '''PaymentClient'''. When you first add a Rich UI project to your workspace, two other projects are added automatically:  
<li>If you still do not see the Data perspective, select '''Show
+
All''' at the bottom of the wizard. Click '''Data''' and
+
then click '''OK'''. [[Image:EDT_Tutorial_edt_richui_sql02_data_perspective.jpg|The Data perspective in the menu of perspectives.]]
+
  
</ol>
+
*org.eclipse.edt.rui.widgets_''versionNumber''; and
 +
*org.eclipse.edt.rui.dojo.remote_''versionNumber'' or (if you are developing a mobile application) org.eclipse.edt.rui.dojo.mobile.widgets_''versionNumber&nbsp;''.
  
<li>Locate the Data Source Explorer view, by default in the
+
The two projects provide access to widgets and other definitions that you use when creating a Rich UI application.  
lower left corner of the workbench; and under '''Database
+
Connections''', right-click '''Derby Database Connection'''.
+
Click the '''Connect''' option. The option
+
was enabled because you set the following check boxes when you created
+
the connection: '''Create database (if required)''' and '''Connect
+
when the wizard completes'''.
+
</ol>
+
  
== Create a table ==
+
The folder structure for the '''PaymentClient''' project includes the '''WebContent''' directory, which contains support files such as cascading style sheets (CSS) and images:<br>
  
 +
[[Image:EDT Tutorial edt richui sql03 explore.jpg|The Project Explorer view shows the new project and folders.]]<br>
  
 +
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
  
While in the Data perspective, you can write an SQL script
+
== Lesson checkpoint  ==
to create a table in the database.
+
  
<ol><li>In the Data Source Explorer view, expand '''Derby
+
In this lesson, you completed the following tasks:  
Database Connection'''. Right-click the '''PaymentDB''' database
+
name and click '''New SQL Script'''. [[Image:EDT_Tutorial_edt_richui_sql02_new_sql_script.jpg|The menu for the new database]]
+
A new script file
+
opens in the editor.
+
<li>Copy the following SQL code into the script file:  
+
  
CREATE TABLE PAYMENT(
+
*Created an EGL project for developing types that are used in both in the service and the Rich UI application
  PAYMENT_ID INT PRIMARY KEY NOT NULL
+
*Created an EGL project for the services used in the application
      GENERATED ALWAYS AS IDENTITY
+
*Created an EGL project for Web 2.0 Rich UI pages to be used in the application
      (START WITH 1, INCREMENT BY 1),
+
  CATEGORY INT,
+
  DESCRIPTION CHAR(30),
+
  AMOUNT DECIMAL(10,2),
+
  FIXED_PAYMENT SMALLINT,
+
  DUE_DATE DATE,
+
  PAYEE_NAME CHAR(30),
+
  PAYEE_ADDRESS1 CHAR(30),
+
  PAYEE_ADDRESS2 CHAR(30));
+
In the next step, you run
+
this code to create a table named PAYMENT.
+
  
'''Note:'''
+
In the next lesson, you will
  
<ol><li>The PAYMENT_ID column is an identity column, which means that
+
*Set up the database connection
Derby will place a unique value into that column whenever the user
+
*Create the database table
creates a record. Each value is one more than the last.
+
*Create a Record type, retrieving most information from a database.
<li>The names of Derby tables and columns are always in uppercase
+
regardless of the case of names that are in the CREATE TABLE statement.
+
</ol>
+
  
<li>Right-click anywhere in the background of the editor pane,
+
{| style="float: right;" class="FCK__ShowTableBorders"
and then click '''Run SQL'''. The
+
|-
SQL Results view, which is by default at the bottom center of the
+
| [[EDT:Tutorial: RUI With DataBase Lesson 1|&lt; Previous]] &#124; [[EDT:Tutorial: RUI With DataBase Lesson 3|Next &gt;]]
workbench, should show the &quot;œcreate table&quot;? operation and a status of
+
&quot;œSucceeded&quot;?. You can now expand the '''PaymentDB''' entry
+
in the Data Source Explorer and see the columns for the new table:[[Image:EDT_Tutorial_edt_richui_sql02_exp_table.jpg|The column names are under Schemas/APP/Tables/PAYMENT/Columns.]]
+
 
+
<li>Close the script file. You do not need to save the file,
+
as you will not need it again.
+
<li>You cannot access the database from EGL source code while
+
the Data view is using the connection. Right-click '''Derby
+
database connection''' and click '''Disconnect'''.
+
</ol>
+
 
+
== Lesson checkpoint ==
+
 
+
In this lesson, you completed the following tasks:
+
 
+
<ul><li>Created an EGL database connection
+
<li>Created a database named <tt>PaymentDB</tt>
+
<li>Created a database table named <tt>PAYMENT</tt>
+
</ul>
+
 
+
In the next lesson, you start writing application code.
+
 
+
 
+
 
+
{| style="float: right"
+
|[[EDT:Tutorial: RUI With DataBase Lesson 1|&lt; Previous]] | [[EDT:Tutorial: RUI With DataBase Lesson 3|Next >]]
+
 
|}
 
|}
 
  
 
[[Category:EDT]]
 
[[Category:EDT]]

Latest revision as of 16:56, 5 July 2012

Access a database with EGL Rich UI

< Previous | Next >

Lesson 2: Set up the projects

An EGL application is organized in one or more projects, each of which is a physical folder in the workspace. A project contains an EGL source folder that is provided for you, and that folder contains one or more packages, which in turn contain EGL source files. This hierarchy is basic to your work in EGL: a project, then an EGL source folder, then a package with EGL source files.

The EGL source files include EGL custom types, which are type definitions that you create. For example, a Service type contains logic, and a Record type can be the basis of a variable that you declare in your Service type.

Packages are important because they separate types into different contexts, or namespaces:

  • A type name might be duplicated in two different packages, and any EGL source code can reference each type precisely. The main benefit of namespaces is that different teams can develop different EGL types without causing name collisions.
  • Each type name in a given package is unique within that package:
    • A type in one package can easily reference another type in the same package by specifying the type name. For example, here is a declaration of a record that is based on the Record type named MyRecordType: myRecord MyRecordType{};
    • A type in one package can also reference a type in a second package by giving the package name and type name, or by a shortcut that involves importing the type.

One project can reference the types in a second project, but only if the EGL build path of the referencing project identifies the referenced project. Again, this tutorial gives examples. However, in all cases, avoid using the same package name in different projects, as that usage can cause problems in name resolution.

Your next task in this tutorial is to create the following projects:

PaymentService
Holds an EGL Service type and related definitions
PaymentClient
Holds the Rich UI Handler types and related definitions
PaymentShared
Holds types used both on the Web client (the browser) by the handlers and on the Web application server by the EGL services.

You can include all your code in a single project, but the separation shown here lets you easily deploy the two kinds of code in different ways.

Types in one project can use types in a different project. EGL uses a build path to search for unresolved references. Later in this lesson, you will add the service project to the build path for the client project and the shared project to the build path for both the service and client projects.

Create the PaymentShared project

To create the project that contains shared types:

  1. If you have been working with EGL in the current workspace, click File > New > EGL Project. If you have not been working with EGL, you might need to click File > New > Other and then expend EGL and click EGL Project.
  2. On the EGL Project window, enter project name PaymentShared, click template Basic, and click Next.
    Create PaymentShared EGL project
  3. On the EGL Settings window, accept the default values and click Finish.
    PaymentShared project EGL settings

EGL creates a project named PaymentShared. Note the folders inside the directory:
            The Project Explorer view shows the new project and folders.

EGLSource
Put your packages and source files here.
EDT System Libraries
Access the read-only type definitions that are already provided.
src
Put any custom Java source files here. These files are not overwritten during the generation process.
JRE System Library
EGL uses this folder for JAR files that support the Java Runtime Environment.

Once you add your first EGL program, the following additional directories will be added automatically:

generatedJava
EGL places the Java files it generates here.
EDT Java runtime
EGL uses this folder for JAR files that support the EDT Java Runtime Environment.


Create the PaymentService project

To create an EGL service project:

  1. Click File > New > EGL Project.
  2. On the EGL Project window, enter project name PaymentService, click template Basic and then Next.
  3. On the EGL Settings window, check Override Generation Settings, uncheck JavaScript Generator, and click Next.
    PaymentService project EGL settings
  4. On the EGL BuildPath window, check PaymentShared (the service project uses types in the shared project)
    and click Finish.
    PaymentService project EGL build path
  5. Change In the Java Build Path, add PaymentShared as the required project.
    PaymentService project Java build path

This step ensures that the output generated for PaymentService will be able to access the output generated for PaymentShared.

Create the PaymentClient project

An EGL Rich UI project includes many shortcuts to speed the development of a user interface for the web.

To create an EGL Rich UI project:

  1. Click File > New > EGL Project.
  2. On the EGL Project window, enter project name PaymentClient, click template Web 2.0 client application,
    and click Next.
    Create PaymentClient EGL project
  3. On the Web 2.0 Client Application Settings window, accept the default values and click Next.PaymentClient project Web settings
  4. On the EGL BuildPath window, check PaymentShared and PaymentService (the client project uses types in the shared and service projects) and left click on Finish.
    PaymentClient project EGL build path
  5. Configure the Java Build Path of the project by adding the required service project.
    Configure Java Build Path 

EGL creates a project named PaymentClient. When you first add a Rich UI project to your workspace, two other projects are added automatically:

  • org.eclipse.edt.rui.widgets_versionNumber; and
  • org.eclipse.edt.rui.dojo.remote_versionNumber or (if you are developing a mobile application) org.eclipse.edt.rui.dojo.mobile.widgets_versionNumber .

The two projects provide access to widgets and other definitions that you use when creating a Rich UI application.

The folder structure for the PaymentClient project includes the WebContent directory, which contains support files such as cascading style sheets (CSS) and images:

The Project Explorer view shows the new project and folders.

     

Lesson checkpoint

In this lesson, you completed the following tasks:

  • Created an EGL project for developing types that are used in both in the service and the Rich UI application
  • Created an EGL project for the services used in the application
  • Created an EGL project for Web 2.0 Rich UI pages to be used in the application

In the next lesson, you will

  • Set up the database connection
  • Create the database table
  • Create a Record type, retrieving most information from a database.
< Previous | Next >

Back to the top