Apama 10.7.2 | Connecting Apama Applications to External Components | Standard IAF Plug-ins | The Database Connector IAF Adapter (ADBC) | The ADBCHelper application programming interface | Opening databases
 
Opening databases
The ADBCHelper API provides several actions for opening databases. The quick open actions allow you to open JDBC and ODBC databases by passing in a minimal set of parameters, while the full open action provides more control by passing in a complete set of parameters. The shared open action allows you to use an already open existing matching connection or open a new connection if a matching one does not exist.
In the following quick open actions, you need to pass in values for the following parameters:
*URL — database connection string
*user — user name
*password — user password
*handleError — name of a default error handler
See Handling errors for more information on creating actions to handle errors.
The quick open actions use the default settings for the autoCommit (true), batchSize (100), and timeOut (30.0) properties.
action openQuickJDBC(
    string URL,
    string user,
    string password,
    action < string > handleError )

action openQuickODBC(
    string URL,
    string user,
    string password,
    action < string > handleError )
The following code snippet shows a use of the openQuickJDBC action.
com.apama.database.DBUtil db;
action onload() {
string dbUrl:= "jdbc:mysql://127.0.0.1:3306/exampledb";
string user := "thomas";
string password := "thomas-123";
db.openQuickJDBC(dbUrl, user, password, handleError );
// ...
For the following open action you need to pass in all parameters.
action open(
    string type,
string serviceId,
    string URL,
    string user,
    string password,
    string autoCommit,
boolean readOnly,
    integer batchSize,
    float timeOut,
    action < string > handleError )
Setting the autoCommit, batchSize, and timeOut parameters in the open action over-rides the adapter properties specified in the IAF configuration file.
*type — The data source type (ODBC, JDBC, Sim, etc.)
*serviceId — The service id for the adapter
*URL — The database connection string
*user — The user name
*password — The user password
*autoCommit — The auto commit mode to use. If this parameter is not set, the open action uses a combination of the AutoCommit and StoreCommitInterval properties specified in the adapter's configuration file. For information on these properties, see Configuring an ADBC adapter. The value for the autoCommit parameter can be one of the following modes:
*"" — An empty string specifies that the value set in the configuration file should be used.
*true — Enables the ODBC/JDBC driver's auto commit.
*false — Disable autoCommit.
*x.x — Use timed auto commit interval in seconds.
For more information on the interaction of the AutoCommit, StoreCommitInterval and StoreBatchSize properties, see Committing database changes.
*readOnly — Specifies if the connection should be read-only. If the connection is read-only an error will be reported for any API action that requires writes (Store, Commit, or Rollback). Most databases do not prevent writes from a connection in read-only mode so it is still possible to perform writes using the Command actions.
*batchSize — The query results batch size to be used for any queries performed.
*timeOut — Controls how long the ADBC open action will wait for the adapter to become available if it is not running when the open action is called.
The following code snippet shows a use of the open action. It creates variables for each of the parameters and passes them with the open action.
com.apama.database.DBUtil db;
action onload() {
string type := "jdbc";
string serviceId := "com.apama.adbc.JDBC";
string dbUrl:= "jdbc:mysql://127.0.0.1:3306/exampledb";
string user := "thomas";
string password := "thomas-123";
string commit := "15.0";
boolean readMode := false;
float openTimeout := 30.0;
Integer queryBatchSize := 100
db.open(type, serviceId, dbUrl, user, password, commit,
readMode, openTimeout, queryBatchSize, handleError );
// ...
The following open action allows you to use a connection that is already open; the action opens a connection if an existing matching connection is not found. The openShared action uses the same parameters as the open action, above.
action openShared(
string type,
string serviceId,
string URL,
string user,
string password,
string autoCommit,
boolean readOnly,
integer batchSize,
float timeOut,
action < string > errorHandler )