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:Resource Binding Introduction"

(2.3 Using the database binding in code)
(2.3 Using the database binding in code)
Line 71: Line 71:
 
</source>
 
</source>
 
<br>  
 
<br>  
</source>
+
 
 
“propertyFileName” is the egldd file name of the project.<br>“bindingkey” is the SQL DataBase Binding Name which you created in 1.2<br><br>
 
“propertyFileName” is the egldd file name of the project.<br>“bindingkey” is the SQL DataBase Binding Name which you created in 1.2<br><br>

Revision as of 00:02, 21 December 2011

1 Introduction for Resource binding

There is already a tutorial in Eclipse Wiki page EDT:Tutorial:_Access_a_database_with_EGL_Rich_UI to introduce how to create a RUI project to connect a Database. But there are several different methods to binding the Database to your project. In this lesson, you will learn how to binding resources to your project which includes Database connection binding and service binding.

One of the more elegant aspects of EGL is its use of resource bindings, each of which is a value that describes how to access a service or database. The bindings are maintained in an EGL deployment descriptor, which is external to your logic and provides the access details when you are developing or deploying your application.

This use of the deployment descriptor is safe and flexible. You can change the details stored there and then redeploy the code without changing the access logic and without spending the time to regenerate output.

2 Binding DB with Reference in workspace

2.1 Add Database Binding

Open the egl deploy description file ***.elgdd and switch to “Resource Bindings” Tab, you will find there is a list for all the Resource binding of this project.


Img1.JPG


You can add new database bind by click the Add button. After clicked the Add button, a “Add a Resource Binding” dialog will pop and please check the Radio button of “SQL database binding” then click “Next” button

Bind Img2.JPG


2.2 Select database biding type

In the “Add a SQL Database Binding” dialog you can see, there are two types of SQL Binding

  • Reference the selected workspace connection below(retrieved at runtime)
  • Add the information from the selected connection below(hard-coded information)

There are differences between these two types of DB bindings. If you selected Reference binding, the DB information will be stored in deploy descriptor and you can update or edit it anytime via the egldd file without to touch the source code in order that to avoid the potential risk.

Select type of Reference the selected workspace connection below (retrieved at runtime)

Bind Img3.JPG


Select a database connection from the list or you can follow the instruction EDT:Tutorial:_Access_a_database_with_EGL_Rich_UI_Lesson_3 to create a database connection for your project.
Click the “Finish” button to complete the database connection binding. The database binding will be completed.

Bind img4.JPG


This type of database binding is retrieved at runtime, the database information depends on the database connection in this project. If you edited the database connection information, the database binding will also change accordingly.

2.3 Using the database binding in code

In project you can use this database binding to define a SQLDataSource.
For example:


//Define the SQLDataSource
ds SQLDataSource?{@resource{propertyFileName = "crud" , bindingkey = "NewMySQL"}};

or

ds SQLDataSource = SysLib.getResource("NewMySQL");
</soucre>
 
<source lang="java">
// Function Declarations
function getTable() returns (expense[])
    exp expense[];
    get exp from ds;
    return (exp);
end


“propertyFileName” is the egldd file name of the project.
“bindingkey” is the SQL DataBase Binding Name which you created in 1.2

Back to the top