use of org.jkiss.dbeaver.model.exec.DBCExecutionContext 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.exec.DBCExecutionContext in project dbeaver by serge-rider.
the class DatabaseEditorInputFactory method saveState.
public static void saveState(IMemento memento, DatabaseEditorInput input) {
if (!DBWorkbench.getPlatform().getPreferenceStore().getBoolean(DatabaseEditorPreferences.PROP_SAVE_EDITORS_STATE)) {
return;
}
final DBCExecutionContext context = input.getExecutionContext();
if (context == null) {
// Detached - nothing to save
return;
}
if (input.getDatabaseObject() != null && !input.getDatabaseObject().isPersisted()) {
return;
}
final DBNDatabaseNode node = input.getNavigatorNode();
memento.putString(TAG_CLASS, input.getClass().getName());
memento.putString(TAG_PROJECT, context.getDataSource().getContainer().getProject().getName());
memento.putString(TAG_DATA_SOURCE, context.getDataSource().getContainer().getId());
memento.putString(TAG_NODE, node.getNodeItemPath());
memento.putString(TAG_NODE_NAME, node.getNodeName());
if (!CommonUtils.isEmpty(input.getDefaultPageId())) {
memento.putString(TAG_ACTIVE_PAGE, input.getDefaultPageId());
}
if (!CommonUtils.isEmpty(input.getDefaultFolderId())) {
memento.putString(TAG_ACTIVE_FOLDER, input.getDefaultFolderId());
}
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.
the class AbstractSessionEditor method createEditorControl.
@Override
public void createEditorControl(Composite parent) {
final DBCExecutionContext executionContext = getExecutionContext();
if (executionContext != null) {
setPartName("Sessions - " + executionContext.getDataSource().getContainer().getName());
sessionsViewer = createSessionViewer(executionContext, parent);
sessionsViewer.loadSettings(this);
sessionsViewer.refreshSessions();
}
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.
the class SQLEditorBase method scrollCursorToError.
/**
* Error handling
*/
boolean scrollCursorToError(@NotNull DBRProgressMonitor monitor, @NotNull SQLQuery query, @NotNull Throwable error) {
try {
DBCExecutionContext context = getExecutionContext();
if (context == null) {
return false;
}
boolean scrolled = false;
DBPErrorAssistant errorAssistant = DBUtils.getAdapter(DBPErrorAssistant.class, context.getDataSource());
if (errorAssistant != null) {
DBPErrorAssistant.ErrorPosition[] positions = errorAssistant.getErrorPosition(monitor, context, query.getText(), error);
if (positions != null && positions.length > 0) {
int queryStartOffset = query.getOffset();
int queryLength = query.getLength();
DBPErrorAssistant.ErrorPosition pos = positions[0];
if (pos.line < 0) {
if (pos.position >= 0) {
// Only position
getSelectionProvider().setSelection(new TextSelection(queryStartOffset + pos.position, 0));
scrolled = true;
}
} else {
// Line + position
IDocument document = getDocument();
if (document != null) {
int startLine = document.getLineOfOffset(queryStartOffset);
int errorOffset = document.getLineOffset(startLine + pos.line);
int errorLength;
if (pos.position >= 0) {
errorOffset += pos.position;
errorLength = 1;
} else {
errorLength = document.getLineLength(startLine + pos.line);
}
if (errorOffset < queryStartOffset)
errorOffset = queryStartOffset;
if (errorLength > queryLength)
errorLength = queryLength;
if (errorOffset >= queryStartOffset + queryLength) {
// This may happen if error position was incorrectly detected.
// E.g. in SQL Server when actual error happened in some stored procedure.
errorOffset = queryStartOffset + queryLength - 1;
}
getSelectionProvider().setSelection(new TextSelection(errorOffset, errorLength));
scrolled = true;
}
}
}
}
return scrolled;
// if (!scrolled) {
// // Can't position on error - let's just select entire problem query
// showStatementInEditor(result.getStatement(), true);
// }
} catch (Exception e) {
log.warn("Error positioning on query error", e);
return false;
}
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by dbeaver.
the class TransactionInfoDialog method createTransactionLogPanel.
protected void createTransactionLogPanel(Composite composite) {
DBCExecutionContext context = getCurrentContext();
QMEventFilter filter = context == null ? VOID_FILTER : createContextFilter(context);
logViewer = new QueryLogViewer(composite, activeEditor.getSite(), filter, false, true);
logViewer.setUseDefaultFilter(false);
final Object gd = logViewer.getControl().getLayoutData();
if (gd instanceof GridData) {
((GridData) gd).heightHint = logViewer.getControl().getHeaderHeight() + logViewer.getControl().getItemHeight() * 5;
}
showAllCheck = UIUtils.createCheckbox(composite, CoreMessages.transaction_info_dialog_checkbox_show_all_queries, CoreMessages.transaction_info_dialog_label_show_all_transaction_queries, false, 1);
showAllCheck.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
updateTransactionFilter();
}
});
showPreviousCheck = UIUtils.createCheckbox(composite, CoreMessages.transaction_info_dialog_checkbox_show_previous_transactions, CoreMessages.transaction_info_dialog_label_otherwise, false, 1);
showPreviousCheck.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
updateTransactionFilter();
}
});
closeOnFocusLost(logViewer.getSearchText(), logViewer.getControl(), showAllCheck, showPreviousCheck);
}
Aggregations