Using DataSources from com.intellij.persistence.database in Custom Plugin

I've been going round and round trying to get the LocalDataSource.getConnection(Project) method to not hang and give me a java.sql.Connection object.  No dice.  So, I spent quite a bit of time coming up with the following solution.

1.  Create a custom UrlClassLoader instance with the jars from the LocalDataSource.
2.  Retrieving the java.sql.Driver implementation from the new classloader
3.  Instantiating the Driver implementation instance directly (since DriverManager.getConnection() can't find the Driver class in the custom ClassLoader)
4.  Calling Driver.connect(String, Properties) directly.
5.  Continuing on with the rest of my logic.


Is there something I'm missing here?  Is it really that difficult to use the LocalDataSource to connect to the database?

4 comments
Comment actions Permalink

Hello Brad,

getConnection() method definitely should not hang if invoked properly otherwise it is a bug.
You should never instantiate Driver instances inside Idea JVM.
This pollutes permgen and there are lots of other problems like native code loaded twice or in-memory database instances that
you will have to consider.

getConnection() should not be called from event thread or under write/readAction.
Please post here a thread dump if it is still a problem.

Gregory Shrago


On 04.06.2010 21:59, Brad Handy wrote:

I've been going round and round trying to get the LocalDataSource.getConnection(Project) method to not hang and give me a java.sql.Connection object.  No dice.  So, I spent quite a bit of time coming up with the following solution.

>

1.  Create a custom UrlClassLoader instance with the jars from the LocalDataSource.
2.  Retrieving the java.sql.Driver implementation from the new classloader
3.  Instantiating the Driver implementation instance directly (since DriverManager.getConnection() can't find the Driver class in the custom ClassLoader)
4.  Calling Driver.connect(String, Properties) directly.
5.  Continuing on with the rest of my logic.

>
>

Is there something I'm missing here?  Is it really that difficult to use the LocalDataSource to connect to the database?

>

---
Original message URL: http://www.jetbrains.net/devnet/message/5264789#5264789


0
Comment actions Permalink

That was my error then.  I was calling it from code to generate an EditorNotificationPanel.  I believe this is called from the event thread.  Thanks.

0
Comment actions Permalink

Correction.  I just tried a Task.Backgroundable implementation for doing the work, and it is still hanging.  I've attached the thread dump.



Attachment(s):
plugin-thread-dump.txt.zip
0
Comment actions Permalink

This problem is fixed in 9.0.3.

As a temporary workaround before the next 9.0.3 EAP:
the event thread should not wait for the task so it may handle invokeLater calls.

On 08.06.2010 19:39, Brad Handy wrote:

Correction.  I just tried a Task.Backgroundable implementation for doing the work, and it is still hanging.  I've attached
the thread dump.

>

--- Original message URL: http://www.jetbrains.net/devnet/message/5265018#5265018


0

Please sign in to leave a comment.