Accessing table for MySQL database [message #51259] |
Sat, 08 November 2008 14:18  |
Eclipse User |
|
|
|
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 #51339 is a reply to message #51311] |
Mon, 10 November 2008 12:56  |
Eclipse User |
|
|
|
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 10:17  |
Eclipse User |
|
|
|
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 11:54  |
Eclipse User |
|
|
|
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 12:56  |
Eclipse User |
|
|
|
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;
>>
>> }
|
|
|
Powered by
FUDForum. Page generated in 0.05205 seconds