Search in sources :

Example 61 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project dbeaver by serge-rider.

the class ClientHomesSelector method populateHomes.

public void populateHomes(DBPDriver driver, String currentHome, boolean selectDefault) {
    this.driver = driver;
    this.currentHomeId = currentHome;
    this.homesCombo.removeAll();
    this.homeIds.clear();
    Map<String, DBPNativeClientLocation> homes = new LinkedHashMap<>();
    AbstractJob hlJob = new AbstractJob("Find native client homes") {

        @Override
        protected IStatus run(DBRProgressMonitor monitor) {
            for (DBPNativeClientLocation ncl : driver.getNativeClientLocations()) {
                homes.put(ncl.getName(), ncl);
            }
            DBPNativeClientLocationManager clientManager = driver.getNativeClientManager();
            if (clientManager != null) {
                for (DBPNativeClientLocation location : clientManager.findLocalClientLocations()) {
                    homes.putIfAbsent(location.getName(), location);
                }
            }
            return Status.OK_STATUS;
        }
    };
    hlJob.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            UIUtils.syncExec(() -> {
                for (DBPNativeClientLocation location : homes.values()) {
                    homesCombo.add(location.getDisplayName());
                    homeIds.add(location.getName());
                    if (currentHomeId != null && location.getName().equals(currentHomeId)) {
                        homesCombo.select(homesCombo.getItemCount() - 1);
                    }
                }
                if (homesCombo.getItemCount() == 0) {
                    homesCombo.add(UIConnectionMessages.controls_client_home_selector_missing);
                    homeIds.add(null);
                }
                if (selectDefault && homesCombo.getSelectionIndex() == -1) {
                    homesCombo.select(0);
                    currentHomeId = homeIds.get(0);
                }
                homesCombo.add(UIConnectionMessages.controls_client_home_selector_browse);
                displayClientVersion();
                homesCombo.setEnabled(true);
            });
            super.done(event);
        }
    });
    hlJob.schedule();
}
Also used : AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DBPNativeClientLocation(org.jkiss.dbeaver.model.connection.DBPNativeClientLocation) DBPNativeClientLocationManager(org.jkiss.dbeaver.model.connection.DBPNativeClientLocationManager) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent)

Example 62 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project dbeaver by serge-rider.

the class ERDEditorStandalone method loadDiagram.

/*
    protected void createActions()
    {
        super.createActions();

        //addEditorAction(new SaveAction(this));
    }
*/
@Override
protected synchronized void loadDiagram(boolean refreshMetadata) {
    if (diagramLoadingJob != null) {
        // Do not start new one while old is running
        return;
    }
    diagramLoadingJob = LoadingJob.createService(new AbstractLoadService<EntityDiagram>("Load diagram '" + getEditorInput().getName() + "'") {

        @Override
        public EntityDiagram evaluate(DBRProgressMonitor monitor) {
            try {
                return loadContentFromFile(monitor);
            } catch (DBException e) {
                log.error(e);
            }
            return null;
        }

        @Override
        public Object getFamily() {
            return ERDEditorStandalone.this;
        }
    }, progressControl.createLoadVisualizer());
    diagramLoadingJob.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            diagramLoadingJob = null;
        }
    });
    diagramLoadingJob.schedule();
    setPartName(getEditorInput().getName());
}
Also used : DBException(org.jkiss.dbeaver.DBException) AbstractLoadService(org.jkiss.dbeaver.model.runtime.load.AbstractLoadService) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent)

Example 63 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project dbeaver by serge-rider.

the class ExasolBaseTableToolDialog method executeSQL.

@Override
protected void executeSQL() {
    final String jobName = getShell().getText();
    final SQLScriptProgressListener<ExasolTableBase> scriptListener = getScriptListener();
    final List<ExasolTableBase> objects = getCheckedObjects();
    final Map<ExasolTableBase, List<String>> objectsSQL = new LinkedHashMap<>();
    for (ExasolTableBase object : objects) {
        final List<String> lines = new ArrayList<>();
        generateObjectCommand(lines, object);
        objectsSQL.put(object, lines);
    }
    final DataSourceJob job = new DataSourceJob(jobName, getExecutionContext()) {

        Exception objectProcessingError;

        @SuppressWarnings("rawtypes")
        @Override
        protected IStatus run(final DBRProgressMonitor monitor) {
            final DataSourceJob curJob = this;
            UIUtils.asyncExec(() -> scriptListener.beginScriptProcessing(curJob, objects));
            monitor.beginTask(jobName, objects.size());
            try (DBCSession session = getExecutionContext().openSession(monitor, DBCExecutionPurpose.UTIL, jobName)) {
                for (int i = 0; i < objects.size(); i++) {
                    if (monitor.isCanceled()) {
                        break;
                    }
                    final int objectNumber = i;
                    final ExasolTableBase object = objects.get(i);
                    monitor.subTask("Process " + DBUtils.getObjectFullName(object, DBPEvaluationContext.UI));
                    objectProcessingError = null;
                    UIUtils.asyncExec(() -> scriptListener.beginObjectProcessing(object, objectNumber));
                    try {
                        final List<String> lines = objectsSQL.get(object);
                        for (String line : lines) {
                            try (final Statement statement = ((JDBCSession) session).getOriginal().createStatement()) {
                                int affectedRows = statement.executeUpdate(line);
                                Integer[] resultSetData = new Integer[] { affectedRows };
                                final LocalResultSet resultSet = new LocalResultSet<>(session, new JDBCStatementImpl<>((JDBCSession) session, statement, true));
                                resultSet.addColumn("ROWS_AFFECTED", DBPDataKind.NUMERIC);
                                resultSet.addRow((Object[]) resultSetData);
                                // Run in sync because we need result set
                                UIUtils.syncExec(() -> {
                                    try {
                                        scriptListener.processObjectResults(object, null, resultSet);
                                    } catch (DBCException e) {
                                        objectProcessingError = e;
                                    }
                                });
                                if (objectProcessingError != null) {
                                    break;
                                }
                            }
                        }
                    } catch (Exception e) {
                        objectProcessingError = e;
                    } finally {
                        UIUtils.asyncExec(() -> scriptListener.endObjectProcessing(object, objectProcessingError));
                    }
                    monitor.worked(1);
                }
            } finally {
                monitor.done();
                UIUtils.asyncExec(scriptListener::endScriptProcessing);
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(false);
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
        }
    });
    job.schedule();
}
Also used : LocalResultSet(org.jkiss.dbeaver.model.impl.local.LocalResultSet) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) Statement(java.sql.Statement) ExasolTableBase(org.jkiss.dbeaver.ext.exasol.model.ExasolTableBase) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) DataSourceJob(org.jkiss.dbeaver.runtime.jobs.DataSourceJob) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Example 64 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project dbeaver by serge-rider.

the class DBGJDBCSession method runAsync.

/**
 * Start thread for SQL command
 */
protected void runAsync(String commandSQL, String name, DBGEvent begin, DBGEvent end) throws DBGException {
    workerJob = new DBGJDBCWorker(this, name, commandSQL, begin, end);
    workerJob.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            workerJob = null;
        }
    });
    workerJob.schedule();
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent)

Example 65 with IJobChangeEvent

use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project dbeaver by serge-rider.

the class PropertySourceAbstract method getPropertyValue.

@Override
public Object getPropertyValue(@Nullable DBRProgressMonitor monitor, final Object object, final ObjectPropertyDescriptor prop, boolean formatValue) {
    try {
        if (monitor == null && prop.isLazy(object, true) && !prop.supportsPreview()) {
            final Object value = lazyValues.get(prop.getId());
            if (value != null) {
                return value;
            }
            if (lazyValues.containsKey(prop.getId())) {
                // Some lazy props has null value
                return null;
            }
            if (!loadLazyProps) {
                return null;
            } else {
                synchronized (lazyProps) {
                    lazyProps.add(prop);
                    if (lazyLoadJob == null) {
                        // We assume that it can be called ONLY by properties viewer
                        // So, start lazy loading job to update it after value will be loaded
                        lazyLoadJob = DBWorkbench.getPlatformUI().createLoadingService(new PropertyValueLoadService(), new PropertyValueLoadVisualizer());
                        lazyLoadJob.addJobChangeListener(new JobChangeAdapter() {

                            @Override
                            public void done(IJobChangeEvent event) {
                                synchronized (lazyProps) {
                                    if (!lazyProps.isEmpty()) {
                                        lazyLoadJob.schedule(100);
                                    } else {
                                        lazyLoadJob = null;
                                    }
                                }
                            }
                        });
                        lazyLoadJob.schedule(100);
                    }
                }
                // Return dummy string for now
                lazyValues.put(prop.getId(), null);
                return null;
            }
        } else {
            return prop.readValue(object, monitor, formatValue);
        }
    } catch (Throwable e) {
        if (e instanceof InvocationTargetException) {
            e = ((InvocationTargetException) e).getTargetException();
        }
        log.error("Error reading property '" + prop.getId() + "' from " + object, e);
        return e.getMessage();
    }
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)172 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)163 Job (org.eclipse.core.runtime.jobs.Job)46 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)45 IStatus (org.eclipse.core.runtime.IStatus)36 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)30 ArrayList (java.util.ArrayList)13 IFile (org.eclipse.core.resources.IFile)13 File (java.io.File)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 CoreException (org.eclipse.core.runtime.CoreException)12 DataSourceJob (org.jkiss.dbeaver.runtime.jobs.DataSourceJob)12 Status (org.eclipse.core.runtime.Status)11 IJobChangeListener (org.eclipse.core.runtime.jobs.IJobChangeListener)11 IOException (java.io.IOException)10 DBException (org.jkiss.dbeaver.DBException)10 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)10 IProject (org.eclipse.core.resources.IProject)9 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)8 Composite (org.eclipse.swt.widgets.Composite)7