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"

(The typical process)
Line 1: Line 1:
<span style="font-size:smaller;">&lt;&nbsp;[[EDT|EDT wiki home]]</span> <br />
+
<span style="font-size:smaller;">&lt;&nbsp;[[EDT|EDT wiki home]]</span> <br> 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. In most cases, you maintain bindings in an EGL deployment descriptor, which is external to your logic. The deployment descriptor provides the access details when you are developing or deploying your application.  
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. In most cases, you maintain bindings in an EGL deployment descriptor, which is external to your logic. The deployment descriptor 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 redeploy the code without changing the logic and without spending the time to regenerate output.&nbsp;'''<br> '''  
 
This use of the deployment descriptor is safe and flexible. You can change the details stored there and redeploy the code without changing the logic and without spending the time to regenerate output.&nbsp;'''<br> '''  
Line 9: Line 8:
  
 
#Write a resource binding in an EGL deployment descriptor.<br>  
 
#Write a resource binding in an EGL deployment descriptor.<br>  
#Relate a variable to the stored resource binding in either of two ways: by invoking the '''SysLib.getResource''' function or by writing a '''Resource''' annotation.&nbsp; A variable that includes binding detail is called a ''binding variable''.
+
#Relate a variable to the stored resource binding in either of two ways: by invoking the '''SysLib.getResource''' function or by writing a '''Resource''' annotation.&nbsp; A variable that includes binding detail is called a ''binding variable''.  
 
#Please the binding variable in an EGL statement. If you are accessing external logic, use the '''call''' statement. If you are accessing a database, use one of the statements that read or write data; for example, the '''add''' or '''get''' statement.
 
#Please the binding variable in an EGL statement. If you are accessing external logic, use the '''call''' statement. If you are accessing a database, use one of the statements that read or write data; for example, the '''add''' or '''get''' statement.
  
Line 15: Line 14:
 
<pre>myBindingVar HttpRest? = SysLib.getResource("binding:myEntry");
 
<pre>myBindingVar HttpRest? = SysLib.getResource("binding:myEntry");
 
</pre>  
 
</pre>  
The function call requires a single argument, which identifies an entry in the EGL deployment descriptor.
+
The function call requires a single argument, which identifies an entry in the EGL deployment descriptor.  
  
Here is an example use of the equivalent Resource annotation, which you can specify anywhere that you declare a variable: <br>
+
Here is an example use of the equivalent Resource annotation, which you can specify anywhere that you declare a variable: <br>  
 
<pre>myBindingVar HttpRest?{@Resource{uri="binding:myEntry"}};
 
<pre>myBindingVar HttpRest?{@Resource{uri="binding:myEntry"}};
 
</pre>  
 
</pre>  
 
The '''uri''' annotation field is optional and refers by default to a resource binding that has the same name as the variable. For example, the missing value for the '''uri''' field in the following annotation is <code>"binding:<span style="font-family: sans-serif;">myBindingVar</span></code>":<br>  
 
The '''uri''' annotation field is optional and refers by default to a resource binding that has the same name as the variable. For example, the missing value for the '''uri''' field in the following annotation is <code>"binding:<span style="font-family: sans-serif;">myBindingVar</span></code>":<br>  
<pre>myBindingVar HttpRest {@Resource {uri="binding:file:myDDFile#myEntry"}};
+
<pre>myBindingVar HttpRest {@Resource};
 +
</pre>
 +
Whether you s pecify the SysLib.getResource function or Resource annotation, you can use an extended format ("binding:file:entry") to identify the EGL deployment descriptor that contains the entry. Here is an example:
 +
<pre>myBindingVar HttpRest? = SysLib.getResource("binding:file:myDDFIle#myEntry");
 +
 
 +
 
 +
// equivalent annotation
 +
myBindingVar HttpRest?{@Resource{uri = "binding:file:myDDFile#myEntry"}};
 
</pre>
 
</pre>
If you do not use the extended format, the reference EGL deployment descriptor is as follows:
+
If you do not use the extended format, the reference EGL deployment descriptor is as follows:  
  
 
*At development time, the code is referencing the development deployment descriptor. That descriptor is the one that is identified in the following project property: '''Development Deployment Descriptor'''.&nbsp;  
 
*At development time, the code is referencing the development deployment descriptor. That descriptor is the one that is identified in the following project property: '''Development Deployment Descriptor'''.&nbsp;  
 
*At deployment time, the code is referencing the deployment descriptor that you deploy.
 
*At deployment time, the code is referencing the deployment descriptor that you deploy.
  
 +
<br>
  
 
+
<br>
 
+
  
 
Whether you specify the SysLib.getResource function or Resource annotation, you can use an extended format ("binding:file#entry") to identify the EGL deployment descriptor that contains the entry. Here is an example:&nbsp;  
 
Whether you specify the SysLib.getResource function or Resource annotation, you can use an extended format ("binding:file#entry") to identify the EGL deployment descriptor that contains the entry. Here is an example:&nbsp;  
Line 42: Line 48:
  
 
myService MyInterfaceType?
 
myService MyInterfaceType?
 +
 +
 +
 +
  
  
 
   (@Resource{uri = "binding:file:myDDFile#myBinding"}};            // .8 syntax</pre>  
 
   (@Resource{uri = "binding:file:myDDFile#myBinding"}};            // .8 syntax</pre>  
If you do not identify an EGL deployment descriptor, the referenced file is the one that is currently in use. At development time, the one that is currently in use is identified in the following project property: '''Development Deployment Descriptor''' . At deployment time, the referenced deployment descriptor is the one that you deploy. <br> <br>
+
If you do not identify an EGL deployment descriptor, the referenced file is the one that is currently in use. At development time, the one that is currently in use is identified in the following project property: '''Development Deployment Descriptor''' . At deployment time, the referenced deployment descriptor is the one that you deploy. <br> <br>  
  
 
= Bindings in your code  =
 
= Bindings in your code  =
Line 61: Line 71:
 
The following topic gives an overview on IBM i support, which also involves resource bindings:  
 
The following topic gives an overview on IBM i support, which also involves resource bindings:  
  
*[[EDT:Support for IBM i|Support for IBM i]]  
+
*[[EDT:Support for IBM i|Support for IBM i]]
 
+
  
<br>
+
<br> <br>

Revision as of 21:26, 15 March 2012

EDT wiki home
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. In most cases, you maintain bindings in an EGL deployment descriptor, which is external to your logic. The deployment descriptor 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 redeploy the code without changing the logic and without spending the time to regenerate output. 

The typical process

The binding mechanism is the same for service and database access. The typical process is as follows:

  1. Write a resource binding in an EGL deployment descriptor.
  2. Relate a variable to the stored resource binding in either of two ways: by invoking the SysLib.getResource function or by writing a Resource annotation.  A variable that includes binding detail is called a binding variable.
  3. Please the binding variable in an EGL statement. If you are accessing external logic, use the call statement. If you are accessing a database, use one of the statements that read or write data; for example, the add or get statement.

Here is an example use of the SysLib.getResource function, which can be invoked only inside an EGL function:

myBindingVar HttpRest? = SysLib.getResource("binding:myEntry");

The function call requires a single argument, which identifies an entry in the EGL deployment descriptor.

Here is an example use of the equivalent Resource annotation, which you can specify anywhere that you declare a variable:

myBindingVar HttpRest?{@Resource{uri="binding:myEntry"}};

The uri annotation field is optional and refers by default to a resource binding that has the same name as the variable. For example, the missing value for the uri field in the following annotation is "binding:myBindingVar":

myBindingVar HttpRest {@Resource};

Whether you s pecify the SysLib.getResource function or Resource annotation, you can use an extended format ("binding:file:entry") to identify the EGL deployment descriptor that contains the entry. Here is an example:

myBindingVar HttpRest? = SysLib.getResource("binding:file:myDDFIle#myEntry");


// equivalent annotation
myBindingVar HttpRest?{@Resource{uri = "binding:file:myDDFile#myEntry"}};

If you do not use the extended format, the reference EGL deployment descriptor is as follows:

  • At development time, the code is referencing the development deployment descriptor. That descriptor is the one that is identified in the following project property: Development Deployment Descriptor
  • At deployment time, the code is referencing the deployment descriptor that you deploy.



Whether you specify the SysLib.getResource function or Resource annotation, you can use an extended format ("binding:file#entry") to identify the EGL deployment descriptor that contains the entry. Here is an example: 

myBindingVar HttpRest? = SysLib.getResource("binding:file:myDDFile#myEntry");


// equivalent annotation
myBindingVar HttpRest? (

// equivalent annotation

myService MyInterfaceType?




(@Resource{uri = "binding:file:myDDFile#myBinding"}}; // .8 syntax

If you do not identify an EGL deployment descriptor, the referenced file is the one that is currently in use. At development time, the one that is currently in use is identified in the following project property: Development Deployment Descriptor . At deployment time, the referenced deployment descriptor is the one that you deploy.

Bindings in your code

A resource binding includes a series of fields that are characteristic of a particular type of binding. For example, a REST service binding has fields that are different from those in an SQL database binding. The existence of binding types means that you can go beyond the typical process described earlier:

  • You might define a variable that is of the appropriate binding type. You can assign field values to that variable and use the variable for resource access. In this case, the resource binding is solely in your code.
  • In relation to service bindings, you can initialize the variable with values from the EGL deployment descriptor and then update the fields in your code.

The next sections give further details:

The following topic gives an overview on IBM i support, which also involves resource bindings:



Back to the top