1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java Wed Sep 24 22:53:30 2014 +0200
1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java Thu Sep 25 17:50:40 2014 +0200
1.3 @@ -17,6 +17,8 @@
1.4 */
1.5 package info.globalcode.sql.dk;
1.6
1.7 +import static info.globalcode.sql.dk.jmx.ConnectionManagement.incrementCounter;
1.8 +import static info.globalcode.sql.dk.jmx.ConnectionManagement.resetCounter;
1.9 import info.globalcode.sql.dk.batch.Batch;
1.10 import info.globalcode.sql.dk.batch.BatchException;
1.11 import info.globalcode.sql.dk.configuration.DatabaseDefinition;
1.12 @@ -24,6 +26,8 @@
1.13 import info.globalcode.sql.dk.configuration.Property;
1.14 import info.globalcode.sql.dk.formatting.ColumnsHeader;
1.15 import info.globalcode.sql.dk.formatting.Formatter;
1.16 +import info.globalcode.sql.dk.jmx.ConnectionManagement;
1.17 +import info.globalcode.sql.dk.jmx.ConnectionManagement.COUNTER;
1.18 import java.sql.Connection;
1.19 import java.sql.DriverManager;
1.20 import java.sql.PreparedStatement;
1.21 @@ -50,10 +54,23 @@
1.22 private final DatabaseDefinition databaseDefinition;
1.23 private final Connection connection;
1.24 private final Properties properties;
1.25 + /**
1.26 + * Could be null = JMX is disabled → must check, see functions in
1.27 + * {@linkplain ConnectionManagement}
1.28 + */
1.29 + private final ConnectionManagement connectionMBean;
1.30
1.31 - public DatabaseConnection(DatabaseDefinition databaseDefinition, Properties properties) throws SQLException {
1.32 + /**
1.33 + *
1.34 + * @param databaseDefinition DB url, name, password etc.
1.35 + * @param properties additional properties from CLI
1.36 + * @param connectionMBean JMX management bean | null = disabled JMX reporting
1.37 + * @throws SQLException
1.38 + */
1.39 + public DatabaseConnection(DatabaseDefinition databaseDefinition, Properties properties, ConnectionManagement connectionMBean) throws SQLException {
1.40 this.databaseDefinition = databaseDefinition;
1.41 this.properties = properties;
1.42 + this.connectionMBean = connectionMBean;
1.43
1.44 if (properties.hasProperty(JDBC_PROPERTY_PASSWORD)) {
1.45 log.log(Level.WARNING, "Passing DB password as CLI parameter is insecure!");
1.46 @@ -97,6 +114,9 @@
1.47 }
1.48
1.49 private void processCommand(SQLCommand sqlCommand, Formatter formatter) throws SQLException {
1.50 + incrementCounter(connectionMBean, COUNTER.COMMAND);
1.51 + resetCounter(connectionMBean, COUNTER.RECORD_CURRENT);
1.52 +
1.53 try (PreparedStatement ps = sqlCommand.prepareStatement(connection)) {
1.54 log.log(Level.FINE, "Statement prepared");
1.55 sqlCommand.parametrize(ps);
1.56 @@ -135,6 +155,9 @@
1.57 int columnCount = rs.getMetaData().getColumnCount();
1.58
1.59 while (rs.next()) {
1.60 + incrementCounter(connectionMBean, COUNTER.RECORD_CURRENT);
1.61 + incrementCounter(connectionMBean, COUNTER.RECORD_TOTAL);
1.62 +
1.63 formatter.writeStartRow();
1.64
1.65 for (int i = 1; i <= columnCount; i++) {