This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 71704 - DatabaseConnection.getJDBCConnection() should not call Connection.isClosed()
Summary: DatabaseConnection.getJDBCConnection() should not call Connection.isClosed()
Status: RESOLVED FIXED
Alias: None
Product: db
Classification: Unclassified
Component: Code (show other bugs)
Version: 5.x
Hardware: All All
: P3 blocker (vote)
Assignee: Andrei Badea
URL:
Keywords: API
Depends on:
Blocks:
 
Reported: 2006-01-21 16:57 UTC by Andrei Badea
Modified: 2006-04-09 20:01 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrei Badea 2006-01-21 16:57:02 UTC
The implementation of DatabaseConnection.getJDBCConnection() calls
java.sql.Connection.close(), which can possibly block due to thread
synchronization or network activity. It does so in order to return a null value
if the connection is closed.

However, this approach has several problems:

1. Connection.isClosed() is only guaranteed to return false if
Connection.close() method has been previously calleed. Therefore in order to be
reliable, the implementation of DC.getJDBCConnection() can only call
C.isClosed() after the connection has been closed (e.g., by invoking the
Disconnect action in the Database Explorer's UI). But then the implementation
doesn't need to call C.isClosed() at all, since the fact that the connection has
been closed is known (it is even displayed in the UI).

2. The Javadoc of DC.getJDBCConnection(), which states that a null value will be
returned if the connection is disconnected, suggests this method can be used to
find out the connections state. Imagine a combo box containing all connections
with a connected/disconnected icon next to each connection. The usage
DC.getJDBCConnection() to determine the icon could lead to an UI freeze.

There should be a DC.isConnected() method returning the state of the connection
as known by the Database Explorer. DC.getJDBCConnection() should return null iff
DC.isConnected() == true.
Comment 1 Andrei Badea 2006-01-21 22:15:45 UTC
Sorry, the first line of the description should be:

The implementation of DC.getJDCBConnection calls *java.sql.Connection.isClosed()*...
Comment 2 Andrei Badea 2006-04-09 20:01:29 UTC
Fixed.

Checking in src/org/netbeans/api/db/explorer/DatabaseConnection.java;
/cvs/db/src/org/netbeans/api/db/explorer/DatabaseConnection.java,v  <-- 
DatabaseConnection.java
new revision: 1.5.2.1.2.2; previous revision: 1.5.2.1.2.1
done
Checking in src/org/netbeans/modules/db/explorer/DatabaseConnection.java;
/cvs/db/src/org/netbeans/modules/db/explorer/DatabaseConnection.java,v  <-- 
DatabaseConnection.java
new revision: 1.39.2.2.2.1; previous revision: 1.39.2.2
done