use of org.jkiss.dbeaver.model.DBPTransactionIsolation in project dbeaver by dbeaver.
the class DataSourceAutoCommitHandler method updateElement.
@Override
public void updateElement(UIElement element, Map parameters) {
IWorkbenchWindow workbenchWindow = element.getServiceLocator().getService(IWorkbenchWindow.class);
if (workbenchWindow == null || workbenchWindow.getActivePage() == null) {
return;
}
IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor();
if (activeEditor == null) {
return;
}
boolean autoCommit = true;
DBPTransactionIsolation isolation = null;
DBCExecutionContext context = getExecutionContext(activeEditor);
if (context != null && context.isConnected()) {
DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
if (txnManager != null) {
try {
// Change auto-commit mode
autoCommit = txnManager.isAutoCommit();
isolation = txnManager.getTransactionIsolation();
} catch (DBCException e) {
log.warn(e);
}
}
} else if (activeEditor instanceof IDataSourceContainerProvider) {
DBPDataSourceContainer container = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
if (container != null) {
autoCommit = container.isDefaultAutoCommit();
isolation = container.getActiveTransactionsIsolation();
}
}
element.setChecked(autoCommit);
// Update command image
element.setIcon(DBeaverIcons.getImageDescriptor(autoCommit ? UIIcon.TXN_COMMIT_AUTO : UIIcon.TXN_COMMIT_MANUAL));
String isolationName = isolation == null ? "?" : isolation.getTitle();
String text = autoCommit ? "Switch to manual commit (" + isolationName + ")" : "Switch to auto-commit";
element.setText(text);
element.setTooltip(text);
}
use of org.jkiss.dbeaver.model.DBPTransactionIsolation in project dbeaver by serge-rider.
the class DataSourceAutoCommitHandler method updateElement.
@Override
public void updateElement(UIElement element, Map parameters) {
IWorkbenchWindow workbenchWindow = element.getServiceLocator().getService(IWorkbenchWindow.class);
if (workbenchWindow == null || workbenchWindow.getActivePage() == null) {
return;
}
IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor();
if (activeEditor == null) {
return;
}
boolean autoCommit = true;
DBPTransactionIsolation isolation = null;
DBCExecutionContext context = getExecutionContextFromPart(activeEditor);
if (context != null && context.isConnected()) {
DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
if (txnManager != null) {
try {
// Change auto-commit mode
autoCommit = txnManager.isAutoCommit();
isolation = txnManager.getTransactionIsolation();
} catch (DBCException e) {
log.warn(e);
}
}
} else if (activeEditor instanceof IDataSourceContainerProvider) {
DBPDataSourceContainer container = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
if (container != null) {
autoCommit = container.isDefaultAutoCommit();
isolation = container.getActiveTransactionsIsolation();
}
}
element.setChecked(autoCommit);
// Update command image
element.setIcon(DBeaverIcons.getImageDescriptor(autoCommit ? UIIcon.TXN_COMMIT_AUTO : UIIcon.TXN_COMMIT_MANUAL));
String isolationName = isolation == null ? "?" : isolation.getTitle();
String text = autoCommit ? NLS.bind(CoreMessages.action_menu_transaction_manualcommit_name, isolationName) : CoreMessages.action_menu_transaction_autocommit_name;
element.setText(text);
element.setTooltip(text);
}
use of org.jkiss.dbeaver.model.DBPTransactionIsolation in project dbeaver by serge-rider.
the class ConnectionPageInitialization method loadDatabaseSettings.
private void loadDatabaseSettings(DBRProgressMonitor monitor, DBPDataSource dataSource) {
DBPDataSourceContainer dataSourceContainer = dataSource.getContainer();
Collection<DBPTransactionIsolation> txnLevels = CommonUtils.safeCollection(dataSource.getInfo().getSupportedTransactionsIsolation());
Integer levelCode = dataSourceContainer.getDefaultTransactionsIsolation();
UIUtils.syncExec(() -> {
autocommit.setSelection(dataSourceContainer.isDefaultAutoCommit());
// isolationLevel.setEnabled(!autocommit.getSelection());
supportedLevels.clear();
DBPTransactionIsolation defaultLevel = null;
{
if (levelCode != null && !CommonUtils.isEmpty(txnLevels)) {
for (DBPTransactionIsolation level : txnLevels) {
if (level.getCode() == levelCode) {
defaultLevel = level;
break;
}
}
}
}
isolationLevel.removeAll();
supportedLevels.clear();
for (DBPTransactionIsolation level : txnLevels) {
if (!level.isEnabled()) {
continue;
}
isolationLevel.add(level.getTitle());
supportedLevels.add(level);
if (level.equals(defaultLevel)) {
isolationLevel.select(isolationLevel.getItemCount() - 1);
}
}
});
if (dataSource instanceof DBSObjectContainer) {
DBCExecutionContext executionContext = DBUtils.getDefaultContext(dataSource, true);
DBCExecutionContextDefaults contextDefaults = executionContext.getContextDefaults();
DBSObjectContainer catalogContainer = DBUtils.getChangeableObjectContainer(contextDefaults, (DBSObjectContainer) dataSource, DBSCatalog.class);
if (catalogContainer != null) {
loadSelectableObject(monitor, catalogContainer, defaultCatalog, contextDefaults, true);
}
DBSObjectContainer schemaContainer = DBUtils.getChangeableObjectContainer(contextDefaults, (DBSObjectContainer) dataSource, DBSSchema.class);
loadSelectableObject(monitor, schemaContainer, defaultSchema, contextDefaults, false);
}
txnOptionsLoaded = true;
}
use of org.jkiss.dbeaver.model.DBPTransactionIsolation in project dbeaver by serge-rider.
the class DBTaskUtils method extractContext.
public static DBTTaskContext extractContext(@NotNull DBCExecutionContext executionContext) {
DBTTaskContext context = new DBTTaskContext();
DBCExecutionContextDefaults defaults = executionContext.getContextDefaults();
if (defaults != null) {
DBSCatalog defaultCatalog = defaults.getDefaultCatalog();
if (defaultCatalog != null) {
context.setDefaultCatalog(defaultCatalog.getName());
}
DBSSchema defaultSchema = defaults.getDefaultSchema();
if (defaultSchema != null) {
context.setDefaultSchema(defaultSchema.getName());
}
}
DBCTransactionManager txnManager = DBUtils.getTransactionManager(executionContext);
if (txnManager != null) {
try {
context.setAutoCommit(txnManager.isAutoCommit());
DBPTransactionIsolation isolation = txnManager.getTransactionIsolation();
if (isolation != null) {
context.setTransactionIsolation(isolation.getCode());
}
} catch (Throwable e) {
log.debug(e);
}
}
return context;
}
Aggregations