Revision: 6715
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=6715&view=rev
Author: gerdwagner
Date: 2012-11-14 21:49:37 +0000 (Wed, 14 Nov 2012)
Log Message:
-----------
Closing or reconnecting Sessions caused SQuirreL to hang when the JDBC driver's connection close method didn't return.
Now closing timeouts after 2 seconds.
Modified Paths:
--------------
trunk/sql12/doc/src/main/resources/changes.txt
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/sql/SQLConnection.java
Modified: trunk/sql12/doc/src/main/resources/changes.txt
===================================================================
--- trunk/sql12/doc/src/main/resources/changes.txt 2012-11-14 21:48:33 UTC (rev 6714)
+++ trunk/sql12/doc/src/main/resources/changes.txt 2012-11-14 21:49:37 UTC (rev 6715)
@@ -8,6 +8,9 @@
Enhancements:
+Closing or reconnecting Sessions caused SQuirreL to hang when the JDBC driver's connection close method didn't return.
+ Now closing timeouts after 2 seconds.
+
Function to detach/close a file while keeping its contents in the SQL editor. Accessible through Toolbar and tools pop up.
Hibernate Plugin:
Modified: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/sql/SQLConnection.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/sql/SQLConnection.java 2012-11-14 21:48:33 UTC (rev 6714)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/sql/SQLConnection.java 2012-11-14 21:49:37 UTC (rev 6715)
@@ -26,6 +26,7 @@
import java.sql.Statement;
import java.util.Calendar;
import java.util.Date;
+import java.util.concurrent.*;
import net.sourceforge.squirrel_sql.fw.dialects.DialectFactory;
import net.sourceforge.squirrel_sql.fw.dialects.DialectType;
@@ -87,41 +88,85 @@
*/
public void close() throws SQLException
{
- SQLException savedEx = null;
- if (_conn != null)
- {
- s_log.debug("Closing connection");
- try
- {
- if (!_conn.getAutoCommit())
- {
- if (_autoCommitOnClose)
- {
- _conn.commit();
- }
- else
- {
- _conn.rollback();
- }
- }
- }
- catch (SQLException ex)
- {
- savedEx = ex;
- }
- _conn.close();
- _conn = null;
- _timeClosed = Calendar.getInstance().getTime();
- if (savedEx != null)
- {
- s_log.debug("Connection close failed", savedEx);
- throw savedEx;
- }
- s_log.debug("Connection closed successfully");
- }
- }
+ ExecutorService executorService = Executors.newSingleThreadExecutor();
- /**
+ int timeoutSeconds = 2;
+ try
+ {
+ Runnable task = new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ _closeIntern();
+ }
+ };
+ Future<?> future = executorService.submit(task);
+
+ future.get(timeoutSeconds, TimeUnit.SECONDS);
+
+ }
+ catch (TimeoutException e)
+ {
+ String message =
+ "The database connection took longer than " + timeoutSeconds + " seconds to close. " +
+ "Maybe closing will succeed later but SQuirreL stops waiting to stay responsive for user interaction.";
+ s_log.error(message, e);
+ }
+ catch (Throwable e)
+ {
+ s_log.error("Error while closing connection", e);
+ }
+ finally
+ {
+ _conn = null;
+ }
+ }
+
+ private void _closeIntern()
+ {
+ try
+ {
+ SQLException savedEx = null;
+ if (_conn != null)
+ {
+ s_log.debug("Closing connection");
+ try
+ {
+ if (!_conn.getAutoCommit())
+ {
+ if (_autoCommitOnClose)
+ {
+ _conn.commit();
+ }
+ else
+ {
+ _conn.rollback();
+ }
+ }
+ }
+ catch (SQLException ex)
+ {
+ savedEx = ex;
+ }
+ _conn.close();
+ _conn = null;
+ _timeClosed = Calendar.getInstance().getTime();
+ if (savedEx != null)
+ {
+ s_log.debug("Connection close failed", savedEx);
+ throw savedEx;
+ }
+ s_log.debug("Connection closed successfully");
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
* @see net.sourceforge.squirrel_sql.fw.sql.ISQLConnection#commit()
*/
public void commit() throws SQLException
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|