Search in sources :

Example 1 with SQLCannotConnectException

use of net.sourceforge.sqlexplorer.SQLCannotConnectException in project tdq-studio-se by Talend.

the class OpenPasswordConnectDialogAction method run.

public void run() {
    SessionEstablishedListener listener = null;
    if (!user.hasAuthenticated())
        listener = new SessionEstablishedAdapter() {

            @Override
            public void sessionEstablished(Session session) {
                Display.getDefault().asyncExec(new Runnable() {

                    public void run() {
                        DatabaseStructureView dsView = SQLExplorerPlugin.getDefault().getDatabaseStructureView();
                        if (dsView != null)
                            try {
                                dsView.addUser(user);
                            } catch (SQLCannotConnectException e) {
                                MessageDialog.openError(Display.getDefault().getActiveShell(), "Cannot connect", e.getMessage());
                            }
                    }
                });
            }
        };
    ConnectionJob.createSession(alias, user, listener, alwaysPrompt);
}
Also used : SessionEstablishedListener(net.sourceforge.sqlexplorer.connections.SessionEstablishedListener) DatabaseStructureView(net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView) SessionEstablishedAdapter(net.sourceforge.sqlexplorer.connections.SessionEstablishedAdapter) Session(net.sourceforge.sqlexplorer.dbproduct.Session) SQLCannotConnectException(net.sourceforge.sqlexplorer.SQLCannotConnectException)

Example 2 with SQLCannotConnectException

use of net.sourceforge.sqlexplorer.SQLCannotConnectException in project tdq-studio-se by Talend.

the class ConnectionsView method openNewEditor.

public void openNewEditor(User user) {
    try {
        // First time we connect, get the database structure view up too
        if (!user.hasAuthenticated()) {
            DatabaseStructureView dsView = SQLExplorerPlugin.getDefault().getDatabaseStructureView();
            dsView.addUser(user);
        }
        SQLEditorInput input = new SQLEditorInput("SQL Editor (" + SQLExplorerPlugin.getDefault().getEditorSerialNo() + // $NON-NLS-1$ $NON-NLS-2$
        ").sql");
        input.setUser(user);
        IWorkbenchPage page = SQLExplorerPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
        page.openEditor(input, SQLEditor.class.getName());
    } catch (SQLCannotConnectException e) {
        MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.getString("ConnectionsView.cannotConnect"), e.getMessage());
    } catch (Throwable e) {
        SQLExplorerPlugin.error(Messages.getString("ConnectionsView.errCreateSql"), e);
    }
}
Also used : SQLEditorInput(net.sourceforge.sqlexplorer.plugin.editors.SQLEditorInput) SQLEditor(net.sourceforge.sqlexplorer.plugin.editors.SQLEditor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) DatabaseStructureView(net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView) SQLCannotConnectException(net.sourceforge.sqlexplorer.SQLCannotConnectException)

Example 3 with SQLCannotConnectException

use of net.sourceforge.sqlexplorer.SQLCannotConnectException in project tdq-studio-se by Talend.

the class NewDatabaseStructureViewAction method run.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
@Override
public void run() {
    DatabaseStructureView view = SQLExplorerPlugin.getDefault().getDatabaseStructureView();
    if (view == null) {
        return;
    }
    Collection<User> users = getView().getSelectedUsers(true);
    for (User user : users) {
        try {
            // ADD msjian TDQ-8535 2014-4-25: we need to do this to make sure the hive connection can be created
            // successfully
            setMetadataToUserAndUpdateDriver(user);
            // TDQ-8535~
            view.addUser(user);
        } catch (SQLCannotConnectException e) {
            MessageDialog.openError(Display.getDefault().getActiveShell(), "Cannot connect", e.getMessage());
        }
    }
}
Also used : User(net.sourceforge.sqlexplorer.dbproduct.User) DatabaseStructureView(net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView) SQLCannotConnectException(net.sourceforge.sqlexplorer.SQLCannotConnectException)

Example 4 with SQLCannotConnectException

use of net.sourceforge.sqlexplorer.SQLCannotConnectException in project tdq-studio-se by Talend.

the class ManagedDriver method getConnection.

/**
 * Establishes a JDBC connection
 *
 * @param user
 * @return
 * @throws ExplorerException
 * @throws SQLException
 */
public SQLConnection getConnection(User user) throws SQLException {
    Properties props = new Properties();
    // jars(e.g:ojdbc14.jar) don't support international and cause to get connection error
    if (user.getUserName() != null) {
        // $NON-NLS-1$
        props.put("user", user.getUserName());
    }
    if (user.getPassword() != null) {
        // $NON-NLS-1$
        props.put("password", user.getPassword());
    }
    if (!isDriverClassLoaded()) {
        try {
            DatabaseConnection dbConn = user.getDatabaseConnection();
            if (dbConn != null) {
                registerSQLDriver(dbConn);
            }
        } catch (Exception e) {
            throw new SQLException(// $NON-NLS-1$ //$NON-NLS-2$
            Messages.getString("ManagedDriver.CannotLoadDriver1", driverClassName) + " " + // $NON-NLS-1$
            Messages.getString("ManagedDriver.CannotLoadDriver2"));
        }
    }
    if (!isDriverClassLoaded()) {
        // $NON-NLS-1$
        throw new SQLException(Messages.getString("ManagedDriver.CannotLoadDriver1", driverClassName));
    }
    Connection jdbcConn = null;
    try {
        String dbUrl = user.getAlias().getUrl();
        if (ConnectionUtils.isHsql(dbUrl)) {
            dbUrl = ConnectionUtils.addShutDownForHSQLUrl(dbUrl, user.getDatabaseConnection().getAdditionalParams());
        }
        jdbcConn = jdbcDriver.connect(dbUrl, props);
    } catch (SQLException e) {
        throw new SQLCannotConnectException(user, e);
    }
    if (jdbcConn == null) {
        throw new SQLCannotConnectException(user);
    }
    return new SQLConnection(user, jdbcConn, this, getDatabaseProduct().describeConnection(jdbcConn));
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Properties(java.util.Properties) SQLException(java.sql.SQLException) ExplorerException(net.sourceforge.sqlexplorer.ExplorerException) ValidationException(net.sourceforge.squirrel_sql.fw.persist.ValidationException) SQLCannotConnectException(net.sourceforge.sqlexplorer.SQLCannotConnectException) SQLCannotConnectException(net.sourceforge.sqlexplorer.SQLCannotConnectException)

Example 5 with SQLCannotConnectException

use of net.sourceforge.sqlexplorer.SQLCannotConnectException in project tdq-studio-se by Talend.

the class DatabaseStructureView method addSession.

/**
 * Add a new session to the database structure view. This will create a new tab for the session.
 *
 * @param session
 */
private void addSession(final MetaDataSession session) throws SQLCannotConnectException {
    if (_allSessions.contains(session)) {
        return;
    }
    try {
        session.getMetaData();
        session.setAutoCommit(true);
    } catch (SQLCannotConnectException e) {
        SQLExplorerPlugin.error(e);
        throw e;
    } catch (SQLException e) {
        SQLExplorerPlugin.error(e);
        MessageDialog.openError(getSite().getShell(), "Cannot connect", e.getMessage());
    }
    DatabaseNode rootNode = session.getRoot();
    if (rootNode == null) {
        return;
    }
    _allSessions.add(session);
    if (_filterAction != null) {
        _filterAction.setEnabled(true);
    }
    if (_tabFolder == null || _tabFolder.isDisposed()) {
        clearParent();
        // create tab folder for different sessions
        _tabFolder = new CTabFolder(_parent, SWT.TOP | SWT.CLOSE);
        // add listener to keep both views on the same active tab
        _tabFolder.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                // set the selected node in the detail view.
                DatabaseDetailView detailView = (DatabaseDetailView) getSite().getPage().findView(SqlexplorerViewConstants.SQLEXPLORER_DBDETAIL);
                synchronizeDetailView(detailView);
            }
        });
        // Set up a gradient background for the selected tab
        Display display = getSite().getShell().getDisplay();
        _tabFolder.setSelectionBackground(new Color[] { display.getSystemColor(SWT.COLOR_WHITE), new Color(null, 211, 225, 250), new Color(null, 175, 201, 246), IConstants.TAB_BORDER_COLOR }, new int[] { 25, 50, 75 }, true);
        // Add a listener to handle the close button on each tab
        _tabFolder.addCTabFolder2Listener(new CTabFolder2Adapter() {

            @Override
            public void close(CTabFolderEvent event) {
                CTabItem tabItem = (CTabItem) event.item;
                TabData tabData = (TabData) tabItem.getData();
                _allSessions.remove(tabData.session);
                event.doit = true;
            }
        });
        _parent.layout();
        _parent.redraw();
    }
    // create tab
    final CTabItem tabItem = new CTabItem(_tabFolder, SWT.NULL);
    TabData tabData = new TabData();
    tabItem.setData(tabData);
    tabData.session = session;
    // set tab text
    String labelText = session.getUser().getDescription();
    tabItem.setText(labelText);
    // create composite for our outline
    Composite composite = new Composite(_tabFolder, SWT.NULL);
    composite.setLayout(new FillLayout());
    tabItem.setControl(composite);
    // create outline
    final TreeViewer treeViewer = new TreeViewer(composite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER);
    tabData.treeViewer = treeViewer;
    // add drag support
    // TODO improve drag support options
    Transfer[] transfers = new Transfer[] { TableNodeTransfer.getInstance() };
    treeViewer.addDragSupport(DND.DROP_COPY, transfers, new DragSourceListener() {

        public void dragFinished(DragSourceEvent event) {
            System.out.println("$drag finished");
            TableNodeTransfer.getInstance().setSelection(null);
        }

        public void dragSetData(DragSourceEvent event) {
            Object sel = ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
            event.data = sel;
        }

        public void dragStart(DragSourceEvent event) {
            event.doit = !treeViewer.getSelection().isEmpty();
            if (event.doit) {
                Object sel = ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
                if (!(sel instanceof TableNode)) {
                    event.doit = false;
                } else {
                    TableNode tn = (TableNode) sel;
                    TableNodeTransfer.getInstance().setSelection(tn);
                    if (!tn.isTable()) {
                        event.doit = false;
                    }
                }
            }
        }
    });
    // use hash lookup to improve performance
    treeViewer.setUseHashlookup(true);
    // add content and label provider
    treeViewer.setContentProvider(new DBTreeContentProvider());
    treeViewer.setLabelProvider(new DBTreeLabelProvider());
    // set input session
    treeViewer.setInput(rootNode);
    // add selection change listener, so we can update detail view as
    // required.
    treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent ev) {
            // set the selected node in the detail view.
            DatabaseDetailView detailView = (DatabaseDetailView) getSite().getPage().findView(SqlexplorerViewConstants.SQLEXPLORER_DBDETAIL);
            synchronizeDetailView(detailView);
        }
    });
    // bring detail to front on doubleclick of node
    treeViewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            try {
                // find view
                DatabaseDetailView detailView = (DatabaseDetailView) getSite().getPage().findView(SqlexplorerViewConstants.SQLEXPLORER_DBDETAIL);
                if (detailView == null) {
                    getSite().getPage().showView(SqlexplorerViewConstants.SQLEXPLORER_DBDETAIL);
                }
                getSite().getPage().bringToTop(detailView);
                synchronizeDetailView(detailView);
            } catch (Exception e) {
            // fail silent
            }
        }
    });
    // add expand/collapse listener
    treeViewer.addTreeListener(new ITreeViewerListener() {

        public void treeCollapsed(TreeExpansionEvent event) {
            // refresh the node to change image
            INode node = (INode) event.getElement();
            node.setExpanded(false);
            TreeViewer viewer = (TreeViewer) event.getSource();
            viewer.update(node, null);
        }

        public void treeExpanded(TreeExpansionEvent event) {
            // refresh the node to change image
            INode node = (INode) event.getElement();
            node.setExpanded(true);
            TreeViewer viewer = (TreeViewer) event.getSource();
            viewer.update(node, null);
        }
    });
    // set new tab as the active one
    _tabFolder.setSelection(_tabFolder.getItemCount() - 1);
    // update detail view
    DatabaseDetailView detailView = (DatabaseDetailView) getSite().getPage().findView(SqlexplorerViewConstants.SQLEXPLORER_DBDETAIL);
    if (detailView != null) {
        // synchronze detail view with new session
        synchronizeDetailView(detailView);
        // bring detail to top of the view stack
        getSite().getPage().bringToTop(detailView);
    }
    // refresh view
    composite.layout();
    _tabFolder.layout();
    _tabFolder.redraw();
    // bring this view to top of the view stack, above detail if needed..
    getSite().getPage().bringToTop(this);
    // add context menu
    final DBTreeActionGroup actionGroup = new DBTreeActionGroup(treeViewer);
    MenuManager menuManager = new MenuManager("DBTreeContextMenu");
    menuManager.setRemoveAllWhenShown(true);
    Menu contextMenu = menuManager.createContextMenu(treeViewer.getTree());
    treeViewer.getTree().setMenu(contextMenu);
    menuManager.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            actionGroup.fillContextMenu(manager);
        }
    });
// if (sessionSelectionMap.containsKey(tabData.session)) {
// tabData.treeViewer.setSelection(sessionSelectionMap.get(tabData.session));
// sessionSelectionMap.remove(tabData.session);
// _allSessions.remove(tabData.session);
// }
}
Also used : INode(net.sourceforge.sqlexplorer.dbstructure.nodes.INode) CTabFolder(org.eclipse.swt.custom.CTabFolder) SQLException(java.sql.SQLException) TreeViewer(org.eclipse.jface.viewers.TreeViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) DBTreeActionGroup(net.sourceforge.sqlexplorer.dbstructure.DBTreeActionGroup) CTabItem(org.eclipse.swt.custom.CTabItem) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) DatabaseNode(net.sourceforge.sqlexplorer.dbstructure.nodes.DatabaseNode) DBTreeLabelProvider(net.sourceforge.sqlexplorer.dbstructure.DBTreeLabelProvider) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBTreeContentProvider(net.sourceforge.sqlexplorer.dbstructure.DBTreeContentProvider) Menu(org.eclipse.swt.widgets.Menu) TreeExpansionEvent(org.eclipse.jface.viewers.TreeExpansionEvent) CTabFolder2Adapter(org.eclipse.swt.custom.CTabFolder2Adapter) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Color(org.eclipse.swt.graphics.Color) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ITreeViewerListener(org.eclipse.jface.viewers.ITreeViewerListener) CTabFolderEvent(org.eclipse.swt.custom.CTabFolderEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FillLayout(org.eclipse.swt.layout.FillLayout) SQLException(java.sql.SQLException) SQLCannotConnectException(net.sourceforge.sqlexplorer.SQLCannotConnectException) IMenuListener(org.eclipse.jface.action.IMenuListener) Transfer(org.eclipse.swt.dnd.Transfer) TableNode(net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) SQLCannotConnectException(net.sourceforge.sqlexplorer.SQLCannotConnectException) Display(org.eclipse.swt.widgets.Display)

Aggregations

SQLCannotConnectException (net.sourceforge.sqlexplorer.SQLCannotConnectException)7 DatabaseStructureView (net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView)4 SQLException (java.sql.SQLException)2 SQLEditor (net.sourceforge.sqlexplorer.plugin.editors.SQLEditor)2 SQLEditorInput (net.sourceforge.sqlexplorer.plugin.editors.SQLEditorInput)2 Connection (java.sql.Connection)1 Properties (java.util.Properties)1 ExplorerException (net.sourceforge.sqlexplorer.ExplorerException)1 SessionEstablishedAdapter (net.sourceforge.sqlexplorer.connections.SessionEstablishedAdapter)1 SessionEstablishedListener (net.sourceforge.sqlexplorer.connections.SessionEstablishedListener)1 Alias (net.sourceforge.sqlexplorer.dbproduct.Alias)1 Session (net.sourceforge.sqlexplorer.dbproduct.Session)1 User (net.sourceforge.sqlexplorer.dbproduct.User)1 DBTreeActionGroup (net.sourceforge.sqlexplorer.dbstructure.DBTreeActionGroup)1 DBTreeContentProvider (net.sourceforge.sqlexplorer.dbstructure.DBTreeContentProvider)1 DBTreeLabelProvider (net.sourceforge.sqlexplorer.dbstructure.DBTreeLabelProvider)1 DatabaseNode (net.sourceforge.sqlexplorer.dbstructure.nodes.DatabaseNode)1 INode (net.sourceforge.sqlexplorer.dbstructure.nodes.INode)1 TableNode (net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode)1 ValidationException (net.sourceforge.squirrel_sql.fw.persist.ValidationException)1