Skip to content

Commit

Permalink
MONDRIAN: Fix for MONDRIAN-571, close SqlStatement objects in HighCar…
Browse files Browse the repository at this point in the history
…dSqlTupleReader that have empty results immediately

[git-p4: depot-paths = "//open/mondrian/": change = 12995]
  • Loading branch information
Will Gorman committed Aug 10, 2009
1 parent 5797fd3 commit aa7ca77
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/mondrian/rolap/HighCardSqlTupleReader.java
Expand Up @@ -112,6 +112,12 @@ protected void prepareTuples(
} else {
throw Util.newError(sqle, message);
}
} finally {
if (!moreRows) {
if (stmt != null) {
stmt.close();
}
}
}
}

Expand Down
38 changes: 38 additions & 0 deletions testsrc/main/mondrian/test/BasicQueryTest.java
Expand Up @@ -6821,6 +6821,44 @@ public String[] getReservedWords() {
return null;
}
}

/**
* This unit test would cause connection leaks without a fix for MONDRIAN-571.
* It would be better if there was a way to verify that no leaks occurred in
* the data source.
*/
public void testHighCardSqlTupleReaderLeakingConnections() {
assertQueryReturns(
"WITH MEMBER [Measures].[NegativeSales] AS '- [Measures].[Store Sales]' "
+ "MEMBER [Product].[SameName] AS 'Aggregate(Filter("
+ "[Product].[Product Name].members,([Measures].[Store Sales] > 0)))' "
+ "MEMBER [Measures].[SameName] AS "
+ "'([Measures].[Store Sales],[Product].[SameName])' "
+ "select {[Measures].[Store Sales], [Measures].[NegativeSales], "
+ "[Measures].[SameName]} ON COLUMNS, "
+ "[Store].[Store Country].members ON ROWS "
+ "from [Sales] "
+ "where [Time].[1997]",
"Axis #0:\n"
+ "{[Time].[1997]}\n"
+ "Axis #1:\n"
+ "{[Measures].[Store Sales]}\n"
+ "{[Measures].[NegativeSales]}\n"
+ "{[Measures].[SameName]}\n"
+ "Axis #2:\n"
+ "{[Store].[All Stores].[Canada]}\n"
+ "{[Store].[All Stores].[Mexico]}\n"
+ "{[Store].[All Stores].[USA]}\n"
+ "Row #0: \n"
+ "Row #0: \n"
+ "Row #0: \n"
+ "Row #1: \n"
+ "Row #1: \n"
+ "Row #1: \n"
+ "Row #2: 565,238.13\n"
+ "Row #2: -565,238.13\n"
+ "Row #2: 565,238.13\n");
}
}

// End BasicQueryTest.java

0 comments on commit aa7ca77

Please sign in to comment.