Service Database

from database import Database

Port NameLocationProtocolInterfaces
iplocalDatabaseInterface

List of Available Interfaces

DatabaseInterface

Operation NameInput TypeOutput TypeFaultsDescription
beginTxvoidTxHandle
SQLExceptionundefined
ConnectionErrorundefined

Designates a connection from the connection pool as an open transaction, and returns an int which can be used to refer to the now open transaction.
checkConnectionvoidvoid
ConnectionErrorundefined

Checks the connection with the database. Throws ConnectionError if the connection is not functioning properly.
closevoidvoid-
Explicitly closes a database connection
Per default the close happens on reconnect or on termination of the
Database service, eg. when the enclosing program finishes.
commitTxTxHandlevoid
TransactionExceptionundefined
SQLExceptionundefined
ConnectionErrorundefined

Commits and closes the connection associated with the transaction handle in CommitTransactionRequest. The connection is
then returned to the connection pool, and any further actions attempted using the transaction handle will throw a TransactionException.
connectConnectionInfovoid
InvalidDriverundefined
ConnectionErrorundefined
DriverClassNotFoundundefined

Connects to a database and closes any potential preexisting database connection.

Example with HSQLDB:
with ( connectionInfo ) {
.username = "sa";
.password = "";
.host = "";
.database = "file:weatherdb/weatherdb"; // "." for memory-only
.driver = "hsqldb_embedded"
};
connect@Database( connectionInfo )( void );
executeTransactionDatabaseTransactionRequestDatabaseTransactionResult
SQLExceptionundefined
ConnectionErrorundefined

Executes more than one database command in a single transaction
queryQueryRequestQueryResult
TransactionExceptionundefined
SQLExceptionundefined
ConnectionErrorundefined

Queries the database and returns a result set

Example with SQL parameters:
queryRequest =
"SELECT city, country, data FROM weather " +
"WHERE city=:city AND country=:country";
queryRequest.city = City;
queryRequest.country = Country;
query@Database( queryRequest )( queryResponse );

_template:
Field _template allows for the definition of a specific output template.
Assume, e.g., to have a table with the following columns:
rollbackTxTxHandlevoid
TransactionExceptionundefined
SQLExceptionundefined
ConnectionErrorundefined

Rolls back and closes the connection associated with the handle TxHandle. The connection is
then returned to the connection pool, and any further actions attempted using the transaction handle will throw a TransactionException.
updateUpdateRequestint
TransactionExceptionundefined
SQLExceptionundefined
ConnectionErrorundefined

Updates the database and returns a single status code

Example with SQL parameters:
updateRequest =
"INSERT INTO weather(city, country, data) " +
"VALUES (:city, :country, :data)";
updateRequest.city = City;
updateRequest.country = Country;
updateRequest.data = r;
update@Database( updateRequest )( ret )

To run the update within specific transaction, a transaction handle can be provided along with the updateRequest.
To execute the updateRequest above in an open transaction with txHandle 42, we can call update in the following way:
updateDatabase@Database( {
txHandle = 42
update = updateRequest
} )( ret )

Types

ConnectionInfo:
Type Declaration
void {
  database[1,1]: string // 
  password[1,1]: string // 
  checkConnection[0,1]: int // 
  driver[1,1]: string {
    class[0,1]: string //  it allows for specifying a specific driver Java class
  } // 
  port[0,1]: int // 
  connectionPoolConfig[0,1]: ConnectionPoolConfig // 
  toLowerCase[0,1]: bool // 
  host[1,1]: string // 
  toUpperCase[0,1]: bool // 
  attributes[0,1]: string // 
  username[1,1]: string // 
}
ConnectionPoolConfig:
Type Declaration
void {
  transactionIsolation[0,1]: string // 
  initializationFailTimeout[0,1]: int // 
  validationTimeout[0,1]: int // 
  catalog[0,1]: string // 
  readOnly[0,1]: bool // 
  isolateInternalQueries[0,1]: bool // 
  maxLifetime[0,1]: int // 
  connectionInitSql[0,1]: string // 
  minimumIdle[0,1]: int // 
  idleTimeout[0,1]: int // 
  connectionTestQuery[0,1]: string // 
  maximumPoolSize[0,1]: int // 
  connectionTimeout[0,1]: int // 
  poolName[0,1]: string // 
}
DatabaseTransactionRequest:
Type Declaration
void {
  statement[1,1]: string // 
}
DatabaseTransactionResult:
Type Declaration
void {
  result[0,1]: TransactionQueryResult // 
}
QueryRequest:
Type Declaration
string
|void {
  txHandle[1,1]: TxHandle // 
  query[1,1]: string // 
}

QueryResult:
Type Declaration
void {
  row[0,1]: void // 
}
TransactionQueryResult:
Type Declaration
int {
  row[0,1]: void // 
}
TxHandle:
Type Declaration
long
UpdateRequest:
Type Declaration
string
|void {
  txHandle[1,1]: TxHandle // 
  update[1,1]: string // 
}