use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project dbeaver by serge-rider.
the class QueryLogViewer method preferenceChange.
@Override
public synchronized void preferenceChange(PreferenceChangeEvent event) {
if (event.getProperty().startsWith(QMConstants.PROP_PREFIX)) {
// So here we just schedule single refresh job
if (configRefreshJob == null) {
configRefreshJob = new ConfigRefreshJob();
configRefreshJob.schedule(250);
configRefreshJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
configRefreshJob = null;
}
});
}
}
}
use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project dbeaver by serge-rider.
the class DataSourceHandler method disconnectDataSource.
public static void disconnectDataSource(DBPDataSourceContainer dataSourceContainer, @Nullable final Runnable onFinish) {
// Save users
for (DBPDataSourceUser user : dataSourceContainer.getUsers()) {
if (user instanceof ISaveablePart) {
if (!SaveChangesHandler.validateAndSave(VoidProgressMonitor.INSTANCE, (ISaveablePart) user)) {
return;
}
}
}
if (!checkAndCloseActiveTransaction(dataSourceContainer)) {
return;
}
if (dataSourceContainer instanceof DataSourceDescriptor && dataSourceContainer.isConnected()) {
final DataSourceDescriptor dataSourceDescriptor = (DataSourceDescriptor) dataSourceContainer;
if (!ArrayUtils.isEmpty(Job.getJobManager().find(dataSourceDescriptor))) {
// Already connecting/disconnecting - just return
return;
}
final DisconnectJob disconnectJob = new DisconnectJob(dataSourceDescriptor);
disconnectJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
IStatus result = disconnectJob.getConnectStatus();
if (onFinish != null) {
onFinish.run();
} else if (!result.isOK()) {
UIUtils.showErrorDialog(null, disconnectJob.getName(), null, result);
}
}
});
// Run in UI thread to update actions (some Eclipse magic)
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
disconnectJob.schedule();
}
});
}
}
use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project dbeaver by serge-rider.
the class DataSourceInvalidateHandler method execute.
public static void execute(final Shell shell, final DBCExecutionContext context) {
if (context != null) {
//final DataSourceDescriptor dataSourceDescriptor = (DataSourceDescriptor) context;
if (!ArrayUtils.isEmpty(Job.getJobManager().find(context.getDataSource().getContainer()))) {
// Already connecting/disconnecting - just return
return;
}
final InvalidateJob invalidateJob = new InvalidateJob(context);
invalidateJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
StringBuilder message = new StringBuilder();
Throwable error = null;
int totalNum = 0, connectedNum = 0, aliveNum = 0;
for (InvalidateJob.ContextInvalidateResult result : invalidateJob.getInvalidateResults()) {
totalNum++;
if (result.error != null) {
error = result.error;
}
switch(result.result) {
case CONNECTED:
case RECONNECTED:
connectedNum++;
break;
case ALIVE:
aliveNum++;
break;
default:
break;
}
}
if (connectedNum > 0) {
message.insert(0, "Connections reopened: " + connectedNum + " (of " + totalNum + ")");
} else if (message.length() == 0) {
message.insert(0, "All connections (" + totalNum + ") are alive!");
}
if (error != null) {
// UIUtils.showErrorDialog(
// shell,
// "Invalidate data source [" + context.getDataSource().getContainer().getName() + "]",
// "Error while connecting to the datasource",// + "\nTime spent: " + RuntimeUtils.formatExecutionTime(invalidateJob.getTimeSpent()),
// error);
DBeaverUI.syncExec(new Runnable() {
@Override
public void run() {
}
});
final DBPDataSourceContainer container = context.getDataSource().getContainer();
final Throwable dialogError = error;
final Integer result = new UITask<Integer>() {
@Override
protected Integer runTask() {
ConnectionLostDialog clDialog = new ConnectionLostDialog(shell, container, dialogError, "Disconnect");
return clDialog.open();
}
}.execute();
if (result == IDialogConstants.STOP_ID) {
// Disconnect - to notify UI and reflect model changes
new DisconnectJob(container).schedule();
} else if (result == IDialogConstants.RETRY_ID) {
execute(shell, context);
}
} else {
log.info(message);
}
}
});
invalidateJob.schedule();
}
}
use of org.eclipse.core.runtime.jobs.JobChangeAdapter 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, null, getExecutionContext()) {
public Exception objectProcessingError;
@SuppressWarnings("rawtypes")
@Override
protected IStatus run(final DBRProgressMonitor monitor) {
final DataSourceJob curJob = this;
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
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;
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
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
DBeaverUI.syncExec(new Runnable() {
@Override
public void run() {
try {
scriptListener.processObjectResults(object, null, resultSet);
} catch (DBCException e) {
objectProcessingError = e;
}
}
});
if (objectProcessingError != null) {
break;
}
}
}
} catch (Exception e) {
objectProcessingError = e;
} finally {
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
scriptListener.endObjectProcessing(object, objectProcessingError);
}
});
}
monitor.worked(1);
}
} finally {
monitor.done();
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
scriptListener.endScriptProcessing();
}
});
}
return Status.OK_STATUS;
}
};
job.setUser(false);
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
}
});
job.schedule();
}
use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project dbeaver by serge-rider.
the class GenerateMultiSQLDialog method executeSQL.
@Override
protected void executeSQL() {
final String jobName = getShell().getText();
final SQLScriptProgressListener<T> scriptListener = getScriptListener();
final List<T> objects = getCheckedObjects();
final Map<T, List<String>> objectsSQL = new LinkedHashMap<>();
for (T object : objects) {
final List<String> lines = new ArrayList<>();
generateObjectCommand(lines, object);
objectsSQL.put(object, lines);
}
final DataSourceJob job = new DataSourceJob(jobName, null, getExecutionContext()) {
public Exception objectProcessingError;
@Override
protected IStatus run(final DBRProgressMonitor monitor) {
final DataSourceJob curJob = this;
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
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 T object = objects.get(i);
monitor.subTask("Process " + DBUtils.getObjectFullName(object, DBPEvaluationContext.UI));
objectProcessingError = null;
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
scriptListener.beginObjectProcessing(object, objectNumber);
}
});
try {
final List<String> lines = objectsSQL.get(object);
for (String line : lines) {
try (final DBCStatement statement = DBUtils.makeStatement(session, line, false)) {
if (statement.executeStatement()) {
try (DBCResultSet resultSet = statement.openResultSet()) {
// Run in sync because we need result set
DBeaverUI.syncExec(new Runnable() {
@Override
public void run() {
try {
scriptListener.processObjectResults(object, statement, resultSet);
} catch (DBCException e) {
objectProcessingError = e;
}
}
});
}
if (objectProcessingError != null) {
break;
}
} else {
DBeaverUI.syncExec(new Runnable() {
@Override
public void run() {
try {
scriptListener.processObjectResults(object, statement, null);
} catch (DBCException e) {
objectProcessingError = e;
}
}
});
}
}
}
} catch (Exception e) {
objectProcessingError = e;
} finally {
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
scriptListener.endObjectProcessing(object, objectProcessingError);
}
});
}
monitor.worked(1);
}
} finally {
monitor.done();
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
scriptListener.endScriptProcessing();
}
});
}
return Status.OK_STATUS;
}
};
job.setUser(false);
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
}
});
job.schedule();
}
Aggregations