This Question is Answered

1 "correct" answer available (4 pts) 2 "helpful" answers available (2 pts)
14 Replies Last post: Jun 3, 2013 8:55 PM by Gregory Shrago  
Martin Zardecki Newbie 40 posts since
May 3, 2003
Currently Being Moderated

Oct 24, 2007 6:18 AM

Can I access and use the IDEA Data Sources?

Creating a plugin that will connect to a DB and do stuff (read data only).

 

Is there a way to use data sources defined in IntelliJ? Easier than writing my own data source and connection management stuff.

 

Thanks,

 

Happy

Guest
Currently Being Moderated
Oct 25, 2007 12:32 PM in response to: Martin Zardecki
Re: Can I access and use the IDEA Data Sources?

Hello Martin,

 

Creating a plugin that will connect to a DB and do stuff (read data

only).

 

Is there a way to use data sources defined in IntelliJ? Easier than

writing my own data source and connection management stuff.

 

Yes, you can use that. That functionality is part of the Java EE plugin,

so you'll need to depend on that plugin and reference javaee-openapi.jar

in your plugin. The starting point for this functionality is the DataSourceManager

class.

 

If you have more specific questions, feel free to ask them here.

 

--

Dmitry Jemerov

Development Lead

JetBrains, Inc.

http://www.jetbrains.com/

"Develop with Pleasure!"

 

 

 

James Cowan Newbie 4 posts since
Jul 30, 2003
Currently Being Moderated
Nov 15, 2007 6:58 PM in response to: Dmitry Jemerov
Re: Can I access and use the IDEA Data Sources?

I actually have a small plugin that I wrote for 6, and I used the DataSourceManager.getInstance(project) method, but it now returns null. I went through the latest API but there is no mention of any changes. There was a JIRA post but the user commented the following:

 

"Sorry, my mistake! I should make plugin extend com.intellij.javaee, and use version 2."

 

But that isn't very helpful. Is there something special that needs to be done to access the DataSourceManager instance?

Guest
Currently Being Moderated
Nov 15, 2007 7:04 PM in response to: James Cowan
Re: Can I access and use the IDEA Data Sources?

Hello James,

 

I actually have a small plugin that I wrote for 6, and I used the

DataSourceManager.getInstance(project) method, but it now returns

null. I went through the latest API but there is no mention of any

changes. There was a JIRA post but the user commented the following:

 

"Sorry, my mistake! I should make plugin extend com.intellij.javaee,

and use version 2."

 

But that isn't very helpful. Is there something special that needs to

be done to access the DataSourceManager instance?

 

Add to your plugin.xml.

 

--

Dmitry Jemerov

Development Lead

JetBrains, Inc.

http://www.jetbrains.com/

"Develop with Pleasure!"

 

 

 

James Cowan Newbie 4 posts since
Jul 30, 2003
Currently Being Moderated
Nov 15, 2007 11:05 PM in response to: Dmitry Jemerov
Re: Can I access and use the IDEA Data Sources?

Thanks Dmitry. It didn't seem to make a difference. I still get a null on the DataSourceManager.getInstance(project) method.

Guest
Currently Being Moderated
Nov 16, 2007 12:42 PM in response to: James Cowan
Re: Can I access and use the IDEA Data Sources?

Hello James,

 

I still get a null on the DataSourceManager.getInstance(project) method.

 

You probably added javaee-openapi.jar to your plugin dependencies. You should add it to the IDEA-JDK

instead. Also make sure the jar is not present any more in the plugin's lib directory in the sandbox.

 

Sascha

 

James Cowan Newbie 4 posts since
Jul 30, 2003
Currently Being Moderated
Nov 16, 2007 5:35 PM in response to: Sascha Weinreuter
Re: Can I access and use the IDEA Data Sources?

Thanks Sascha. That was it. When I was getting the null error, I thought that it was a dependency issue so I had added it in but I forgot to take it out.

 

Works like a charm now.

 

Thanks to both of you for your time.

pepe  Newbie 4 posts since
Dec 3, 2004
Currently Being Moderated
Jul 22, 2009 1:44 AM in response to: Sascha Weinreuter
Re: Can I access and use the IDEA Data Sources?

Hi, sorry for my english, I speak spanish.

I have a similar problem, with idea 8.1.3:

I have the DatasourceManager.class in the IDEA_HOME\plugins\DatabaseSupport\lib\database-openapi.jar file. If I add this jar to the plugin dependencies, I get the NPE. But If I remove this file from the dependencies, and adds it to the IDEA-JDK, I get:

 

java.lang.NoClassDefFoundError: com/intellij/javaee/dataSource/DataSourceManager

at com.intellij.openapi.samples.HelloWorldAction.actionPerformed(HelloWorldAction.java:33)
  at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:17)
  at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
....

 

Thanks.

Christopher Duwenkamp Newbie 1 posts since
Apr 5, 2011
Currently Being Moderated
Apr 5, 2011 11:37 AM in response to: Dmitry Jemerov
Re: Can I access and use the IDEA Data Sources?

Hi, thank you very much for the information, I could instanciate the DataSourceManager and get the DataSource I needed, but know I have a little Problem:

-The DataSource only has the method 'performJdbcOperation' to actualy perfom an datasource-action, which needs a ServerInstance as one paramter.

 

How can I aquire a ServerInstance to use for a query? -Or is there a simpler way to do this?

 

Thanks in advance,

Chris

Daniel Kec Newbie 6 posts since
May 29, 2013
Currently Being Moderated
May 29, 2013 10:56 PM in response to: Christopher Duwenkamp
Re: Can I access and use the IDEA Data Sources?

Hi i did it this way but it's awfull:

 

 

DataSourceManager dataSourceManager = DataSourceManager.getInstance(e.getProject());
DataSource dataSource = dataSourceManager.getDataSourceByName("BB21_TST"); 
Method getConnectionMethod = dataSource.getClass().getDeclaredMethod("getConnection", Project.class, ServerInstance.class);
getConnectionMethod.setAccessible(true);
Connection conn = (Connection) getConnectionMethod.invoke(dataSource, p, null);

 

 

Works on Idea 12

Denis Zhdanov Expert 1,620 posts since
Oct 20, 2007
Currently Being Moderated
May 30, 2013 1:47 PM in response to: Daniel Kec
Re: Can I access and use the IDEA Data Sources?

Hi Daniel,

 

Why do you want to get a Connection object instead of using DataSource.performJdbcOperation()?

 

Denis

Daniel Kec Newbie 6 posts since
May 29, 2013
Currently Being Moderated
May 30, 2013 1:57 PM in response to: Denis Zhdanov
Re: Can I access and use the IDEA Data Sources?

Because I'm using third party library which need's connection, i would make my own connection but I can't find LocalDataSource class any more, for obtaining driver and url.

Denis Zhdanov Expert 1,620 posts since
Oct 20, 2007
Currently Being Moderated
May 30, 2013 2:24 PM in response to: Daniel Kec
Re: Can I access and use the IDEA Data Sources?

Just checked that LocalDataSource class is available at the database-impl.jar under $IDEA_HOME/plugins/DatabaseSupport/lib

 

Denis

Daniel Kec Newbie 6 posts since
May 29, 2013
Currently Being Moderated
May 30, 2013 4:06 PM in response to: Denis Zhdanov
Re: Can I access and use the IDEA Data Sources?

That's it, i was missing database-impl.jar in my sdk, didn't noticed its not in database-openapi.jar.

Thank you

Gregory Shrago JetBrains 220 posts since
Mar 27, 2006
Currently Being Moderated
Jun 3, 2013 8:55 PM in response to: Daniel Kec
Re: Can I access and use the IDEA Data Sources?

In order to simplify this a

 

public DataSource.getConnection(Project)

 

method is added to IDEA 13 and IDEA 12.1.X codebases.

More Like This

  • Retrieving data ...