use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by dbeaver.
the class SavePreviewDialog method populateSQL.
private void populateSQL() {
try {
final List<DBEPersistAction> sqlScript = new ArrayList<>();
UIUtils.runInProgressService(monitor -> {
List<DBEPersistAction> script = viewer.generateChangesScript(monitor, saveSettings);
if (script != null) {
sqlScript.addAll(script);
}
});
String scriptText = "";
if (!sqlScript.isEmpty()) {
scriptText = SQLUtils.generateScript(viewer.getDataSource(), sqlScript.toArray(new DBEPersistAction[0]), false);
scriptText = SQLUtils.generateCommentLine(viewer.getDataSource(), "Auto-generated SQL script. Actual values for binary/complex data types may differ - what you see is the default string representation of values.") + scriptText;
UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
if (serviceSQL != null) {
serviceSQL.setSQLPanelText(sqlPanel, scriptText);
}
}
} catch (Exception e) {
DBWorkbench.getPlatformUI().showError("Can't generalte SQL script", "Error generating SQL script from changes", e);
}
}
use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by dbeaver.
the class PostgreFDWConfigWizard method installFDW.
private void installFDW(DBRProgressMonitor monitor) throws DBException {
monitor.beginTask("Generate FDW script", 2);
monitor.subTask("Read actions");
List<DBEPersistAction> actions = generateScript(monitor);
monitor.subTask("Execute script");
DBCExecutionContext context = DBUtils.getDefaultContext(getDatabase(), false);
DBExecUtils.executeScript(monitor, context, "Install FDW", actions);
}
use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by dbeaver.
the class PostgreFDWConfigWizardPageFinal method generateScript.
private void generateScript() {
StringBuilder script = new StringBuilder();
try {
PostgreDataSource dataSource = getWizard().getDatabase().getDataSource();
getWizard().getRunnableContext().run(true, true, monitor -> {
try {
DBExecUtils.tryExecuteRecover(monitor, dataSource, param -> {
try {
monitor.beginTask("Generate FDW script", 2);
monitor.subTask("Read actions");
List<DBEPersistAction> actions = getWizard().generateScript(monitor);
monitor.subTask("Generate script");
script.append(SQLUtils.generateScript(dataSource, actions.toArray(new DBEPersistAction[0]), false));
monitor.done();
} catch (DBException e) {
throw new InvocationTargetException(e);
}
});
} catch (DBException e) {
throw new InvocationTargetException(e);
}
});
} catch (InvocationTargetException e) {
log.debug(e.getTargetException());
setErrorMessage(e.getTargetException().getMessage());
return;
} catch (InterruptedException e) {
return;
}
setErrorMessage(null);
scriptText = script.toString();
UIServiceSQL service = DBWorkbench.getService(UIServiceSQL.class);
if (service != null) {
service.setSQLPanelText(sqlPanel, scriptText);
}
}
use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by dbeaver.
the class DBExecUtils method executeScript.
public static void executeScript(DBCSession session, DBEPersistAction[] persistActions) {
DBRProgressMonitor monitor = session.getProgressMonitor();
boolean ignoreErrors = false;
monitor.beginTask(session.getTaskTitle(), persistActions.length);
try {
for (DBEPersistAction action : persistActions) {
if (monitor.isCanceled()) {
break;
}
if (!CommonUtils.isEmpty(action.getTitle())) {
monitor.subTask(action.getTitle());
}
try {
executePersistAction(session, action);
} catch (Exception e) {
log.debug("Error executing query", e);
if (ignoreErrors) {
continue;
}
boolean keepRunning = true;
switch(DBWorkbench.getPlatformUI().showErrorStopRetryIgnore(session.getTaskTitle(), e, true)) {
case STOP:
keepRunning = false;
break;
case RETRY:
// just make it again
continue;
case IGNORE:
// Just do nothing
break;
case IGNORE_ALL:
ignoreErrors = true;
break;
}
if (!keepRunning) {
break;
}
} finally {
monitor.worked(1);
}
}
} finally {
monitor.done();
}
}
use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by dbeaver.
the class SaveScriptDialog method populateSQL.
private void populateSQL() {
try {
final List<DBEPersistAction> sqlScript = new ArrayList<>();
UIUtils.runInProgressService(monitor -> {
List<DBEPersistAction> script = viewer.generateChangesScript(monitor, saveSettings);
if (script != null) {
sqlScript.addAll(script);
}
});
scriptText = "";
if (!sqlScript.isEmpty()) {
scriptText = SQLUtils.generateScript(viewer.getDataSource(), sqlScript.toArray(new DBEPersistAction[0]), false);
scriptText = SQLUtils.generateCommentLine(viewer.getDataSource(), "Auto-generated SQL script #" + new SimpleDateFormat(GeneralUtils.DEFAULT_TIMESTAMP_PATTERN).format(new Date())) + scriptText;
UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
if (serviceSQL != null) {
serviceSQL.setSQLPanelText(sqlPanel, scriptText);
}
}
} catch (Exception e) {
DBWorkbench.getPlatformUI().showError("Can't generate SQL script", "Error generating SQL script from data changes", e);
}
}
Aggregations