use of org.jkiss.dbeaver.runtime.sql.SQLQueryListener in project dbeaver by dbeaver.
the class SQLEditor method processQueries.
private void processQueries(@NotNull final List<SQLScriptElement> queries, final boolean newTab, final boolean export, final boolean checkSession, @Nullable final SQLQueryListener queryListener) {
if (queries.isEmpty()) {
// Nothing to process
return;
}
final DBPDataSourceContainer container = getDataSourceContainer();
if (checkSession) {
try {
DBRProgressListener connectListener = status -> {
if (!status.isOK() || container == null || !container.isConnected()) {
DBUserInterface.getInstance().showError(CoreMessages.editors_sql_error_cant_obtain_session, null, status);
return;
}
updateExecutionContext(new Runnable() {
@Override
public void run() {
DBeaverUI.syncExec(() -> processQueries(queries, newTab, export, false, queryListener));
}
});
};
if (!checkSession(connectListener)) {
return;
}
} catch (DBException ex) {
ResultSetViewer viewer = getActiveResultSetViewer();
if (viewer != null) {
viewer.setStatus(ex.getMessage(), DBPMessageType.ERROR);
}
DBUserInterface.getInstance().showError(CoreMessages.editors_sql_error_cant_obtain_session, ex.getMessage());
return;
}
}
if (dataSourceContainer == null) {
return;
}
final boolean isSingleQuery = (queries.size() == 1);
if (isSingleQuery && queries.get(0) instanceof SQLQuery) {
SQLQuery query = (SQLQuery) queries.get(0);
if (query.isDeleteUpdateDangerous()) {
String targetName = "multiple tables";
if (query.getSingleSource() != null) {
targetName = query.getSingleSource().getEntityName();
}
if (ConfirmationDialog.showConfirmDialogEx(getSite().getShell(), DBeaverPreferences.CONFIRM_DANGER_SQL, ConfirmationDialog.CONFIRM, ConfirmationDialog.WARNING, query.getType().name(), targetName) != IDialogConstants.OK_ID) {
return;
}
}
} else if (newTab && queries.size() > MAX_PARALLEL_QUERIES_NO_WARN) {
if (ConfirmationDialog.showConfirmDialogEx(getSite().getShell(), DBeaverPreferences.CONFIRM_MASS_PARALLEL_SQL, ConfirmationDialog.CONFIRM, ConfirmationDialog.WARNING, queries.size()) != IDialogConstants.OK_ID) {
return;
}
}
if (sashForm.getMaximizedControl() != null) {
sashForm.setMaximizedControl(null);
}
// Save editor
if (getActivePreferenceStore().getBoolean(SQLPreferenceConstants.AUTO_SAVE_ON_EXECUTE) && isDirty()) {
doSave(new NullProgressMonitor());
}
if (!newTab || !isSingleQuery) {
// We don't need new tab or we are executing a script - so close all extra tabs
closeExtraResultTabs(null);
}
if (newTab) {
// Execute each query in a new tab
for (int i = 0; i < queries.size(); i++) {
SQLScriptElement query = queries.get(i);
QueryProcessor queryProcessor = (i == 0 && !isSingleQuery ? curQueryProcessor : createQueryProcessor(queries.size() == 1));
queryProcessor.processQueries(Collections.singletonList(query), true, export, getActivePreferenceStore().getBoolean(SQLPreferenceConstants.RESULT_SET_CLOSE_ON_ERROR), queryListener);
}
} else {
// Use current tab.
// If current tab was pinned then use first tab
final QueryResultsContainer firstResults = curQueryProcessor.getFirstResults();
if (firstResults.isPinned()) {
curQueryProcessor = queryProcessors.get(0);
}
closeExtraResultTabs(curQueryProcessor);
if (firstResults.tabItem != null) {
// Do not switch tab if Output tab is active
CTabItem selectedTab = resultTabs.getSelection();
if (selectedTab == null || selectedTab.getData() != outputViewer) {
resultTabs.setSelection(firstResults.tabItem);
}
}
curQueryProcessor.processQueries(queries, false, export, false, queryListener);
}
}
Aggregations