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 Databases"

Line 1: Line 1:
If the purpose of a resource binding is database access, the definition is called a ''database binding'', and the main detail is in one of three categories:
+
If the purpose of a resource binding is to access a relational database, the definition is called a ''SQL database binding'', and the main detail involves the following choices: 
  
 +
<br>
  
 
+
*&nbsp; Specify a JNDI<br>  
*&nbsp; <br>  
+
 
*&nbsp;  
 
*&nbsp;  
*&nbsp;  
+
*&nbsp;
 
+
  
 +
<br>
  
 
<br>  
 
<br>  

Revision as of 15:37, 23 January 2012

If the purpose of a resource binding is to access a relational database, the definition is called a SQL database binding, and the main detail involves the following choices: 


  •   Specify a JNDI
  •  
  •  



Binding DB with Reference in workspace

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


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.

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");
// 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 2.2

Binding DB with hard-coded

Add database binding

Please refer to section 2.1 for the detail<span style="text-decoration: underline;" />

Select database binding type

Select type of Add the information from the selected connection below(hard-coded information). You can also use the existing database connection or create a new database connection. The completed database binding should like below:

Bind Img5.JPG


In can also update or exit the database information manually. After updated database information manually, do NOT forget to click the “Test Connection” to verify the database connection worked.

Using the database binding in code

Please refer to section 2.3

Other way to define SQL database connection

Besides the resource binding, we can also define the SQL database connection directly in our source code.
For example:

// the data source includes a connection string, as well as
// security details that are stored in a dictionary.
 
connectURL string = "jdbc:derby:SomeDB;create=true;";
properties Dictionary{user = "MyID", password = "MyPassword"};
ds SQLDataSource? = new SQLDataSource(connectURL, properties);




Previous:  Service bindings

First:  Resource binding introduction

[[Category: EDT]]

Back to the top