|
The first step in creating a
Composer service or component is usually to create the appropriate kind of
Connection Resource. It's the Connection Resource, after all, that lets you
connect to your back-end data source, whatever it happens to be. To obtain the
connection, you generally have to supply some basic information regarding ports
and/or driver names and/or user authentication. Usually, you know this
information in advance and can just enter it once into the Connection Resource.
But sometimes you may not know the information until runtime. The question
arises: How can you create the Connection Resource (and store its information as
a static file on disk) if you don't know the necessary parameter values until
runtime?
The solution to this problem is
to use expression-based parameters. In Composer, the "Create a New Connection
Resource" wizard will let you specify connection parameters in two ways: as
Constants or as Expressions. By default, the wizard's parameter-entry fields
are static or constant-based, which means that the literal value you enter for
any given parameter is utilized unchanged, every time the connection is used. An
expression-based parameter, by contrast, gets its value programmatically, at
runtime, via an ECMAScript expression which you supply in the wizard at design
time. The value of an expression-driven parameter, therefore, can be different
each time a connection is used, depending on the conditions prevailing at
runtime.
For
instance, one very simple use of an expression driven parameter in a JDBC
Connection would be to define the User ID and Password as PROJECT Variables: for
example, PROJECT.XPath("USERCONFIG/MyDeployUser". (From
Designer's main menubar, choose Tools,
then Configuration, then select the Project
Variables tab.) When
you go to deploy the project, you can update your
PROJECT Variables in the Deployment Wizard to values appropriate for the
final deployment environment.
As another
example, suppose Queue1 in your MOM environment is scheduled for maintenance on
the 15th day of every month, in which case Queue2 should be used instead. You
could assign an expression to the Queue Name parameter of the connection:
(new
Date).getDate() == 15 ? "Queue1" : "Queue2"
You can also
use an ECMAScript expression to read information from a file on disk, call a
Java object in the Application Server, etc.
As you can see,
the use of expressions to provide parameter information in Connection Resources
affords great flexibility and power. Keep this in mind the next time you design
a Composer service.
|