use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by dbeaver.
the class DataSourceAutoCommitHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
DBCExecutionContext context = getActiveExecutionContext(event, true);
if (context != null) {
DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
if (txnManager != null) {
try {
final DBPDataSourceContainer container = context.getDataSource().getContainer();
boolean newAutocommit = !container.isDefaultAutoCommit();
if (context.isConnected()) {
// Get flag from connection
newAutocommit = !txnManager.isAutoCommit();
}
boolean autoCommit = newAutocommit;
new AbstractJob("Set auto-commit") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
monitor.beginTask("Change connection auto-commit to " + autoCommit, 1);
try {
monitor.subTask("Change context '" + context.getContextName() + "' auto-commit state");
txnManager.setAutoCommit(monitor, autoCommit);
} catch (Exception e) {
return GeneralUtils.makeExceptionStatus(e);
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
}.schedule();
} catch (DBException e) {
DBWorkbench.getPlatformUI().showError("Auto-Commit", "Error while toggle auto-commit", e);
}
}
}
return null;
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by dbeaver.
the class PendingTransactionsDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
contextTree = new Tree(composite, SWT.FULL_SELECTION | SWT.BORDER);
contextTree.setHeaderVisible(true);
contextTree.setLinesVisible(true);
TreeColumn colName = new TreeColumn(contextTree, SWT.NONE);
colName.setText("Connection");
TreeColumn colTxn = new TreeColumn(contextTree, SWT.RIGHT);
colTxn.setText("Transaction");
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = contextTree.getHeaderHeight() + contextTree.getItemHeight() * 5;
contextTree.setLayoutData(gd);
contextTree.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (e.item != null && e.item.getData() instanceof DBCExecutionContext) {
selectedContext = (DBCExecutionContext) e.item.getData();
} else {
selectedContext = null;
}
boolean hasTransaction = selectedContext != null && QMUtils.isTransactionActive(selectedContext, false);
commitButton.setEnabled(hasTransaction);
rollbackButton.setEnabled(hasTransaction);
logViewer.setFilter(createContextFilter(selectedContext));
logViewer.refresh();
}
});
closeOnFocusLost(contextTree);
{
Composite controlPanel = UIUtils.createPlaceholder(composite, 3, 5);
controlPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
final Button showAllCheck = UIUtils.createCheckbox(controlPanel, "Show all connections", "Show all datasource connections. Otherwise shows only transactional connections.", false, 1);
showAllCheck.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
loadContexts(showAllCheck.getSelection());
}
});
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.grabExcessHorizontalSpace = true;
showAllCheck.setLayoutData(gd);
commitButton = UIUtils.createPushButton(controlPanel, "Commit", DBeaverIcons.getImage(UIIcon.TXN_COMMIT));
commitButton.setEnabled(false);
commitButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
endTransaction(true);
}
});
rollbackButton = UIUtils.createPushButton(controlPanel, "Rollback", DBeaverIcons.getImage(UIIcon.TXN_ROLLBACK));
rollbackButton.setEnabled(false);
rollbackButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
endTransaction(false);
}
});
closeOnFocusLost(showAllCheck, commitButton, rollbackButton);
}
super.createTransactionLogPanel(composite);
loadContexts(false);
return parent;
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by dbeaver.
the class DataSourceTransactionModeContributor method fillContributionItems.
@Override
protected void fillContributionItems(final List<IContributionItem> menuItems) {
IEditorPart activePart = UIUtils.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
DBCExecutionContext executionContext = AbstractDataSourceHandler.getExecutionContextFromPart(activePart);
DBPDataSource dataSource = null;
if (executionContext != null) {
dataSource = executionContext.getDataSource();
}
if (dataSource == null) {
return;
}
final DBPDataSourceInfo dsInfo = dataSource.getInfo();
DBCTransactionManager txnManager = DBUtils.getTransactionManager(executionContext);
if (txnManager != null) {
boolean autoCommit = false;
try {
autoCommit = txnManager.isAutoCommit();
} catch (DBCException e) {
log.warn("Can't determine current auto-commit mode", e);
}
// Transactions
DBPTransactionIsolation txnLevelCurrent = null;
try {
txnLevelCurrent = txnManager.getTransactionIsolation();
} catch (DBCException ex) {
log.warn("Can't determine current transaction isolation level", ex);
}
menuItems.add(ActionUtils.makeActionContribution(new TransactionAutoCommitAction(executionContext, true, autoCommit, txnLevelCurrent), true));
menuItems.add(ActionUtils.makeActionContribution(new TransactionAutoCommitAction(executionContext, false, !autoCommit, txnLevelCurrent), true));
ISmartTransactionManager smartTransactionManager = DBUtils.getAdapter(ISmartTransactionManager.class, activePart);
menuItems.add(ActionUtils.makeActionContribution(new SmartAutoCommitAction(dataSource, smartTransactionManager), true));
menuItems.add(new Separator());
for (DBPTransactionIsolation txi : CommonUtils.safeCollection(dsInfo.getSupportedTransactionsIsolation())) {
if (!txi.isEnabled()) {
continue;
}
menuItems.add(ActionUtils.makeActionContribution(new TransactionIsolationAction(executionContext, txi, txi.equals(txnLevelCurrent)), true));
}
}
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by dbeaver.
the class DataSourceTransactionLogHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final Shell activeShell = HandlerUtil.getActiveShell(event);
IEditorPart editor = HandlerUtil.getActiveEditor(event);
DBCExecutionContext context = null;
if (editor instanceof DBPContextProvider) {
context = ((DBPContextProvider) editor).getExecutionContext();
}
TransactionLogDialog.showDialog(activeShell, context);
return null;
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by dbeaver.
the class DatabaseConsumerPageMapping method showDDL.
private void showDDL(DatabaseMappingContainer mapping) {
final DatabaseConsumerSettings settings = getDatabaseConsumerSettings();
final DBSObjectContainer container = settings.getContainer();
if (container == null) {
return;
}
DBPDataSource dataSource = container.getDataSource();
final DBEPersistAction[][] ddl = new DBEPersistAction[1][];
try {
getWizard().getRunnableContext().run(true, true, monitor -> {
monitor.beginTask(DTUIMessages.database_consumer_page_mapping_monitor_task, 1);
try {
DBCExecutionContext executionContext = DBUtils.getDefaultContext(dataSource, true);
ddl[0] = DatabaseTransferUtils.generateTargetTableDDL(monitor, executionContext, container, mapping);
} catch (DBException e) {
throw new InvocationTargetException(e);
}
monitor.done();
});
} catch (InvocationTargetException e) {
DBWorkbench.getPlatformUI().showError(DTUIMessages.database_consumer_page_mapping_title_target_DDL, DTUIMessages.database_consumer_page_mapping_message_error_generating_target_DDL, e);
return;
} catch (InterruptedException e) {
return;
}
DBEPersistAction[] persistActions = ddl[0];
if (ArrayUtils.isEmpty(persistActions)) {
UIUtils.showMessageBox(getShell(), "No schema changes", "No changes are needed for this mapping", SWT.ICON_INFORMATION);
return;
}
UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
if (serviceSQL != null) {
String sql = SQLUtils.generateScript(dataSource, persistActions, false);
int result = serviceSQL.openSQLViewer(DBUtils.getDefaultContext(container, true), DTUIMessages.database_consumer_page_mapping_sqlviewer_title, null, sql, dataSource.getContainer().hasModifyPermission(DBPDataSourcePermission.PERMISSION_EDIT_METADATA), false);
if (result == IDialogConstants.PROCEED_ID) {
if (UIUtils.confirmAction(getShell(), "Create target objects", "Database metadata will be modified by creating new table(s) and column(s).\nAre you sure you want to proceed?")) {
// Create target objects
if (applySchemaChanges(dataSource, mapping, persistActions)) {
autoAssignMappings();
updateMappingsAndButtons();
}
}
}
}
}
Aggregations