Search in sources :

Example 46 with DBException

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

the class DataSourceRegistry method loadDataSources.

private void loadDataSources(InputStream is, DataSourceOrigin origin, boolean refresh, ParseResults parseResults) throws DBException, IOException {
    SAXReader parser = new SAXReader(is);
    try {
        final DataSourcesParser dsp = new DataSourcesParser(origin, refresh, parseResults);
        parser.parse(dsp);
    } catch (XMLException ex) {
        throw new DBException("Datasource config parse error", ex);
    }
    updateProjectNature();
}
Also used : DBException(org.jkiss.dbeaver.DBException) XMLException(org.jkiss.utils.xml.XMLException) SAXReader(org.jkiss.utils.xml.SAXReader)

Example 47 with DBException

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

the class ProjectRegistry method loadProjects.

public void loadProjects(IProgressMonitor monitor) throws DBException {
    final DBeaverCore core = DBeaverCore.getInstance();
    String activeProjectName = DBeaverCore.getGlobalPreferenceStore().getString(PROP_PROJECT_ACTIVE);
    List<IProject> projects = core.getLiveProjects();
    monitor.beginTask("Open active project", projects.size());
    try {
        for (IProject project : projects) {
            if (project.exists() && !project.isHidden()) {
                if (project.getName().equals(activeProjectName)) {
                    activeProject = project;
                    break;
                } else if (activeProject == null) {
                    // By default use first project
                    activeProject = project;
                }
            }
            monitor.worked(1);
        }
        if (activeProject != null) {
            try {
                activeProject.open(monitor);
                activeProject.refreshLocal(IFile.DEPTH_ONE, monitor);
                setActiveProject(activeProject);
            } catch (CoreException e) {
                // Project seems to be corrupted
                projects.remove(activeProject);
                activeProject = null;
            }
        }
    } finally {
        monitor.done();
    }
    if (DBeaverCore.isStandalone() && CommonUtils.isEmpty(projects)) {
        // Create initial project (only for standalone version)
        monitor.beginTask("Create general project", 1);
        try {
            activeProject = createGeneralProject(monitor);
            activeProject.open(monitor);
            setActiveProject(activeProject);
        } catch (CoreException e) {
            throw new DBException("Can't create default project", e);
        } finally {
            monitor.done();
        }
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBeaverCore(org.jkiss.dbeaver.core.DBeaverCore)

Example 48 with DBException

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

the class DriverDescriptor method loadDriver.

private void loadDriver(DBRProgressMonitor monitor, boolean forceReload) throws DBException {
    if (isLoaded && !forceReload) {
        return;
    }
    isLoaded = false;
    loadLibraries();
    if (!acceptDriverLicenses()) {
        throw new DBException("You have to accept driver '" + getFullName() + "' license to be able to connect");
    }
    try {
        if (!isCustomDriverLoader()) {
            try {
                // Load driver classes into core module using plugin class loader
                driverClass = Class.forName(driverClassName, true, classLoader);
            } catch (Throwable ex) {
                throw new DBException("Can't load driver class '" + driverClassName + "'", ex);
            }
            // Create driver instance
            /*if (!this.isInternalDriver())*/
            {
                driverInstance = createDriverInstance();
            }
            isLoaded = true;
            isFailed = false;
        }
    } catch (DBException e) {
        isFailed = true;
        throw e;
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException)

Example 49 with DBException

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

the class DataFormatterRegistry method loadProfiles.

private void loadProfiles() {
    customProfiles = new ArrayList<>();
    File storeFile = DBeaverActivator.getConfigurationFile(CONFIG_FILE_NAME);
    if (!storeFile.exists()) {
        return;
    }
    try {
        try (InputStream is = new FileInputStream(storeFile)) {
            SAXReader parser = new SAXReader(is);
            try {
                parser.parse(new FormattersParser());
            } catch (XMLException ex) {
                throw new DBException("Datasource config parse error", ex);
            }
        } catch (DBException ex) {
            log.warn("Can't load profiles config from " + storeFile.getPath(), ex);
        }
    } catch (IOException ex) {
        log.warn("IO error", ex);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) XMLException(org.jkiss.utils.xml.XMLException) SAXReader(org.jkiss.utils.xml.SAXReader)

Example 50 with DBException

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

the class DatabaseLazyEditorInput method initializeRealInput.

public IDatabaseEditorInput initializeRealInput(final DBRProgressMonitor monitor) throws DBException {
    final DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
    while (!dataSource.isConnected()) {
        boolean connected;
        try {
            connected = dataSource.connect(monitor, true, true);
        } catch (final DBException e) {
            // Connection error
            final Integer result = new UITask<Integer>() {

                @Override
                protected Integer runTask() {
                    ConnectionLostDialog clDialog = new ConnectionLostDialog(DBeaverUI.getActiveWorkbenchShell(), dataSource, e, "Close");
                    return clDialog.open();
                }
            }.execute();
            if (result == IDialogConstants.STOP_ID) {
                // Close editor
                return null;
            } else if (result == IDialogConstants.RETRY_ID) {
                continue;
            } else {
                return new ErrorEditorInput(GeneralUtils.makeExceptionStatus(e), navigatorModel.getNodeByObject(dataSource));
            }
        }
        if (!connected) {
            throw new DBException("Connection to '" + dataSource.getName() + "' canceled");
        }
        break;
    }
    try {
        DBNDataSource dsNode = (DBNDataSource) navigatorModel.getNodeByObject(monitor, dataSource, true);
        if (dsNode == null) {
            throw new DBException("Datasource '" + dataSource.getName() + "' navigator node not found");
        }
        dsNode.initializeNode(monitor, null);
        final DBNNode node = navigatorModel.getNodeByPath(monitor, project, nodePath);
        if (node == null) {
            throw new DBException("Navigator node '" + nodePath + "' not found");
        }
        if (node instanceof DBNDatabaseNode) {
            EntityEditorInput realInput = new EntityEditorInput((DBNDatabaseNode) node);
            realInput.setDefaultFolderId(activeFolderId);
            realInput.setDefaultPageId(activePageId);
            return realInput;
        } else {
            throw new DBException("Database node has bad type: " + node.getClass().getName());
        }
    } catch (DBException e) {
        return new ErrorEditorInput(GeneralUtils.makeExceptionStatus(e), navigatorModel.getNodeByObject(dataSource));
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) UITask(org.jkiss.dbeaver.ui.UITask) ConnectionLostDialog(org.jkiss.dbeaver.ui.dialogs.ConnectionLostDialog) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) EntityEditorInput(org.jkiss.dbeaver.ui.editors.entity.EntityEditorInput) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel)

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