Purpose:
DKDatastorePool is a class that manages the datastore connection
pool. A DKDatastorePool object can only handle the connection pool
for one datastore type. You can use getConnection(userid, password)
and returnConnection(datastore) for the connected datastore with no
session ID. You can use getConnection(userid, password, sessionId)
and returnConnection(DKDatastoreSession) for the connected datastore
with the session ID. With the session ID you will get the same datastore
back, but it is not guaranteed if you leave it in the pool too long
because it will timeout. To guarantee the same connection information,
after a connected datastore is created, do not change the set information,
which includes the datastore name, connection string, configuration
string, maxPoolSize, minPoolsize and time out.
Class summary:
{
public:
DKEXPORT DKDatastorePool(const char* dsType, const char* factoryDLLName);
virtual ~DKDatastorePool();
virtual DKString getDatastoreName() const;
virtual void setDatastoreName(const char* aDSName);
virtual DKString getConnectString() const;
virtual void setConnectString(const char* connectString);
virtual DKString getConfigurationString() const;
virtual void setConfigurationString(const char* configString);
virtual int getMaxPoolSize() const;
virtual void setMaxPoolSize(int poolSize);
virtual int getMinPoolSize() const;
virtual void setMinPoolSize(int poolSize);
virtual int getTimeOut() const;
void setTimeOut(int timeOut);
virtual dkDatastore* getConnection(const char* userId,
const char* passwd);
virtual DKDatastoreSession* getConnection(const char* userId,
const char* passwd,
long aSessionId);
DKEXPORT virtual void returnConnection(dkDatastore* ds);
DKEXPORT virtual void returnConnection(DKDatastoreSession* aDsSession);
DKEXPORT virtual void removeConnection(dkDatastore* ds);
DKEXPORT virtual void removeConnection(DKDatastoreSession* aDsSession);
DKEXPORT virtual void initConnections(const char* userId,
const char* passwd,
int initSize);
DKEXPORT virtual void clearConnections();
DKEXPORT virtual DKString datastoreType() const;
Members:
- Constructor
- Create the datastore pool for a specific datastore type.
valid dsType: (case sensitive);
ICM, IP, OD, V4
valid factoryDLLName:
Windows: cmbxxfac817 or cmbxxfac8171
AIX: libcmbxxfac816.so
xx can be db2, icm, ip, od, v4
DKDatastorePool(const char* dsType, const char* factoryDLLName);
Destructor
virtual ~DKDatastorePool();
- Member functions
- getDatastoreName
- Gets the name of the datastore object. Usually it represents
a datastore source's server name.
virtual DKString getDatastoreName() const;
- setDatastoreName
- Sets the name of the datastore object. Usually it represents
a datastore source's server name. Once the datastore has been created
and connected, you cannot set it to a different name.
virtual void setDatastoreName(const char* aDSName);
- getConnectString
- Gets the connection string that is used to provide additional
connection options.
virtual DKString getConnectString() const;
- setConnectString
- Sets the connection string that is used to provide additional
connection options. Once a datastore has been created and connected,
you cannot set it to a different string.
virtual void setConnectString(const char* connectString);
- getConfigurationString
- Gets the configuration string which supplies the specific initialization
parameters for datastore.
virtual DKString getConfigurationString() const;
- setConfigurationString
- Sets the configuration string which supplies the specific initialization
parameters for datastore. Once a datastore has been created and connected,
you cannot set it to a different configuration string.
virtual void setConfigurationString(const char* configString);
- getMaxPoolSize
- Gets the maximum number of connections that the pool should
contain. 0(zero) indicates no maximum size (unlimited).
virtual int getMaxPoolSize() const;
- setMaxPoolSize
- Sets the maximum number of connections that the pool should
contain. 0 (zero) indicates no maximum size (unlimited). Once the
datastore has been created and connected, you cannot set it to a different
number.
virtual void setMaxPoolSize(int poolSize);
- getMinPoolSize
- Gets the minimum number of connections that the pool should
keep. 0(zero) indicates the connections should be created as needed.
virtual int getMinPoolSize() const;
- setMinPoolSize
- Sets the minimum number of connections that the pool should
keep. 0(zero) indicates the connections should be created as needed.
Once the datastore has been created and connected, you cannot set
it to a different number.
virtual void setMinPoolSize(int poolSize);
- getTimeOut
- Gets the number of minutes that a datastore connection should
remain unused in the pool before the datastore is disconnected and
destroyed. 0 (zero) indicates no limit.
virtual int getTimeOut() const;
- setTimeOut
- Sets the number of minutes that a datastore connection should
remain unused in the pool before the datastore is disconnected and
destroyed. 0 (zero) indicates no limit.
virtual void setTimeOut(int timeOut);
- getConnection
- Gets a connected datastore with no session Id from the pool
This will search the connected datastore with no session Id, if no
matched one it will create a new one.
virtual dkDatastore* getConnection(const char* userId, const char* passwd);
- getConnection
- Gets a connected datastore with sessionId from the pool and
returns a DKDatastaoreSession object that contains the connected datastore
and session ID. The sequence to get the connected datastore is:
if aSessionId <= 0
It will return a DKDatastoreSession object that contains
a new connected datastore with the next available session ID. When
the maximum pool is reached, it will search the available datastore
with no session ID and return DKDatastoreSession containing datastore
and the next available session ID. An application must call DKDatastoreSession
getId() to obtain the session ID.
If aSessionId > 0, the following search sequence is performed:
- Search the available datastore with the matching session ID. If
found, returns datastore and the same session ID.
- Search the available datastore with no session ID. If found, returns
DKDatastoreSession containing the datastore and assign the next available
session ID to it.
- Create a new connected datastore with the next available session
ID, returns DKDatastoreSession containing the datastore and session
ID.
- Search the available datastore with the different session ID (oldest
in queue). If found, returns DKDatastoreSession containing the datastore
and that different session ID.
The application should call DKDatastoreSession getDatastore()
to obtain the dkDatastore and getId() to check the session ID.
virtual DKDatastoreSession* getConnection(const char* userId, const char* passwd, long aSessionId);
- returnConnection
- Returns a connected datastore with no session Id to the pool.
virtual void returnConnection(dkDatastore* ds);
- returnConnection
- Returns a connected datastore with session Id to the pool.
virtual void returnConnection(DKDatastoreSession* aDsSession);
- removeConnection
- Removes a datastore with no session ID from the pool, this is
so that the application can remove the bad datastore from the pool.
virtual void removeConnection(dkDatastore* ds);
- removeConnection
- Removes a datastore with session ID from the pool, this is so
that the application can remove the bad datastore from pool.
virtual void removeConnection(DKDatastoreSession* aDsSession);
- initConnections
- Initialize number of connections and store them in the pool.
This is only for the datastore with no session Id.
virtual void initConnections(const char* userId, const char* passwd, int initSize);
- clearConnections
- Clears this object instance including all the data that has
been set and the connections in the free pool. If any connection is
in use, it will throw an exception.
virtual void clearConnections();
- datastoreType
- Gets the datastore type for this datastore pool objects A instance
of DKDatastorePool can only handle one datastore type.
virtual DKString datastoreType() const;
- setValidate
- Sets the validate flag. When this flag is true, the available
datastore in the free pool will be validated again with the database
connection before returning to the caller of getConnection methods.
This slows down system performance. The purpose of this method is
to check if the DB2 server is down or running.
virtual void setValidate(DKBoolean aValidate);
- getValidate
- Gets the validate flag. If the validate flag is true, it will
validate the connection to the datastore whenever the getConnection()
is called.
virtual DKBoolean getValidate();