Using SQL Adapters in Productions
Using the SQL Outbound Adapter
This chapter describes the default behavior of the SQL outbound adapter (EnsLib.SQL.OutboundAdapter
) and describes how to use this adapter in your productions. It discusses the following topics:
Within a production, an outbound adapter is associated with a business operation that you create and configure. The business operation receives a message from within the production, looks up the message type, and executes the appropriate method. This method usually executes methods of the associated adapter.
The SQL outbound adapter (EnsLib.SQL.OutboundAdapter
) provides settings that you use to specify the data source to connect to and any login details needed for that data source. It also provides methods to perform common SQL activities such as the following:
Executing stored procedures
Performing inserts, updates, and deletes
Creating a Business Operation to Use the Adapter
The following list describes the basic requirements of the business operation class:
parameter should specify the invocation style you want to use, which must be one of the following.
means the message is created within one background job and placed on a queue, at which time the original job is released. Later, when the message is processed, a different background job will be allocated for the task. This is the most common setting.
means the message will be formulated, sent, and delivered in the same job in which it was created. The job will not be released to the sender’s pool until the message is delivered to the target. This is only suitable for special cases.
Your class should define a message map
that includes at least one entry. A message map is an XData block entry that has the following structure:
Your class should define all the methods named in the message map. These methods are known as message handlers
. In general, these methods will refer to properties and methods of the Adapter
property of your business operation.
The following example shows the general structure that you need:
Class ESQL.NewOperation1 Extends Ens.BusinessOperation
Parameter ADAPTER = "EnsLib.SQL.OutboundAdapter";
Parameter INVOCATION = "Queue";
Method SampleCall(pRequest As Ens.Request, Output pResponse As Ens.Response) As %Status
Studio provides a wizard that you can use to create a stub similar to the preceding. To access this wizard, click New
on the File
menu and then click the Production
tab. Choose to create a business operation and select EnsLib.SQL.OutboundAdapter
as the associated outbound adapter.
Creating Methods to Perform SQL Operations
When you create a business operation class for use with EnsLib.SQL.OutboundAdapter
, typically your biggest task is writing message handlers, that is, methods to perform various SQL operations. In general, these methods will refer to properties and methods of the Adapter
property of your business operation. For example:
set tSC = ..Adapter.ExecuteUpdate(.numrows,sql)
A method might look like the following.
/// Insert into NewCustomer table
Method Insert(pReq As ESQL.request, Output pResp As ESQL.response1) As %Status
set sql="insert into NewCustomer (Name,SSN,City,SourceID) values (?,?,?,?)"
//perform the Insert
set tSC = ..Adapter.ExecuteUpdate
//create the response message
if 'tSC write " failed ",tSC quit tSC
Handling Multiple SQL Statements per Message
The adapter configuration is designed to deal with the simple case where the business operation executes one SQL statement per message it receives. If your business operation needs to execute multiple SQL statements for a given message, use the following style (or similar) in your OnMessage()
//... your ..Adapter SQL Operations here...
If 'tStayConn&&..Adapter.Connected Do ..Adapter.Disconnect()
Adding and Configuring the Business Operation
To add your business operation to a production, use the Management Portal to do the following:
Add an instance of your custom business operation class to the production.
Enable the business operation.
Configure the adapter to communicate with a specific external data source. Specifically:
Specifying the Data Source Name
provides a runtime setting that you use to specify the data source that you want to connect to. When you configure the business operation, you should set an appropriate initial value for this setting:
This data source name specifies the external data source to which to connect. InterSystems IRIS™ distinguishes between these three forms automatically: a defined InterSystems SQL Gateway connection, a JDBC URL, or an ODBC DSN configured in your operating system.
If this name matches the name of a JDBC or ODBC connection configured from the [Home] > [Configuration] > [Object/SQL Gateway Settings]
page of the Management Portal, InterSystems IRIS uses the parameters from that specification. If the entry is not the name of a configured connection and it contains a colon (:
), it assumes a JDBC URL, otherwise it assumes an ODBC DSN.
If you are using a JDBC data source, the following settings also apply:
Configuration name of the Java Gateway service controlling the Java Gateway server this operation uses.
This setting is required
for all JDBC data sources, even if you are using a working SQL gateway connection with JDBC. For JDBC connections to work, a business service of type EnsLib.JavaGateway.Service
must be present. The SQL adapter requires the name of this configuration item and uses its configured settings to connect to the JVM it manages.
If you use a named SQL Gateway Connection as DSN, this value is optional; but if present, it overrides the value specified in the named JDBC SQL Gateway Connection set of properties.
Classpath for JDBC driver class name, if needed in addition to the ones configured in the Java Gateway Service.
An optional set of SQL connection attribute options. For ODBC, they have the form:
For JDBC, they have the form
If you use a named JDBC SQL Gateway Connection as DSN, this value is optional; but if present, it overrides the value specified in the named JDBC SQL Gateway Connection set of properties.
Specifying Other Runtime Settings
Specifies whether to keep the connection open between commands, such as issuing an SQL statement or changing an ODBC driver setting.
If this setting is 0, the adapter disconnects immediately after each command.
If this setting is positive, it specifies the idle time, in seconds, after the command completes. The adapter disconnects after this idle time.
If this setting is 1, the adapter auto-connects on startup and then stays connected.