Search in sources :

Example 1 with DBException

use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.

the class NavigatorHandlerObjectOpen method refreshDatabaseNode.

private static void refreshDatabaseNode(@NotNull DBNDatabaseNode selectedNode) throws InvocationTargetException, InterruptedException {
    final DBNDatabaseNode nodeToRefresh = selectedNode;
    DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {

        @Override
        public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                nodeToRefresh.refreshNode(monitor, nodeToRefresh);
            } catch (DBException e) {
                log.error("Error refreshing database object", e);
            }
        }
    });
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with DBException

use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.

the class NavigatorActionSetActiveObject method run.

@Override
public void run(IAction action) {
    if (selection instanceof IStructuredSelection) {
        DBNNode selectedNode = NavigatorUtils.getSelectedNode(selection);
        if (selectedNode instanceof DBNDatabaseNode) {
            final DBNDatabaseNode databaseNode = (DBNDatabaseNode) selectedNode;
            final DBSObjectSelector activeContainer = DBUtils.getParentAdapter(DBSObjectSelector.class, databaseNode.getObject());
            if (activeContainer != null) {
                TasksJob.runTask("Select active object", new DBRRunnableWithProgress() {

                    @Override
                    public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            activeContainer.setDefaultObject(monitor, databaseNode.getObject());
                        } catch (DBException e) {
                            throw new InvocationTargetException(e);
                        }
                    }
                });
            }
        }
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBSObjectSelector(org.jkiss.dbeaver.model.struct.DBSObjectSelector) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with DBException

use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.

the class NavigatorHandlerAddBookmark method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final Shell activeShell = HandlerUtil.getActiveShell(event);
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
        final DBNNode node = NavigatorUtils.getSelectedNode(selection);
        if (node instanceof DBNDatabaseNode) {
            try {
                AddBookmarkDialog dialog = new AddBookmarkDialog(activeShell, (DBNDatabaseNode) node);
                final String title = dialog.chooseName();
                if (title != null) {
                    BookmarksHandlerImpl.createBookmark((DBNDatabaseNode) node, title, dialog.getTargetFolder());
                }
            } catch (DBException e) {
                UIUtils.showErrorDialog(activeShell, CoreMessages.actions_navigator_bookmark_error_title, CoreMessages.actions_navigator_bookmark_error_message, e);
            }
        }
    }
    return null;
}
Also used : DBException(org.jkiss.dbeaver.DBException) Shell(org.eclipse.swt.widgets.Shell) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 4 with DBException

use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.

the class NavigatorHandlerCreateFolder method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection structSelection = (IStructuredSelection) selection;
        Object element = structSelection.getFirstElement();
        if (!(element instanceof DBNResource)) {
            return null;
        }
        Shell activeShell = HandlerUtil.getActiveShell(event);
        String folderName = EnterNameDialog.chooseName(activeShell, CoreMessages.actions_navigator_create_folder_folder_name);
        if (!CommonUtils.isEmpty(folderName)) {
            try {
                ((DBNResource) element).createNewFolder(folderName);
            } catch (DBException e) {
                UIUtils.showErrorDialog(activeShell, CoreMessages.actions_navigator_create_folder_error_title, NLS.bind(CoreMessages.actions_navigator_create_folder_error_message, folderName), e);
            }
        }
    }
    return null;
}
Also used : DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) DBException(org.jkiss.dbeaver.DBException) Shell(org.eclipse.swt.widgets.Shell) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 5 with DBException

use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.

the class ConnectionPageGeneral method saveSettings.

void saveSettings(DataSourceDescriptor dataSource) {
    if (dataSourceDescriptor != null && !activated) {
        // No changes anyway
        return;
    }
    dataSource.setName(connectionNameText.getText());
    dataSource.setSavePassword(savePasswordCheck.getSelection());
    try {
        dataSource.setDefaultAutoCommit(autocommit.getSelection(), null, true, null);
        if (dataSource.isConnected()) {
            int levelIndex = isolationLevel.getSelectionIndex();
            if (levelIndex <= 0) {
                dataSource.setDefaultTransactionsIsolation(null);
            } else {
                dataSource.setDefaultTransactionsIsolation(supportedLevels.get(levelIndex - 1));
            }
        }
    } catch (DBException e) {
        log.error(e);
    }
    dataSource.setDefaultActiveObject(defaultSchema.getText());
    dataSource.setShowSystemObjects(showSystemObjects.getSelection());
    dataSource.setShowUtilityObjects(showUtilityObjects.getSelection());
    dataSource.setConnectionReadOnly(readOnlyConnection.getSelection());
    if (!dataSource.isSavePassword()) {
        dataSource.resetPassword();
    }
    dataSource.setFolder(dataSourceFolder);
    final DBPConnectionConfiguration confConfig = dataSource.getConnectionConfiguration();
    if (connectionTypeCombo.getSelectionIndex() >= 0) {
        confConfig.setConnectionType(connectionTypeCombo.getItem(connectionTypeCombo.getSelectionIndex()));
    }
    for (FilterInfo filterInfo : filters) {
        if (filterInfo.filter != null) {
            dataSource.setObjectFilter(filterInfo.type, null, filterInfo.filter);
        }
    }
    DBPConnectionBootstrap bootstrap = confConfig.getBootstrap();
    bootstrap.setIgnoreErrors(ignoreBootstrapErrors);
    bootstrap.setInitQueries(bootstrapQueries);
    confConfig.setKeepAliveInterval(keepAliveInterval.getSelection());
    final String description = descriptionText.getText();
    if (description.isEmpty()) {
        dataSource.setDescription(null);
    } else {
        dataSource.setDescription(description);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DBPConnectionBootstrap(org.jkiss.dbeaver.model.connection.DBPConnectionBootstrap)

Aggregations

DBException (org.jkiss.dbeaver.DBException)232 SQLException (java.sql.SQLException)58 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)51 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)50 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)43 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)42 ArrayList (java.util.ArrayList)37 InvocationTargetException (java.lang.reflect.InvocationTargetException)23 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)23 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)16 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)14 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)13 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)13 GridData (org.eclipse.swt.layout.GridData)12 DBCException (org.jkiss.dbeaver.model.exec.DBCException)12 CoreException (org.eclipse.core.runtime.CoreException)11 AbstractObjectReference (org.jkiss.dbeaver.model.impl.struct.AbstractObjectReference)10 IStatus (org.eclipse.core.runtime.IStatus)9 DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)8 XMLException (org.jkiss.utils.xml.XMLException)8