Skip to content

Commit

Permalink
MONDRIAN: Fix MONDRIAN-738, "Statements not being closed". Now Statem…
Browse files Browse the repository at this point in the history
…ents are

    closed explicitly, after ResultSets and before Connections.

[git-p4: depot-paths = "//open/mondrian-release/3.2/": change = 13617]
  • Loading branch information
julianhyde committed May 12, 2010
1 parent b424608 commit 995e31a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
14 changes: 14 additions & 0 deletions src/main/mondrian/rolap/SqlStatement.java
Expand Up @@ -216,15 +216,29 @@ public void close() {
haveSemaphore = false;
querySemaphore.leave();
}

// According to the JDBC spec, closing a statement automatically closes
// its result sets, and closing a connection automatically closes its
// statements. But let's be conservative and close everything
// explicitly.
Statement statement = null;
if (resultSet != null) {
try {
statement = resultSet.getStatement();
resultSet.close();
} catch (SQLException e) {
throw Util.newError(message + "; sql=[" + sql + "]");
} finally {
resultSet = null;
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
throw Util.newError(message + "; sql=[" + sql + "]");
}
}
if (jdbcConnection != null) {
try {
jdbcConnection.close();
Expand Down
38 changes: 26 additions & 12 deletions src/main/mondrian/spi/impl/MySqlDialect.java
Expand Up @@ -9,11 +9,8 @@
package mondrian.spi.impl;

import mondrian.olap.Util;
import mondrian.olap.MondrianDef;
import mondrian.util.Pair;

import java.util.List;
import java.util.Iterator;
import java.util.Map;
import java.sql.*;

Expand Down Expand Up @@ -48,6 +45,8 @@ protected boolean acceptsConnection(Connection connection) {
* Creates a MySqlDialect.
*
* @param connection Connection
*
* @throws SQLException on error
*/
public MySqlDialect(Connection connection) throws SQLException {
super(connection);
Expand Down Expand Up @@ -136,21 +135,31 @@ protected boolean deduceSupportsSelectNotInGroupBy(Connection connection)
private String getCurrentSqlMode(Connection connection)
throws SQLException
{
return getSqlMode(connection, true);
return getSqlMode(connection, Scope.SESSION);
}

private String getSqlMode(Connection connection, boolean session)
private String getSqlMode(Connection connection, Scope scope)
throws SQLException
{
String scope = session ? "SESSION" : "GLOBAL";
String sqlmode = null;
Statement s = connection.createStatement();
if (s.execute("SELECT @@" + scope + ".sql_mode")) {
ResultSet rs = s.getResultSet();
rs.next();
sqlmode = rs.getString(1);
Statement s = null;
try {
s = connection.createStatement();
if (s.execute("SELECT @@" + scope + ".sql_mode")) {
ResultSet rs = s.getResultSet();
if (rs.next()) {
sqlmode = rs.getString(1);
}
}
} finally {
if (s != null) {
try {
s.close();
} catch (SQLException e) {
// ignore
}
}
}
s.close();
return sqlmode;
}

Expand Down Expand Up @@ -215,6 +224,11 @@ public boolean requiresOrderByAlias() {
public boolean supportsMultiValueInExpr() {
return true;
}

private enum Scope {
SESSION,
GLOBAL
}
}

// End MySqlDialect.java

0 comments on commit 995e31a

Please sign in to comment.