use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class EditForeignKeyPage method handleRefTableSelect.
private void handleRefTableSelect(ISelection selection) {
DBNDatabaseNode refTableNode = null;
if (!selection.isEmpty() && selection instanceof IStructuredSelection && ((IStructuredSelection) selection).size() == 1) {
final Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof DBNDatabaseNode && ((DBNDatabaseNode) element).getObject() instanceof DBSTable && ((DBNDatabaseNode) element).getObject().isPersisted()) {
refTableNode = (DBNDatabaseNode) element;
}
}
if (refTableNode != null) {
if (refTableNode.getObject() == curRefTable) {
// The same selection
return;
} else {
curRefTable = (DBSTable) refTableNode.getObject();
}
}
uniqueKeyCombo.removeAll();
try {
curConstraints = new ArrayList<>();
curConstraint = null;
if (refTableNode != null) {
final DBSTable refTable = (DBSTable) refTableNode.getObject();
DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
// Cache own table columns
ownTable.getAttributes(monitor);
// Cache ref table columns
refTable.getAttributes(monitor);
// Get constraints
final Collection<? extends DBSTableConstraint> constraints = refTable.getConstraints(monitor);
if (!CommonUtils.isEmpty(constraints)) {
for (DBSTableConstraint constraint : constraints) {
if (constraint.getConstraintType().isUnique()) {
curConstraints.add(constraint);
}
}
}
} catch (DBException e) {
throw new InvocationTargetException(e);
}
}
});
}
for (DBSTableConstraint constraint : curConstraints) {
uniqueKeyCombo.add(constraint.getName());
}
uniqueKeyCombo.select(0);
uniqueKeyCombo.setEnabled(curConstraints.size() > 1);
if (curConstraints.size() == 1) {
curConstraint = curConstraints.get(0);
}
} catch (InvocationTargetException e) {
UIUtils.showErrorDialog(getShell(), CoreMessages.dialog_struct_edit_fk_error_load_constraints_title, CoreMessages.dialog_struct_edit_fk_error_load_constraints_message, e.getTargetException());
} catch (InterruptedException e) {
// do nothing
}
handleUniqueKeySelect();
updatePageState();
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class MySQLUserEditorGeneral method activatePart.
@Override
public void activatePart() {
if (isLoaded) {
return;
}
isLoaded = true;
LoadingJob.createService(new DatabaseLoadService<List<MySQLPrivilege>>(MySQLMessages.editors_user_editor_general_service_load_catalog_privileges, getExecutionContext()) {
@Override
public List<MySQLPrivilege> evaluate(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
final List<MySQLPrivilege> privList = getDatabaseObject().getDataSource().getPrivilegesByKind(monitor, MySQLPrivilege.Kind.ADMIN);
for (Iterator<MySQLPrivilege> iterator = privList.iterator(); iterator.hasNext(); ) {
MySQLPrivilege priv = iterator.next();
// Remove proxy (it is not singleton)
if (priv.getName().equalsIgnoreCase("proxy")) {
iterator.remove();
}
}
return privList;
} catch (DBException e) {
throw new InvocationTargetException(e);
}
}
}, pageControl.createLoadVisualizer()).schedule();
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor 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.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class GenericConnectionPage method createEmbeddedDatabase.
private void createEmbeddedDatabase() {
String paramCreate = CommonUtils.toString(site.getDriver().getDriverParameter(GenericConstants.PARAM_CREATE_URL_PARAM));
DataSourceDescriptor dataSource = (DataSourceDescriptor) site.getActiveDataSource();
final DataSourceDescriptor testDataSource = new DataSourceDescriptor(site.getDataSourceRegistry(), dataSource.getId(), dataSource.getDriver(), new DBPConnectionConfiguration(dataSource.getConnectionConfiguration()));
saveSettings(testDataSource);
DBPConnectionConfiguration cfg = testDataSource.getConnectionConfiguration();
cfg.setUrl(cfg.getUrl() + paramCreate);
String databaseName = cfg.getDatabaseName();
testDataSource.setName(databaseName);
if (!UIUtils.confirmAction(getShell(), "Create Database", "Are you sure you want to create database '" + databaseName + "'?")) {
testDataSource.dispose();
return;
}
try {
site.getRunnableContext().run(true, true, new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
createEmbeddedDatabase(monitor, testDataSource);
} catch (DBException e1) {
throw new InvocationTargetException(e1);
}
}
});
MessageDialog.openInformation(getShell(), "Database Create", "Database '" + databaseName + "' created!");
} catch (InvocationTargetException e1) {
UIUtils.showErrorDialog(getShell(), "Create database", "Error creating database", e1.getTargetException());
} catch (InterruptedException e1) {
// Just ignore
}
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class DriverPropertiesDialogPage method setVisible.
@Override
public void setVisible(boolean visible) {
super.setVisible(visible);
// Set props model
if (visible && propsControl != null) {
final DBPDataSourceContainer activeDataSource = site.getActiveDataSource();
if (prevConnectionInfo == activeDataSource.getConnectionConfiguration()) {
return;
}
final DBPConnectionConfiguration tmpConnectionInfo = new DBPConnectionConfiguration();
final DataSourceDescriptor tempDataSource = new DataSourceDescriptor(site.getDataSourceRegistry(), activeDataSource.getId(), (DriverDescriptor) activeDataSource.getDriver(), tmpConnectionInfo);
hostPage.saveSettings(tempDataSource);
tmpConnectionInfo.getProperties().putAll(activeDataSource.getConnectionConfiguration().getProperties());
try {
getSite().getRunnableContext().run(true, true, new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Loading driver properties", 1);
try {
propertySource = propsControl.makeProperties(monitor, site.getDriver(), tmpConnectionInfo);
} finally {
monitor.done();
}
}
});
} catch (InvocationTargetException e) {
setErrorMessage(e.getTargetException().getMessage());
} catch (InterruptedException e) {
// ignore
}
propsControl.loadProperties(propertySource);
prevConnectionInfo = activeDataSource.getConnectionConfiguration();
tempDataSource.dispose();
}
}
Aggregations