Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » DTP » How do I create a Connection Profile
How do I create a Connection Profile [message #53454] Thu, 12 March 2009 01:54 Go to next message
Mark Leone is currently offline Mark LeoneFriend
Messages: 123
Registered: July 2009
Senior Member
I'm trying to use DTP programmatically, but all the documentation I've
found just addresses how an administrative user sets up connections
through the eclipse UI. Can someone tell me where I might find something
that explains how to use the API. I'm not smart enough to figure out how
to use a barely-documented API of this complexity, but I'm sure I could
figure it out if I saw an example or an explanation of some sort.

Actually I think I just need to know how to create a connection profile.
I have code that creates a driver instance, and I know how to create a
connection if I hand it a connection profile; but I can't figure out how
to create a profile, presumably using the driver instance I created.

I execute the following code and get a NullPointerException where
indicated, which I take to indicate that I need to create a profile first.

ProfileManager pfm = ProfileManager.getInstance();
if (pfm == null){
System.err.println("No ProfileManager");
}
else{
IConnectionProfile[] profiles = pfm.getProfiles(); //NPE occurs here
for(IConnectionProfile profile : profiles){
System.out.println("Profile name: " + profile.getName());
System.out.println("Profile ID: " + profile.getInstanceID());
}
}

And here's how I create the driver instance:

mgr.createNewDriverInstance(templateStringID, templateName,
pathToConnectorJarFile);
Re: How do I create a Connection Profile [message #53482 is a reply to message #53454] Thu, 12 March 2009 19:54 Go to previous messageGo to next message
Mark Leone is currently offline Mark LeoneFriend
Messages: 123
Registered: July 2009
Senior Member
I've gotten further along on this, but I'm still stuck.

I loaded into my target environment the DTP plug-in which provides a MySQL
connectionProfile
(org.eclipse.datatools.enablement.mysql_1.0.2.v200810160130. jar), and all
it's dependencies. I see that in the plug-in's Plugin.XML it defines a
connection profile with cateory =
"org.eclipse.datatools.connectivity.db.category" and name = "MySQL".

But when I query the profile manager for the profile by name or by
category, an NPE is thrown. Below is the code I'm executing.

ProfileManager pfm = ProfileManager.getInstance();
if (pfm == null){
System.err.println("No ProfileManager");
}
else{
IConnectionProfile profileByName =
pfm.getProfileByName("MySQL"); // NPE thrown here
System.out.println("Profile (by name) name: " +
profileByName.getName());
System.out.println("Profile (by name) ID: " +
profileByName.getInstanceID());
}

alternatively, if I execute the following code to get the profiles by
category I also see an NPE thrown

IConnectionProfile[] profiles = pfm.getProfilesByCategory(
"org.eclipse.datatools.connectivity.db.category");// NPE thrown here
for(IConnectionProfile catProfile : profiles){
System.out.println("Profile (by Cat) name: " + catProfile.getName());
System.out.println("Profile (by Cat) ID: " +
catProfile.getInstanceID());
Re: How do I create a Connection Profile [message #53510 is a reply to message #53482] Fri, 13 March 2009 14:41 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: brianf.sybase.com

Hey Mark...

You're definitely along the right path.

When you talk about using the API... What are you including for dependencies
in the plug-in that's calling the API?

And what's the NPE that you're getting? That'll help me better diagnose
what's going on.

--Fitz

"Mark Leone" <midnightjava@verizon.net> wrote in message
news:20f0543b701bb5f2663988d6c0943224$1@www.eclipse.org...
> I've gotten further along on this, but I'm still stuck.
>
> I loaded into my target environment the DTP plug-in which provides a MySQL
> connectionProfile
> (org.eclipse.datatools.enablement.mysql_1.0.2.v200810160130. jar), and all
> it's dependencies. I see that in the plug-in's Plugin.XML it defines a
> connection profile with cateory =
> "org.eclipse.datatools.connectivity.db.category" and name = "MySQL".
>
> But when I query the profile manager for the profile by name or by
> category, an NPE is thrown. Below is the code I'm executing.
>
> ProfileManager pfm = ProfileManager.getInstance();
> if (pfm == null){
> System.err.println("No ProfileManager");
> }
> else{
> IConnectionProfile profileByName =
> pfm.getProfileByName("MySQL"); // NPE thrown here
> System.out.println("Profile (by name) name: " + profileByName.getName());
> System.out.println("Profile (by name) ID: " +
> profileByName.getInstanceID());
> }
>
> alternatively, if I execute the following code to get the profiles by
> category I also see an NPE thrown
>
> IConnectionProfile[] profiles = pfm.getProfilesByCategory(
> "org.eclipse.datatools.connectivity.db.category");// NPE thrown here
> for(IConnectionProfile catProfile : profiles){
> System.out.println("Profile (by Cat) name: " + catProfile.getName());
> System.out.println("Profile (by Cat) ID: " + catProfile.getInstanceID());
>
>
>
Re: How do I create a Connection Profile [message #53778 is a reply to message #53510] Fri, 13 March 2009 17:48 Go to previous message
Mark Leone is currently offline Mark LeoneFriend
Messages: 123
Registered: July 2009
Senior Member
Fitz,

Thanks for your response. I'm pursuing a different implementation vector
based on some guidance I just received from my tech lead. He wants me to
define the connection profile manually rather than try to retrieve one
declared in Plugin.XML. I have some code that does that, which I'll paste
below.

I'm able to verify that the properties are set properly on the connection
profile, but when I try to create a connection on the profile, I get an
NPE thrown in
org.eclipse.datatools.connectivity.internal.ConnectionProfil e. I looked at
the source code where the NPE is thrown, and it seems to be that I don't
have a connection factory set on it. I wasn't sure what value to pass for
the connection factory parameter, so that's probably where my problem is.

My code is below. I'm also registering a driver when the workbench starts
up. The code that does that is below.

DriverManager mgr = DriverManager.getInstance()
mgr.createNewDriverInstance( "org.eclipse.datatools.enablement.mysql.5_1.driverTemplate",
"MySQL JDBC (Bundled)", jarFileURL.getPath());


Here's the code where I try to create the profile and connect through it.

String driverID =
"org.eclipse.datatools.enablement.mysql.5_1.driverTemplate";
String userName = userName;
String password = password;

Properties props = new Properties();
props.setProperty(ConnectionProfileConstants.PROP_DRIVER_DEF INITION_ID,
driverID);
props.setProperty(ConnectionProfileConstants.PROP_PWD, password);
props.setProperty(ConnectionProfileConstants.PROP_UID, userName);

try {
pfm.createProfile("MySQL", "MySQL JDBC Profile",

"org.eclipse.datatools.enablement.mysql.5_1.driverTemplate", props);
} catch (ConnectionProfileException e1) {
e1.printStackTrace();
}
IConnectionProfile profile = pfm.getProfileByName("MySQL");
if (profile.arePropertiesComplete()){
System.err.println("Properties are complete");
} else {
System.err.println("Properties are NOT complete");
}

if(profile.getConnectionState() != IConnectionProfile.CONNECTED_STATE){
profile.connect();
}
connection = profile.createConnection("java.sql.Connection");
//NPE thrown for statement above. See stack trace below
rawConn = (Connection)connection.getRawConnection();

Stack Trace:

Note: I simplified the code above, since I actually call a separate class
(SomeDatabase) where createConnection() is invoked. SomeDatabase.java line
25 in the stack trace corresponds to the line above where I indicated the
NPE was thrown.

java.lang.NullPointerException
at
org.eclipse.datatools.connectivity.internal.ConnectionProfil e.createConnection(ConnectionProfile.java:355)
at prophettest.SomeDatabase.connect(SomeDatabase.java:25)
at prophettest.ConnectionTest.test(ConnectionTest.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.junit.internal.runners.TestMethodRunner.executeMethodBod y(TestMethodRunner.java:99)
at
org.junit.internal.runners.TestMethodRunner.runUnprotected(T estMethodRunner.java:81)
at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected (BeforeAndAfterRunner.java:34)
at
org.junit.internal.runners.TestMethodRunner.runMethod(TestMe thodRunner.java:75)
at
org.junit.internal.runners.TestMethodRunner.run(TestMethodRu nner.java:45)
at
org.junit.internal.runners.TestClassMethodsRunner.invokeTest Method(TestClassMethodsRunner.java:66)
at
org.junit.internal.runners.TestClassMethodsRunner.run(TestCl assMethodsRunner.java:35)
at
org.junit.internal.runners.TestClassRunner$1.runUnprotected( TestClassRunner.java:42)
at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected (BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunn er.java:52)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:45)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
at
org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunne r.main(RemotePluginTestRunner.java:62)
at
org.eclipse.pde.internal.junit.runtime.UITestApplication$1.r un(UITestApplication.java:114)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:3 5)
at
org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchr onizer.java:133)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.jav a:3800)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3425)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2382)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:21 98)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:493)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:288)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:488)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at com.tasc.swb.internal.application.SWBApplication.start(Unkno wn Source)
at
org.eclipse.pde.internal.junit.runtime.UITestApplication.sta rt(UITestApplication.java:46)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:193)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:382)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 549)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
at org.eclipse.equinox.launcher.Main.main(Main.java:1212)
Re: How do I create a Connection Profile [message #594650 is a reply to message #53454] Thu, 12 March 2009 19:54 Go to previous message
Mark Leone is currently offline Mark LeoneFriend
Messages: 123
Registered: July 2009
Senior Member
I've gotten further along on this, but I'm still stuck.

I loaded into my target environment the DTP plug-in which provides a MySQL
connectionProfile
(org.eclipse.datatools.enablement.mysql_1.0.2.v200810160130. jar), and all
it's dependencies. I see that in the plug-in's Plugin.XML it defines a
connection profile with cateory =
"org.eclipse.datatools.connectivity.db.category" and name = "MySQL".

But when I query the profile manager for the profile by name or by
category, an NPE is thrown. Below is the code I'm executing.

ProfileManager pfm = ProfileManager.getInstance();
if (pfm == null){
System.err.println("No ProfileManager");
}
else{
IConnectionProfile profileByName =
pfm.getProfileByName("MySQL"); // NPE thrown here
System.out.println("Profile (by name) name: " +
profileByName.getName());
System.out.println("Profile (by name) ID: " +
profileByName.getInstanceID());
}

alternatively, if I execute the following code to get the profiles by
category I also see an NPE thrown

IConnectionProfile[] profiles = pfm.getProfilesByCategory(
"org.eclipse.datatools.connectivity.db.category");// NPE thrown here
for(IConnectionProfile catProfile : profiles){
System.out.println("Profile (by Cat) name: " + catProfile.getName());
System.out.println("Profile (by Cat) ID: " +
catProfile.getInstanceID());
Re: How do I create a Connection Profile [message #594661 is a reply to message #53482] Fri, 13 March 2009 14:41 Go to previous message
Brian Fitzpatrick is currently offline Brian FitzpatrickFriend
Messages: 500
Registered: July 2009
Senior Member
Hey Mark...

You're definitely along the right path.

When you talk about using the API... What are you including for dependencies
in the plug-in that's calling the API?

And what's the NPE that you're getting? That'll help me better diagnose
what's going on.

--Fitz

"Mark Leone" <midnightjava@verizon.net> wrote in message
news:20f0543b701bb5f2663988d6c0943224$1@www.eclipse.org...
> I've gotten further along on this, but I'm still stuck.
>
> I loaded into my target environment the DTP plug-in which provides a MySQL
> connectionProfile
> (org.eclipse.datatools.enablement.mysql_1.0.2.v200810160130. jar), and all
> it's dependencies. I see that in the plug-in's Plugin.XML it defines a
> connection profile with cateory =
> "org.eclipse.datatools.connectivity.db.category" and name = "MySQL".
>
> But when I query the profile manager for the profile by name or by
> category, an NPE is thrown. Below is the code I'm executing.
>
> ProfileManager pfm = ProfileManager.getInstance();
> if (pfm == null){
> System.err.println("No ProfileManager");
> }
> else{
> IConnectionProfile profileByName =
> pfm.getProfileByName("MySQL"); // NPE thrown here
> System.out.println("Profile (by name) name: " + profileByName.getName());
> System.out.println("Profile (by name) ID: " +
> profileByName.getInstanceID());
> }
>
> alternatively, if I execute the following code to get the profiles by
> category I also see an NPE thrown
>
> IConnectionProfile[] profiles = pfm.getProfilesByCategory(
> "org.eclipse.datatools.connectivity.db.category");// NPE thrown here
> for(IConnectionProfile catProfile : profiles){
> System.out.println("Profile (by Cat) name: " + catProfile.getName());
> System.out.println("Profile (by Cat) ID: " + catProfile.getInstanceID());
>
>
>
Re: How do I create a Connection Profile [message #594752 is a reply to message #53510] Fri, 13 March 2009 17:48 Go to previous message
Mark Leone is currently offline Mark LeoneFriend
Messages: 123
Registered: July 2009
Senior Member
Fitz,

Thanks for your response. I'm pursuing a different implementation vector
based on some guidance I just received from my tech lead. He wants me to
define the connection profile manually rather than try to retrieve one
declared in Plugin.XML. I have some code that does that, which I'll paste
below.

I'm able to verify that the properties are set properly on the connection
profile, but when I try to create a connection on the profile, I get an
NPE thrown in
org.eclipse.datatools.connectivity.internal.ConnectionProfil e. I looked at
the source code where the NPE is thrown, and it seems to be that I don't
have a connection factory set on it. I wasn't sure what value to pass for
the connection factory parameter, so that's probably where my problem is.

My code is below. I'm also registering a driver when the workbench starts
up. The code that does that is below.

DriverManager mgr = DriverManager.getInstance()
mgr.createNewDriverInstance( "org.eclipse.datatools.enablement.mysql.5_1.driverTemplate",
"MySQL JDBC (Bundled)", jarFileURL.getPath());


Here's the code where I try to create the profile and connect through it.

String driverID =
"org.eclipse.datatools.enablement.mysql.5_1.driverTemplate";
String userName = userName;
String password = password;

Properties props = new Properties();
props.setProperty(ConnectionProfileConstants.PROP_DRIVER_DEF INITION_ID,
driverID);
props.setProperty(ConnectionProfileConstants.PROP_PWD, password);
props.setProperty(ConnectionProfileConstants.PROP_UID, userName);

try {
pfm.createProfile("MySQL", "MySQL JDBC Profile",

"org.eclipse.datatools.enablement.mysql.5_1.driverTemplate", props);
} catch (ConnectionProfileException e1) {
e1.printStackTrace();
}
IConnectionProfile profile = pfm.getProfileByName("MySQL");
if (profile.arePropertiesComplete()){
System.err.println("Properties are complete");
} else {
System.err.println("Properties are NOT complete");
}

if(profile.getConnectionState() != IConnectionProfile.CONNECTED_STATE){
profile.connect();
}
connection = profile.createConnection("java.sql.Connection");
//NPE thrown for statement above. See stack trace below
rawConn = (Connection)connection.getRawConnection();

Stack Trace:

Note: I simplified the code above, since I actually call a separate class
(SomeDatabase) where createConnection() is invoked. SomeDatabase.java line
25 in the stack trace corresponds to the line above where I indicated the
NPE was thrown.

java.lang.NullPointerException
at
org.eclipse.datatools.connectivity.internal.ConnectionProfil e.createConnection(ConnectionProfile.java:355)
at prophettest.SomeDatabase.connect(SomeDatabase.java:25)
at prophettest.ConnectionTest.test(ConnectionTest.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.junit.internal.runners.TestMethodRunner.executeMethodBod y(TestMethodRunner.java:99)
at
org.junit.internal.runners.TestMethodRunner.runUnprotected(T estMethodRunner.java:81)
at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected (BeforeAndAfterRunner.java:34)
at
org.junit.internal.runners.TestMethodRunner.runMethod(TestMe thodRunner.java:75)
at
org.junit.internal.runners.TestMethodRunner.run(TestMethodRu nner.java:45)
at
org.junit.internal.runners.TestClassMethodsRunner.invokeTest Method(TestClassMethodsRunner.java:66)
at
org.junit.internal.runners.TestClassMethodsRunner.run(TestCl assMethodsRunner.java:35)
at
org.junit.internal.runners.TestClassRunner$1.runUnprotected( TestClassRunner.java:42)
at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected (BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunn er.java:52)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:45)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
at
org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunne r.main(RemotePluginTestRunner.java:62)
at
org.eclipse.pde.internal.junit.runtime.UITestApplication$1.r un(UITestApplication.java:114)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:3 5)
at
org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchr onizer.java:133)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.jav a:3800)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3425)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2382)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:21 98)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:493)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:288)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:488)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at com.tasc.swb.internal.application.SWBApplication.start(Unkno wn Source)
at
org.eclipse.pde.internal.junit.runtime.UITestApplication.sta rt(UITestApplication.java:46)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:193)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:382)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 549)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
at org.eclipse.equinox.launcher.Main.main(Main.java:1212)
Previous Topic:Error: Method can be called only once.
Next Topic:Run script to create procedure in DB2
Goto Forum:
  


Current Time: Sat Apr 20 00:47:31 GMT 2024

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

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

Back to the top