use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by dbeaver.
the class SQLScriptExecuteHandler method runScripts.
private void runScripts(DBRProgressMonitor monitor, DBTTask task, SQLScriptExecuteSettings settings, Log log, PrintStream logStream) throws DBException {
List<DBPDataSourceContainer> dataSources = settings.getDataSources();
for (String filePath : settings.getScriptFiles()) {
IFile sqlFile = SQLScriptExecuteSettings.getWorkspaceFile(filePath);
try (InputStream sqlStream = sqlFile.getContents(true)) {
try (Reader fileReader = new InputStreamReader(sqlStream, sqlFile.getCharset())) {
String sqlScriptContent = IOUtils.readToString(fileReader);
try {
for (DBPDataSourceContainer dataSourceContainer : dataSources) {
if (!dataSourceContainer.isConnected()) {
dataSourceContainer.connect(monitor, true, true);
}
DBPDataSource dataSource = dataSourceContainer.getDataSource();
if (dataSource == null) {
throw new DBException("Can't obtain data source connection");
}
DBCExecutionContext executionContext = dataSource.getDefaultInstance().getDefaultContext(monitor, false);
log.debug("> Execute script [" + filePath + "] in [" + dataSourceContainer.getName() + "]");
DBCExecutionContextDefaults contextDefaults = executionContext.getContextDefaults();
if (contextDefaults != null) {
DBSCatalog defaultCatalog = contextDefaults.getDefaultCatalog();
if (defaultCatalog != null) {
log.debug("> Default catalog: " + defaultCatalog.getName());
}
DBSSchema defaultSchema = contextDefaults.getDefaultSchema();
if (defaultSchema != null) {
log.debug("> Default schema: " + defaultSchema.getName());
}
}
processScript(monitor, task, settings, executionContext, filePath, sqlScriptContent, log, logStream);
}
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
} catch (Throwable e) {
Throwable error = e instanceof InvocationTargetException ? ((InvocationTargetException) e).getTargetException() : e;
throw new DBException("Error executing script '" + filePath + "'", error);
}
}
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext 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.exec.DBCExecutionContext in project dbeaver by serge-rider.
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 serge-rider.
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);
}
use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.
the class TransactionInfoDialog method updateTransactionFilter.
protected void updateTransactionFilter() {
DBCExecutionContext context = getCurrentContext();
QMEventFilter filter = context == null ? VOID_FILTER : createContextFilter(context);
logViewer.setFilter(filter);
logViewer.refresh();
}
Aggregations