Hi all!
Have you ever wondered how to get a DTP SQL Model Database object from a connected connection profile? I seem to run into this problem infrequently, but always have to go through many gyrations to find the answer.Larry from IBM, another member of the Connectivity team, was kind enough to provide the answer. It resulted in this chunk of code:
public Database getDatabaseForProfile (IConnectionProfile profile) {
IManagedConnection managedConnection = ((IConnectionProfile)profile).
getManagedConnection("org.eclipse.datatools.connectivity.sqm.core.connection.ConnectionInfo");
if (managedConnection != null) {
try {
ConnectionInfo connectionInfo = (ConnectionInfo) managedConnection.
getConnection().getRawConnection();
if (connectionInfo != null) {
return connectionInfo.getSharedDatabase();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
(Sorry the code's not pretty. I haven't found a great way of including code in Blogger blog posts yet.)Basically under the covers there is a ConnectionInfo connection adapter that is used to map between the java.sql.Connection object we get from JDBC and the SQL model that's populated via the catalog loaders.
So there you have it! Not that many people have a need for such a thing, but it's handy just in case!
--Fitz