1 package com.quantum.util.connection;
3 import java.sql.Connection;
4 import java.sql.SQLException;
6 import com.quantum.Messages;
7 import com.quantum.model.Bookmark;
8 import com.quantum.model.ConnectionException;
9 import com.quantum.model.NotConnectedException;
10 import com.quantum.ui.dialog.ExceptionDisplayDialog;
11 import com.quantum.ui.dialog.PasswordDialog;
12 import com.quantum.ui.dialog.SQLExceptionDialog;
14 import org.eclipse.swt.widgets.Shell;
17 * <p>This utility gets a connection from a bookmark, and handles any UI-specific
18 * interactions such as providing messages to the user and/or prompting for a
23 public class ConnectionUtil {
25 public Connection getConnection(Bookmark bookmark, Shell shell) {
26 Connection connection = null;
28 connection = bookmark.getConnection();
29 } catch (NotConnectedException e) {
30 connection = connect(bookmark, shell);
35 public Connection connect(Bookmark bookmark, Shell shell) {
36 Connection connection = null;
38 connection = bookmark.connect(PasswordDialog.createPasswordFinder(shell));
39 } catch (ConnectionException e) {
40 if (e.getCause() != null && e.getCause() instanceof SQLException) {
41 SQLExceptionDialog.openException(shell, bookmark, (SQLException) e.getCause());
43 ExceptionDisplayDialog.openError(shell,
44 Messages.getString(getClass().getName() + ".title"),
45 Messages.getString(getClass().getName() + ".message") +
46 " (Bookmark:"+bookmark.getName()+")", e);