InetSoft Technology: Database Connection Pooling

InetSoft's query engine uses connection pooling for enhanced database performance. The default size of the pool is five connections. For enterprise level deployment, the number of connections can be increased to a more appropriate size by setting the property jdbc.connection.pool.size in sree.properties.

jdbc.connection.pool.size=50 

Alternatively, an application can supply its own database connection pooling mechanism by implementing the ConnectionPool interface.

getConnection()

This method is called whenever a new connection is needed by the query engine. The pool should return the next available connection. If there are no more connections in the pool, this method should block until a connection is made available. The method syntax is as below

getConnection(XDataSource xds, Principal user); 

The parameter 'xds' denotes the jdbc data source. Parameter 'user' is a Principal object that identifies the user for whom the connection is being retrieved.

releaseConnection()  

This method is called by the query engine after a connection is no longer needed. This method should be coordinated with the getConnection() method so that if there is a getConnection() pending, this method will notify the waiting thread.

data discovery example

Report Tool Demo Register

Read more about InetSoft's in-memory database technology to learn how it works and what its advantages are over a pure in-memory solution.

Example: Database Connection Pool

The following is a simple connection pool implementation. It creates ten connections at startup and manages the pool using a Stack.

import java.sql.*;
import java.util.*;
import java.security.Principal;
import inetsoft.uql.*;
import inetsoft.uql.jdbc.*;
 
public class SimpleConnectionPool implements ConnectionPool {
public SimpleConnectionPool() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(ClassNotFoundException classx) {
}
 
String url = "jdbc:odbc:dxExample";
connections = new Stack();
 
for(int i = 0; i < size; i++) {
try {
Connection connection =
DriverManager.getConnection(url, "", "");
connections.push(connection);
} catch(SQLException sqlx) {
}
}
}
 
public Connection getConnection(XDataSource xds, Principal user) {
Connection conn = null;
if(xds.getName().equals("Order")) {
synchronized(connections) {
while(connections.empty()) {
try {
connections.wait();
} catch(InterruptedException interruptedx) {
}
}
 
conn = (Connection) connections.pop();
}
}
return conn;
}
public void releaseConnection(XDataSource xds, Connection conn) {
synchronized(connections) {
connections.push(conn);
connections.notifyAll();
}
}
 
Stack connections;
int size = 10;
}

Setting the Connection Pool

There are two methods for setting the connection pool. The first method is to set the property jdbc.connection.pool in sree.properties.

jdbc.connection.pool=SimpleConnectionPool 

The second method is to programmatically call JDBC.setConnectionPool().

ConnectionPool pool = new SimpleConnectionPool(); 
inetsoft.uql.jdbc.JDBCHandler.setConnectionPool(pool); 

Note that it is important to call the close() function of a JDBCTableNode after using it, because if the system is busy it may cause a deadlock in the connection pool.