Bug 113029 - Insert JDBC code in Java files from existing DB connections
Summary: Insert JDBC code in Java files from existing DB connections
Status: NEW
Alias: None
Product: Data Tools
Classification: Tools
Component: SQLDevTools (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: future   Edit
Assignee: Brian Fitzpatrick CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2005-10-18 22:16 EDT by Lawrence Mandel CLA
Modified: 2013-08-01 14:44 EDT (History)
5 users (show)

See Also:


Attachments
screen shot (21.32 KB, image/jpeg)
2010-02-23 18:22 EST, Qiangsheng Wang CLA
no flags Details
screen shot (17.96 KB, image/jpeg)
2010-02-23 18:22 EST, Qiangsheng Wang CLA
no flags Details
The project for the jdbc compeletion. (12.84 KB, application/zip)
2010-03-03 22:23 EST, Qiangsheng Wang CLA
no flags Details
New project with correct package name. (12.84 KB, application/zip)
2010-03-04 17:01 EST, Qiangsheng Wang CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lawrence Mandel CLA 2005-10-18 22:16:27 EDT
The data tools currently allow a user to work with databases but do not help
Java developers integrate DB connections in their code. I'd like to see an
option (possibly on the context menu) that allows users to insert JDBC
connections into their Java code for databases which have already been defined. 

Taking this further, it would also be useful to insert a statement that allows a
user to get the values from an SQL statement. This should probably be linked
with the SQL editor.
Comment 1 Der Ping Chou CLA 2006-05-11 14:24:33 EDT
Great idea, but this enhancement request does not fit into the scope of WTP project.
Comment 2 Lawrence Mandel CLA 2006-05-11 14:31:03 EDT
Agreed. I'm retargetting to DTP.
Comment 3 Lawrence Mandel CLA 2006-05-11 14:32:36 EDT
I opened this bug against WTP but with the formation of the DTP project I'm reassigning to DTP.
Comment 4 John Graham CLA 2006-06-13 13:26:40 EDT
Actually, I had a discussion with John D at EclipseCon about this sort of thing. Interested in how we would integrate with the Java editor: use a code template or something like that?
Comment 5 Hui Cao CLA 2006-11-20 09:46:11 EST
Hey John, I'm afraid we won't be able to do this in 1.0.
Comment 6 Lawrence Mandel CLA 2007-09-06 16:48:41 EDT
Do you guys (DTP guys) have any pointers you can give here on where to retrieve the DB connection info from (API would be nice) so as to help anyone who wants to work on this enhancement? I think a code snippet or content assist may be the way to go to integrate this in the Java editor. Thanks.
Comment 7 Hui Cao CLA 2007-09-09 22:09:55 EDT
I think you should check out org.eclipse.datatools.connectivity.ProfileManager, which defines API such as: getProfiles, getProfilesByCategory, etc.
Comment 8 Qiangsheng Wang CLA 2010-02-14 18:49:30 EST
Has anyone worked on this? If not, I'd like to contribute this enhancement. I had a prototype on the hand already, and just need a little bit refine for several days.

Let me know.
Comment 9 Linda Chan CLA 2010-02-23 14:53:47 EST
(In reply to comment #8)

Hi,

There is no active work done for this thus far.  Can you please post more description regarding the prototype that you have; how it works, etc.?  And what sort of info that you might need? 
Thanks for your contribution.

Linda
Comment 10 Qiangsheng Wang CLA 2010-02-23 18:21:32 EST
(In reply to comment #9)

I'm using the javaCompletionProposalComputer extension point for hooking the proposal into JDT.

If user input the data source name and press ctrl-space in Java Editor, it'll get the matched data source lists. User the data source will generating the JDBC connection string in the code.

See the attached pic.

My questions are:
1. The jdbc string is vendor dependent (am i right?). If yes, I need get this form the profile (or?). Does DTP have this already? Or guessing at the UI side?

2. I'm using a separate project at the moment. Where to put the code?

Cheers
Qiangsheng
Comment 11 Qiangsheng Wang CLA 2010-02-23 18:22:18 EST
Created attachment 160013 [details]
screen shot
Comment 12 Qiangsheng Wang CLA 2010-02-23 18:22:39 EST
Created attachment 160014 [details]
screen shot
Comment 13 Lawrence Mandel CLA 2010-02-23 22:26:00 EST
It's nice to see some traction on this old request. Thanks for stepping up Qiangsheng.
Comment 14 Qiangsheng Wang CLA 2010-03-03 22:21:58 EST
I attached the completed code as a separate project. 

I'm using the IJDBCConnectionProfileConstants.URL_PROP_ID property to retrieve the URL. I'm not an expert of DTP, so if this is not correct then please let me know.
Comment 15 Qiangsheng Wang CLA 2010-03-03 22:23:50 EST
Created attachment 160886 [details]
The project for the jdbc compeletion.
Comment 16 Brian Fitzpatrick CLA 2010-03-04 12:08:49 EST
Hi there... Just one comment about the attached project. One of the package names is incorrect, so you end up with "org.eclipse.datatools.sqltools.internal.*" and "org.eclipse.datatools.sqltools.inertnal.*".

Beyond that, can you provide a series of steps to try out the code?
Comment 17 Qiangsheng Wang CLA 2010-03-04 17:00:56 EST
Yes, apparently my figure was out of control when typing "internal".
Attached the new project.

Well in term of using it, I assume you're using the source project.
1. Import the attached project.
2. Run a new run-time configuration. Make sure you include the new plugin.
3. Create one/several data base connections via DTP data source explorer view.
4. Create a java project, create java files in it.
5. Open a java file, typing the begging letters of a data source name. 
6. Press ctrl-space. You should get the matching data base names in the list
7. Select on of the data base name, you'll get the URL connection string.

You can see my previous screen shot.
Comment 18 Qiangsheng Wang CLA 2010-03-04 17:01:46 EST
Created attachment 161044 [details]
New project with correct package name.
Comment 19 Qiangsheng Wang CLA 2010-03-04 17:16:34 EST
BTW the connections.txt file in the project is a temp file. We don't really need it.
Comment 20 Brian Fitzpatrick CLA 2010-09-27 17:11:50 EDT
Hey Lawrence... Are you already a committer at Eclipse? I think we should be able to work this functionality into DTP for the 1.9 release (with Eclipse Indigo). But we'll have to go through an IP review because of the size of the contribution. It's not huge, but is still going to take some time.
Comment 21 Lawrence Mandel CLA 2010-09-27 17:26:56 EDT
Hi Brian. I'm a former WTP committer. As you can see from the bug history, this request is 5 years old. I'm not currently in a position to help integrate the contribution but I would be happy to test it once it's included in a build.
Comment 22 Brian Fitzpatrick CLA 2010-09-27 17:35:11 EDT
Hi Lawrence - that's awesome. Testing help is always appreciated. :) 

The contribution is small (less than 11k of code) - I just want to make sure that IP-wise we're ok to include it in our Indigo release. 

I think this contribution would be a good start at least. Right now if you use it and type the name of a connection profile (without spaces), you will see a list of profiles (if you have more than one) - select one and it will insert the JDBC URL into the text.

We could do other things such as adding your typical code block:

    // From connection profile: NewSQLite
    Class.forName("org.sqlite.JDBC");
    Connection conn =
      DriverManager.getConnection("jdbc:sqlite:/home/bfitzpat/DBs/MySQLiteDB");
      
Which I think is more in the spirit of your original request.
Comment 23 Qiangsheng Wang CLA 2010-10-12 06:14:55 EDT
The new suggested code looks better than mine. :)