[power-matchmaker] r2760 committed - This fixes 2 of Benjamin's bugs. The first fix is to properly quote co...

0 views
Skip to first unread message

power-ma...@googlecode.com

unread,
Jan 21, 2011, 11:37:19 AM1/21/11
to matchmake...@googlegroups.com
Revision: 2760
Author: ThomasObrien95
Date: Fri Jan 21 08:36:41 2011
Log: This fixes 2 of Benjamin's bugs. The first fix is to properly quote
column names so spaces does not prevent DQguru from letting users create
munge processes. The second fix is a safe guard to close connections left
open as the first error was causing a connection leak.
http://code.google.com/p/power-matchmaker/source/detail?r=2760

Modified:
/branches/0.9.7/src/ca/sqlpower/matchmaker/munge/SQLInputStep.java

=======================================
--- /branches/0.9.7/src/ca/sqlpower/matchmaker/munge/SQLInputStep.java Wed
Jan 20 13:09:10 2010
+++ /branches/0.9.7/src/ca/sqlpower/matchmaker/munge/SQLInputStep.java Fri
Jan 21 08:36:41 2011
@@ -171,52 +171,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