/** * Gets the shared connection from the connection profile * TODO Now this method delegates to IConnectionProfile, which doesn't manage a connection for each * database. * @param databaseIdentifier database identifier used to locate the connection profile * @return the shared connection managed by the connection profile * @throws SQLException * @throws NoSuchProfileException */ public static Connection getReusableConnection(DatabaseIdentifier databaseIdentifier) throws SQLException, NoSuchProfileException { IConnectionProfile profile = getProfile(databaseIdentifier.getProfileName()); if (!profile.isConnected()) { throw new SQLException(NLS.bind(Messages.ProfileUtil_error_not_connected, (new Object[]{databaseIdentifier.getProfileName()}))); } IManagedConnection managedConn = profile.getManagedConnection("java.sql.Connection"); if (managedConn == null || !managedConn.isConnected()) { throw new SQLException(NLS.bind(Messages.ProfileUtil_error_getReusableConnection, (new Object[]{databaseIdentifier.toString()}))); } IConnection iconn = managedConn.getConnection(); DBHelper helper = SQLToolsFacade.getDBHelper(databaseIdentifier); Connection conn = (Connection)iconn.getRawConnection(); helper.switchDatabase(databaseIdentifier, conn); return conn; }
helper.switchDatabase(databaseIdentifier, conn);
DBHelper helper = SQLToolsFacade.getDBHelper(databaseIdentifier); Connection conn = (Connection)iconn.getRawConnection(); helper.switchDatabase(databaseIdentifier, conn); return conn;