The drivers register a single Statement Pool Monitor for each statement pool with the default MBean server of the JVM. The registered MBean name has the following form, where
monitor_name is the string returned by the ExtStatementPoolMonitor.getName() method:
To return information about the statement pool, retrieve the names of all MBeans that are registered with the com.ddtek.jdbc domain and search through the list for the StatementPoolMonitor type attribute. The following code shows how to use the standard JMX API calls to return the state of all active statement pools in the JVM:
System.out.println("Not enough arguments supplied");
System.out.println("Usage: " + "ShowStatementPoolInfo hostname port");
String hostname = args[0];
JMXServiceURL url = null;
JMXConnector connector = null;
MBeanServerConnection server = null;
url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" +
hostname +":" + port + "/jmxrmi");
connector = JMXConnectorFactory.connect(url);
server = connector.getMBeanServerConnection();
System.out.println("Connected to JMX MBean Server at " +
args[0] + ":" + args[1]);
// Get the MBeans that have been registered with the
// com.ddtek.jdbc domain.
ObjectName ddBMeans = new ObjectName("com.ddtek.jdbc:*");
Set
<ObjectName> mbeans = server.queryNames(ddBMeans, null);
// For each statement pool monitor MBean, display statistics and
// contents of the statement pool monitored by that MBean
for (ObjectName name: mbeans) {
if (name.getDomain().equals("com.ddtek.jdbc") &&
name.getKeyProperty("type")
.equals("StatementPoolMonitor")) {
System.out.println("Statement Pool - " +
server.getAttribute(name, "Name"));
System.out.println("Max Size: " +
server.getAttribute(name, "MaxSize"));
System.out.println("Current Size: " +
server.getAttribute(name, "CurrentSize"));
System.out.println("Hit Count: " +
server.getAttribute(name, "HitCount"));
System.out.println("Miss Count: " +
server.getAttribute(name, "MissCount"));
System.out.println("Statements:");
Object[] params = new Object[3];
params[0] = new Integer(-1);
params[1] = new Integer(-1);
params[2] = new Integer(-1);
String[] types = new String[3];
ArrayList<
String>statements = (ArrayList<
String>)
for (String stmt : statements) {
int index = stmt.indexOf(";");
System.out.println(" " + stmt.substring(0, index));
catch (Throwable except) {
System.out.println("ERROR: " + except);
Using DataDirect-Specific Methods
The ExtConnection.getStatementPoolMonitor() method returns an ExtStatementPoolMonitor object for the statement pool associated with the connection. This method is provided by the ExtConnection interface in the com.ddtek.jdbc.extensions package. If the connection does not have a statement pool, the method returns null.
Once you have an ExtStatementPoolMonitor object, you can use the poolEntries() method of the ExtStatementPoolMonitorMBean interface implemented by the ExtStatementPoolMonitor to return a list of statements in the statement pool as an array.
Table 10-1 lists the parameters and the valid values supported by the poolEntries() method.
SQL_TEXT=[
SQL_text];STATEMENT_TYPE=TYPE_PREPARED_STATEMENT|TYPE_CALLABLE_STATEMENT;
RESULTSET_TYPE=TYPE_FORWARD_ONLY|TYPE_SCROLL_INSENSITIVE|TYPE_SCROLL_SENSITIVE;
RESULTSET_CONCURRENCY=CONCUR_READ_ONLY|CONCUR_UPDATABLE;
AUTOGENERATEDKEYSREQUESTED=true|false;REQUESTEDKEYCOLUMNS=
comma-separated_list
where SQL_text is the SQL text of the statement and
comma-separated_list is a list of column names that will be returned as generated keys.
SQL_TEXT=[INSERT INTO emp(id, name) VALUES(99, ?)];
STATEMENT_TYPE=Prepared Statement;RESULTSET_TYPE=Forward Only;
RESULTSET_CONCURRENCY=Read Only;AUTOGENERATEDKEYSREQUESTED=false;
REQUESTEDKEYCOLUMNS=id,name
The following code shows how to return an ExtStatementPoolMonitor object using a connection and generate a list of statements in the statement pool associated with the connection.
PreparedStatement prepStmt = null;
// Create the connection and enable statement pooling
Class.forName("com.ddtek.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection(
"jdbc:datadirect:sqlserver://SMITH:1440;" +
"maxPooledStatements=10", "test", "test");
// Prepare a couple of statements
sql = "INSERT INTO employees (id, name) VALUES(?, ?)";
prepStmt = con.prepareStatement(sql);
sql = "SELECT name FROM employees WHERE id = ?";
prepStmt = con.prepareStatement(sql);
ExtStatementPoolMonitor monitor =
((ExtConnection) con).getStatementPoolMonitor();
System.out.println("Statement Pool - " + monitor.getName());
System.out.println("Max Size: " + monitor.getMaxSize());
System.out.println("Current Size: " + monitor.getCurrentSize());
System.out.println("Hit Count: " + monitor.getHitCount());
System.out.println("Miss Count: " + monitor.getMissCount());
System.out.println("Statements:");
ArrayList statements = monitor.poolEntries(-1, -1, -1);
Iterator itr = statements.iterator();
String entry = (String)itr.next();
System.out.println(entry);
System.out.println("ERROR: " + except);
catch (SQLException except) {}
In the previous code example, the PoolEntries() method returns all statements in the statement pool regardless of statement type, result set cursor type, and concurrency type by specifying the value
-1 for each parameter as shown in the following code:
We could have easily filtered the list of statements to return only prepared statements that have a forward-only result set with a concurrency type of updateable using the following code:
ExtStatementPoolMonitor.TYPE_PREPARED_STATEMENT,
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);