Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » DTP » Accessing table for MySQL database
Accessing table for MySQL database [message #51259] Sat, 08 November 2008 19:18 Go to next message
Eclipse UserFriend
Originally posted by: andi.hotz.adsl.li

Here is something I can't get my head around: I can configure my MySQL
database so that it shows up in the Data Source Explorer and I can
access the table(s).
If I want to check the structure of the table from some piece of code I
retrieve a Database object retrieve the schemas and grab the tables.
Since MySQL doesn't care about schemas I tried to grab the catalogs with
the same result. Here is the piece of code:

public List<String> getOwner(IConnectionProfile profile, String factoryID){
Vector<String> v = new Vector<String>();
if (factoryID==null){
factoryID="java.sql.Connection";
}
IConnection conn = profile.createConnection(factoryID);
JDBCDatabase database = new JDBCDatabase((Connection)
conn.getRawConnection());
...
EList l = database.getCatalogs();
for (Iterator iterator = l.iterator(); iterator.hasNext();) {
Catalog s = (Catalog) iterator.next();
...
}
return v;
}

Irrelevant of the fact that I use database.getCatalogs() or
database.getSchemas() the result is always an empty list.

Based on the fact that it is possible to retrieve the data I must miss
something. Or is there another way to gather the meta data of a table?

Hope someone can help me out

Andi
Re: Accessing table for MySQL database [message #51285 is a reply to message #51259] Mon, 10 November 2008 15:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: brianf.sybase.com

Hi Andi!

You are SOOO close. :)

Try something along these lines to get the managed database so you get it
populated correctly. This routine gets the Database object from the managed
connection that handles such things under the covers, which is what you're
actually seeing in the Data Source Explorer when you connect and expand.

Let me know if this works for you!
--Fitz

public Database getDatabaseForProfile (IConnectionProfile profile) {

IManagedConnection managedConnection =
((IConnectionProfile)profile).getManagedConnection(" org.eclipse.datatools.connectivity.sqm.core.connection.Conne ctionInfo ");//java.sql.Connection");

if (managedConnection != null)

{

try {

ConnectionInfo connectionInfo = (ConnectionInfo)
managedConnection.getConnection().getRawConnection();

if (connectionInfo != null) {

return connectionInfo.getSharedDatabase();

}

} catch (Exception e) {

e.printStackTrace();

}

}

return null;

}

"Andi Hotz" <andi.hotz@adsl.li> wrote in message
news:gf4om5$o0v$1@build.eclipse.org...
> Here is something I can't get my head around: I can configure my MySQL
> database so that it shows up in the Data Source Explorer and I can access
> the table(s).
> If I want to check the structure of the table from some piece of code I
> retrieve a Database object retrieve the schemas and grab the tables. Since
> MySQL doesn't care about schemas I tried to grab the catalogs with the
> same result. Here is the piece of code:
>
> public List<String> getOwner(IConnectionProfile profile, String
> factoryID){
> Vector<String> v = new Vector<String>();
> if (factoryID==null){
> factoryID="java.sql.Connection";
> }
> IConnection conn = profile.createConnection(factoryID);
> JDBCDatabase database = new JDBCDatabase((Connection)
> conn.getRawConnection());
> ...
> EList l = database.getCatalogs(); for (Iterator iterator = l.iterator();
> iterator.hasNext();) {
> Catalog s = (Catalog) iterator.next();
> ...
> }
> return v;
> }
>
> Irrelevant of the fact that I use database.getCatalogs() or
> database.getSchemas() the result is always an empty list.
>
> Based on the fact that it is possible to retrieve the data I must miss
> something. Or is there another way to gather the meta data of a table?
>
> Hope someone can help me out
>
> Andi
Re: Accessing table for MySQL database [message #51311 is a reply to message #51285] Mon, 10 November 2008 16:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: andi.hotz.adsl.li

Thanks Brian

It worked!

Thinking about alternatives I came across the following:
I want to create a wizard that can produce some SQL script. My approach
is to collect the data from DTP. Another approach would be to offer the
option in the popup menu of the Data Source Explorer on the table
besides "Generate DDL". How could I hook into this popup menu?

Brian Fitzpatrick wrote:
> Hi Andi!
>
> You are SOOO close. :)
>
> Try something along these lines to get the managed database so you get it
> populated correctly. This routine gets the Database object from the managed
> connection that handles such things under the covers, which is what you're
> actually seeing in the Data Source Explorer when you connect and expand.
>
> Let me know if this works for you!
> --Fitz
>
> public Database getDatabaseForProfile (IConnectionProfile profile) {
>
> IManagedConnection managedConnection =
> ((IConnectionProfile)profile).getManagedConnection(" org.eclipse.datatools.connectivity.sqm.core.connection.Conne ctionInfo ");//java.sql.Connection");
>
> if (managedConnection != null)
>
> {
>
> try {
>
> ConnectionInfo connectionInfo = (ConnectionInfo)
> managedConnection.getConnection().getRawConnection();
>
> if (connectionInfo != null) {
>
> return connectionInfo.getSharedDatabase();
>
> }
>
> } catch (Exception e) {
>
> e.printStackTrace();
>
> }
>
> }
>
> return null;
>
> }
Re: Accessing table for MySQL database [message #51339 is a reply to message #51311] Mon, 10 November 2008 17:56 Go to previous message
Eclipse UserFriend
Originally posted by: brianf.sybase.com

Hey Andi!

Glad that worked for you. :)

As for adding a menu item to the DSE, that's pretty easy. The Data Source
Explorer uses the Common Navigator Framework (CNF) from the Eclipse
Platform, which makes it easy to contribute new menus. I'm including some
possibilities below.

--Fitz

Create a new IObjectActionDelegate class and reference it in your plug-in
something like the following...

The class might look like:

package blah;

import ...;
public class MyAction implements IObjectActionDelegate {


private ISelection mStashedSelection = null;


/**

* Constructor for Action1.

*/

public MyAction() {

super();

}


/**

* @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)

*/

public void setActivePart(IAction action, IWorkbenchPart targetPart) {

}


/**

* @see IActionDelegate#run(IAction)

*/

public void run(IAction action) {

if (mStashedSelection != null && !mStashedSelection.isEmpty()) {

if (mStashedSelection instanceof IStructuredSelection) {

IStructuredSelection ssel = (IStructuredSelection) mStashedSelection;

if (ssel.getFirstElement() instanceof IConnectionProfile) {

//do something

}

}

}

}


public void selectionChanged(IAction action, ISelection selection) {

mStashedSelection = selection;

}

}

And then your extension point in your plugin.xml looks something like this:
<extension

point="org.eclipse.ui.popupMenus">

<objectContribution

objectClass="org.eclipse.datatools.connectivity.IConnectionProfile "

id="my.action.contribution">

<action

label="My Action Label"

class="my.action.class"

menubarPath="slot3"

enablesFor="1"

id="my.action.id">

</action>

</objectContribution>

</extension>

"Andi Hotz" <andi.hotz@adsl.li> wrote in message
news:gf9p0c$92s$1@build.eclipse.org...
> Thanks Brian
>
> It worked!
>
> Thinking about alternatives I came across the following:
> I want to create a wizard that can produce some SQL script. My approach is
> to collect the data from DTP. Another approach would be to offer the
> option in the popup menu of the Data Source Explorer on the table besides
> "Generate DDL". How could I hook into this popup menu?
>
> Brian Fitzpatrick wrote:
>> Hi Andi!
>>
>> You are SOOO close. :)
>>
>> Try something along these lines to get the managed database so you get it
>> populated correctly. This routine gets the Database object from the
>> managed connection that handles such things under the covers, which is
>> what you're actually seeing in the Data Source Explorer when you connect
>> and expand.
>>
>> Let me know if this works for you!
>> --Fitz
>>
>> public Database getDatabaseForProfile (IConnectionProfile profile) {
>>
>> IManagedConnection managedConnection =
>> ((IConnectionProfile)profile).getManagedConnection(" org.eclipse.datatools.connectivity.sqm.core.connection.Conne ctionInfo ");//java.sql.Connection");
>>
>> if (managedConnection != null)
>>
>> {
>>
>> try {
>>
>> ConnectionInfo connectionInfo = (ConnectionInfo)
>> managedConnection.getConnection().getRawConnection();
>>
>> if (connectionInfo != null) {
>>
>> return connectionInfo.getSharedDatabase();
>>
>> }
>>
>> } catch (Exception e) {
>>
>> e.printStackTrace();
>>
>> }
>>
>> }
>>
>> return null;
>>
>> }
Re: Accessing table for MySQL database [message #593749 is a reply to message #51259] Mon, 10 November 2008 15:17 Go to previous message
Brian Fitzpatrick is currently offline Brian FitzpatrickFriend
Messages: 500
Registered: July 2009
Senior Member
Hi Andi!

You are SOOO close. :)

Try something along these lines to get the managed database so you get it
populated correctly. This routine gets the Database object from the managed
connection that handles such things under the covers, which is what you're
actually seeing in the Data Source Explorer when you connect and expand.

Let me know if this works for you!
--Fitz

public Database getDatabaseForProfile (IConnectionProfile profile) {

IManagedConnection managedConnection =
((IConnectionProfile)profile).getManagedConnection(" org.eclipse.datatools.connectivity.sqm.core.connection.Conne ctionInfo ");//java.sql.Connection");

if (managedConnection != null)

{

try {

ConnectionInfo connectionInfo = (ConnectionInfo)
managedConnection.getConnection().getRawConnection();

if (connectionInfo != null) {

return connectionInfo.getSharedDatabase();

}

} catch (Exception e) {

e.printStackTrace();

}

}

return null;

}

"Andi Hotz" <andi.hotz@adsl.li> wrote in message
news:gf4om5$o0v$1@build.eclipse.org...
> Here is something I can't get my head around: I can configure my MySQL
> database so that it shows up in the Data Source Explorer and I can access
> the table(s).
> If I want to check the structure of the table from some piece of code I
> retrieve a Database object retrieve the schemas and grab the tables. Since
> MySQL doesn't care about schemas I tried to grab the catalogs with the
> same result. Here is the piece of code:
>
> public List<String> getOwner(IConnectionProfile profile, String
> factoryID){
> Vector<String> v = new Vector<String>();
> if (factoryID==null){
> factoryID="java.sql.Connection";
> }
> IConnection conn = profile.createConnection(factoryID);
> JDBCDatabase database = new JDBCDatabase((Connection)
> conn.getRawConnection());
> ...
> EList l = database.getCatalogs(); for (Iterator iterator = l.iterator();
> iterator.hasNext();) {
> Catalog s = (Catalog) iterator.next();
> ...
> }
> return v;
> }
>
> Irrelevant of the fact that I use database.getCatalogs() or
> database.getSchemas() the result is always an empty list.
>
> Based on the fact that it is possible to retrieve the data I must miss
> something. Or is there another way to gather the meta data of a table?
>
> Hope someone can help me out
>
> Andi
Re: Accessing table for MySQL database [message #593765 is a reply to message #51285] Mon, 10 November 2008 16:54 Go to previous message
Eclipse UserFriend
Originally posted by: andi.hotz.adsl.li

Thanks Brian

It worked!

Thinking about alternatives I came across the following:
I want to create a wizard that can produce some SQL script. My approach
is to collect the data from DTP. Another approach would be to offer the
option in the popup menu of the Data Source Explorer on the table
besides "Generate DDL". How could I hook into this popup menu?

Brian Fitzpatrick wrote:
> Hi Andi!
>
> You are SOOO close. :)
>
> Try something along these lines to get the managed database so you get it
> populated correctly. This routine gets the Database object from the managed
> connection that handles such things under the covers, which is what you're
> actually seeing in the Data Source Explorer when you connect and expand.
>
> Let me know if this works for you!
> --Fitz
>
> public Database getDatabaseForProfile (IConnectionProfile profile) {
>
> IManagedConnection managedConnection =
> ((IConnectionProfile)profile).getManagedConnection(" org.eclipse.datatools.connectivity.sqm.core.connection.Conne ctionInfo ");//java.sql.Connection");
>
> if (managedConnection != null)
>
> {
>
> try {
>
> ConnectionInfo connectionInfo = (ConnectionInfo)
> managedConnection.getConnection().getRawConnection();
>
> if (connectionInfo != null) {
>
> return connectionInfo.getSharedDatabase();
>
> }
>
> } catch (Exception e) {
>
> e.printStackTrace();
>
> }
>
> }
>
> return null;
>
> }
Re: Accessing table for MySQL database [message #593788 is a reply to message #51311] Mon, 10 November 2008 17:56 Go to previous message
Brian Fitzpatrick is currently offline Brian FitzpatrickFriend
Messages: 500
Registered: July 2009
Senior Member
Hey Andi!

Glad that worked for you. :)

As for adding a menu item to the DSE, that's pretty easy. The Data Source
Explorer uses the Common Navigator Framework (CNF) from the Eclipse
Platform, which makes it easy to contribute new menus. I'm including some
possibilities below.

--Fitz

Create a new IObjectActionDelegate class and reference it in your plug-in
something like the following...

The class might look like:

package blah;

import ...;
public class MyAction implements IObjectActionDelegate {


private ISelection mStashedSelection = null;


/**

* Constructor for Action1.

*/

public MyAction() {

super();

}


/**

* @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)

*/

public void setActivePart(IAction action, IWorkbenchPart targetPart) {

}


/**

* @see IActionDelegate#run(IAction)

*/

public void run(IAction action) {

if (mStashedSelection != null && !mStashedSelection.isEmpty()) {

if (mStashedSelection instanceof IStructuredSelection) {

IStructuredSelection ssel = (IStructuredSelection) mStashedSelection;

if (ssel.getFirstElement() instanceof IConnectionProfile) {

//do something

}

}

}

}


public void selectionChanged(IAction action, ISelection selection) {

mStashedSelection = selection;

}

}

And then your extension point in your plugin.xml looks something like this:
<extension

point="org.eclipse.ui.popupMenus">

<objectContribution

objectClass="org.eclipse.datatools.connectivity.IConnectionProfile "

id="my.action.contribution">

<action

label="My Action Label"

class="my.action.class"

menubarPath="slot3"

enablesFor="1"

id="my.action.id">

</action>

</objectContribution>

</extension>

"Andi Hotz" <andi.hotz@adsl.li> wrote in message
news:gf9p0c$92s$1@build.eclipse.org...
> Thanks Brian
>
> It worked!
>
> Thinking about alternatives I came across the following:
> I want to create a wizard that can produce some SQL script. My approach is
> to collect the data from DTP. Another approach would be to offer the
> option in the popup menu of the Data Source Explorer on the table besides
> "Generate DDL". How could I hook into this popup menu?
>
> Brian Fitzpatrick wrote:
>> Hi Andi!
>>
>> You are SOOO close. :)
>>
>> Try something along these lines to get the managed database so you get it
>> populated correctly. This routine gets the Database object from the
>> managed connection that handles such things under the covers, which is
>> what you're actually seeing in the Data Source Explorer when you connect
>> and expand.
>>
>> Let me know if this works for you!
>> --Fitz
>>
>> public Database getDatabaseForProfile (IConnectionProfile profile) {
>>
>> IManagedConnection managedConnection =
>> ((IConnectionProfile)profile).getManagedConnection(" org.eclipse.datatools.connectivity.sqm.core.connection.Conne ctionInfo ");//java.sql.Connection");
>>
>> if (managedConnection != null)
>>
>> {
>>
>> try {
>>
>> ConnectionInfo connectionInfo = (ConnectionInfo)
>> managedConnection.getConnection().getRawConnection();
>>
>> if (connectionInfo != null) {
>>
>> return connectionInfo.getSharedDatabase();
>>
>> }
>>
>> } catch (Exception e) {
>>
>> e.printStackTrace();
>>
>> }
>>
>> }
>>
>> return null;
>>
>> }
Previous Topic:Accessing table for MySQL database
Next Topic:Executing SQL statement
Goto Forum:
  


Current Time: Fri Mar 29 12:34:35 GMT 2024

Powered by FUDForum. Page generated in 0.04090 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top