TIBCO BusinessEvents - Database Concepts (DBConcepts) - Usage of catalog functions Database.setCurrentConnection() and Database.unsetConnection()

TIBCO BusinessEvents - Database Concepts (DBConcepts) - Usage of catalog functions Database.setCurrentConnection() and Database.unsetConnection()

book

Article ID: KB0073504

calendar_today

Updated On:

Products

TIBCO BusinessEvents Enterprise Edition

Description

For TIBCO BusinessEvents applications with DBConcepts enabled, the number of available database connections is configured in CDD file (Cluster area -> Database Concepts).

For each database operation the catalog function Database.setCurrentConnection() returns a connection of the pool to the worker thread.
That connection marked as in use until Database.unsetConnection() has been called. That catalog function releases the database connection.


It is required to release the connection to avoid that all connections are in use. In that case an error reported.
"java.lang.RuntimeException: Connections are unavailable, increase the max pool size or wait timeout Database may be disconnected"


 

Issue/Introduction

TIBCO BusinessEvents - Database Concepts (DBConcepts) - Usage of catalog functions Database.setCurrentConnection() and Database.unsetConnection()

Environment

All Operating Systems

Resolution

Each time when you execute Database.setCurrentConnection() the worker thread requests a new connection from pool. If the existing newer connection is not released before the old connection then the old connection remains open and cannot be closed.
That behavior is related to the implementation - one connection per DB per thread.

To avoid scenario where you run out of DB Connections you can use the approach highlighted below.

To manage the connections, create a wrapper RuleFunction and call Database.setCurrentConnection() and Database.unsetConnection() in that RuleFunction only.  

e.g.,
try  {
    Database.setCurrentConnection("/SharedResources/JDBCConnection");
    
    // call your RuleFunctions with database operations 
    Rulefunctions.DBQuery(cp1,cp2);
    Rulefunctions.DBUpdate1(cp1,cp2);
    Rulefunctions.DBUpdate2(cp3,cp4)

}
catch(Exception e) 
{
    // Error handling
    System.debugOut("### Error:" + e@stackTrace);
}
        
finally 
{
    Database.unsetConnection();    
}

 

Additional Information

https://docs.tibco.com/pub/businessevents-enterprise/6.1.0/doc/html/Default.htm#Data-Modeling-Developers/RDBMS-Catalog-Functions.htm?TocPath=Data%2520Modelling%2520Developers%2520Guide%257CRDBMS%2520Catalog%2520Functions%257C_____0

https://docs.tibco.com/pub/businessevents-enterprise/6.1.0/doc/html/Default.htm#Data-Modeling-Developers/The-setCurrentConnection-and-unsetConnection-Functions.htm?TocPath=Data%2520Modelling%2520Developers%2520Guide%257CRDBMS%2520Catalog%2520Functions%257C_____1