Advanced Database Feature Guide


Initialization and termination

The initialization tasks consist of the allocation and initialization of the environment and one or more connection objects.

There are three basic types of objects:

UtyDB2DatabaseManager
The UtyDB2DatabaseManager object is a singleton object that contains information regarding the global state of the applications, such as attributes and connections.

UtyDB2Connection
The UtyDB2Connection object contains information associated with a connection to a particular data source (database). This includes connection attributes, general status information, transaction status, and diagnostic information.

An application can be connected to several serves at the same time, and can establish several distinct connections to the same server. An application requires a connection object for each connection to a database server. For information on multiple connections, refer to Connecting to one or more data sources.

UtyDB2Statement
The UtyDB2Statement object is discussed in the next section entitled "Transaction Processing".

Connecting to one or more data sources

The Advanced Database feature supports three ways to connect to a data source. The simplest way is by sending the connectTo:as:password: message to the UtyDB2DatabaseManager class.

connection := 
UtyDB2DatabaseManager 
connectTo: 'SAMPLE' 
as: 'userid' 
password: 'password'. 

The second way involves the use of a connection descriptor. A connection descriptor is a session independent means of storing information about a connection and its attributes. In the following example, the connection’s auto commit attribute is specified using the connection descriptor.

connection := 
UtyDB2DatabaseManager newConnectionDescriptor 
databaseName: 'SAMPLE'; 
userId: 'user'; 
password: 'password'; 
autoCommit: false; 
connect. 

The third way a connection may be established is by using the DB2 CLI driver connect mechanism.

connection := UtyDB2DatabaseManager connectUsing: aConnectionString 

where aConnectionString has the following format:

+-,-----------------------------------------+ 
V | 
>>----+-DSN---------------------+=--attribute--+--------------->< 
+-UID---------------------+ 
+-PWD---------------------+ 
+-DB2 CLI-defined-keyword-+ 

Each keyword above has an attribute that is equal to the following:

DSN Data source name. The name or alias-name of the database.
UID Authorization-name (user identifier).
PWD The password corresponding to the authorization name. If there is no password for the user ID, an empty is specified (PWD=;).

The list of DB2 CLI defined keywords and their associated attribute values are discussed in the Configuration Keywords section of the DB2 Call Level Interface Guide and Reference. Any one of the keywords in that section can be specified on the connection string. If any keywords are repeated in the connection string, the value associated with the first occurrence of the keyword is used.

If any keyword exists in the CLI initialization file, the keyword and their respective values are used to augment the information passed to DB2 CLI in the connection string. If the information in the CLI initialization file contradicts information in the connection string, the values in connection string take precedence.

Object Termination

Most of the objects, including the database manager, implement a close method. In all cases, the close method causes the receiving object to release its handle to its corresponding CLI data object and well as any other system resource it references, such as allocated memory.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]