[power-matchmaker] r2758 committed - This is 2 bugs fixed in one. ...

0 views
Skip to first unread message

power-ma...@googlecode.com

unread,
Jan 20, 2011, 12:36:59 PM1/20/11
to matchmake...@googlegroups.com
Revision: 2758
Author: ThomasObrien95
Date: Thu Jan 20 09:35:55 2011
Log: This is 2 bugs fixed in one.
The first bug is we were not quoting column names when selecting columns in
a table on refresh. Without quotes around the column name columns in spaces
in their names on sql server 2008 will cause the query to fail.
The second bug is if the query failed on an exception the connection would
never be closed causing a connection leak. The connection, statement and
result set are now all properly closed if necessary at the end of the
method call.
http://code.google.com/p/power-matchmaker/source/detail?r=2758

Modified:
/trunk/src/ca/sqlpower/matchmaker/munge/SQLInputStep.java

=======================================
--- /trunk/src/ca/sqlpower/matchmaker/munge/SQLInputStep.java Fri Oct 22
07:25:31 2010
+++ /trunk/src/ca/sqlpower/matchmaker/munge/SQLInputStep.java Thu Jan 20
09:35:55 2011
@@ -183,52 +183,71 @@
throw new RuntimeException("The input table has no parent database
defined.");
}

- con = db.getConnection();
- if (con == null) {
- throw new RuntimeException("Could not obtain a connection to the
input table's database");
- }
- con.setAutoCommit(false);
-
- Statement stmt =
con.createStatement(ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_UPDATABLE);
-
- // Some platforms (definitely PostgreSQL) require a non-zero
fetch size to enable streaming
- stmt.setFetchSize(100);
-
- StringBuilder sql = new StringBuilder();
- sql.append("SELECT");
- boolean first = true;
- for (SQLColumn c : table.getColumns()) {
- if (!first) sql.append(",");
- sql.append("\n ").append(c.getName());
- first = false;
- }
- sql.append("\nFROM ").append(DDLUtils.toQualifiedName(table));
- if (getProject().getFilter() != null &&
getProject().getFilter().trim().length() > 0) {
- sql.append("\nWHERE " + getProject().getFilter());
- }
-
- if (isPreviewMode()) {
- stmt.setMaxRows(MungePreviewer.MAX_ROWS_PREVIEWED);
- }
- logger.debug("Attempting to execute input query: " + sql);
- ResultSet tempRs = stmt.executeQuery(sql.toString());
-
- logger.debug("ResultSet fetch size is: " + tempRs.getFetchSize());
- if (tempRs.getFetchSize() < DEFAULT_FETCH_SIZE) {
- tempRs.setFetchSize(DEFAULT_FETCH_SIZE);
- }
-
- if (isPreviewMode()) {
- previewRS.populate(tempRs);
- previewRS.beforeFirst();
- rs = previewRS;
- tempRs.close();
- stmt.close();
- } else if (!nullOutRS) {
- rs = tempRs;
- }
- if (isPreviewMode() || nullOutRS) {
- con.close();
+ Statement stmt = null;
+ ResultSet tempRs = null;
+ try {
+ con = db.getConnection();
+ if (con == null) {
+ throw new RuntimeException("Could not obtain a connection to the
input table's database");
+ }
+ con.setAutoCommit(false);
+
+ stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_UPDATABLE);
+
+ // Some platforms (definitely PostgreSQL) require a non-zero fetch
size to enable streaming
+ stmt.setFetchSize(100);
+
+ StringBuilder sql = new StringBuilder();
+ sql.append("SELECT");
+ boolean first = true;
+ for (SQLColumn c : table.getColumns()) {
+ if (!first) sql.append(",");
+ sql.append("\n ").append("\"").append(c.getName()).append("\"");
+ first = false;
+ }
+ sql.append("\nFROM ").append(DDLUtils.toQualifiedName(table));
+ if (getProject().getFilter() != null &&
getProject().getFilter().trim().length() > 0) {
+ sql.append("\nWHERE " + getProject().getFilter());
+ }
+
+ if (isPreviewMode()) {
+ stmt.setMaxRows(MungePreviewer.MAX_ROWS_PREVIEWED);
+ }
+ logger.debug("Attempting to execute input query: " + sql);
+ tempRs = stmt.executeQuery(sql.toString());
+
+ logger.debug("ResultSet fetch size is: " + tempRs.getFetchSize());
+ if (tempRs.getFetchSize() < DEFAULT_FETCH_SIZE) {
+ tempRs.setFetchSize(DEFAULT_FETCH_SIZE);
+ }
+
+ if (isPreviewMode()) {
+ previewRS.populate(tempRs);
+ previewRS.beforeFirst();
+ rs = previewRS;
+ } else if (!nullOutRS) {
+ rs = tempRs;
+ }
+ } finally {
+ if (isPreviewMode()) {
+ if (tempRs != null) {
+ try {
+ tempRs.close();
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+ if (stmt != null) {
+ try {
+ stmt.close();
+ } catch (Exception e) {
+ logger.error(e);
+ }
+ }
+ con.close();
+ } else if (nullOutRS) {
+ con.close();
+ }
}
}
}

Reply all
Reply to author
Forward
0 new messages