use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by serge-rider.
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 serge-rider.
the class DatabaseConsumerPageMapping method showDDL.
private void showDDL(DatabaseMappingContainer mapping) {
final DatabaseConsumerSettings settings = getDatabaseConsumerSettings();
final DBSObjectContainer container = settings.getContainer();
if (container == null) {
return;
}
DBPDataSource dataSource = container.getDataSource();
final DBEPersistAction[][] ddl = new DBEPersistAction[1][];
try {
getWizard().getRunnableContext().run(true, true, monitor -> {
monitor.beginTask(DTUIMessages.database_consumer_page_mapping_monitor_task, 1);
try {
DBCExecutionContext executionContext = DBUtils.getDefaultContext(dataSource, true);
ddl[0] = DatabaseTransferUtils.generateTargetTableDDL(monitor, executionContext, container, mapping);
} catch (DBException e) {
throw new InvocationTargetException(e);
}
monitor.done();
});
} catch (InvocationTargetException e) {
DBWorkbench.getPlatformUI().showError(DTUIMessages.database_consumer_page_mapping_title_target_DDL, DTUIMessages.database_consumer_page_mapping_message_error_generating_target_DDL, e);
return;
} catch (InterruptedException e) {
return;
}
DBEPersistAction[] persistActions = ddl[0];
if (ArrayUtils.isEmpty(persistActions)) {
UIUtils.showMessageBox(getShell(), "No schema changes", "No changes are needed for this mapping", SWT.ICON_INFORMATION);
return;
}
UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
if (serviceSQL != null) {
String sql = SQLUtils.generateScript(dataSource, persistActions, false);
int result = serviceSQL.openSQLViewer(DBUtils.getDefaultContext(container, true), DTUIMessages.database_consumer_page_mapping_sqlviewer_title, null, sql, dataSource.getContainer().hasModifyPermission(DBPDataSourcePermission.PERMISSION_EDIT_METADATA), false);
if (result == IDialogConstants.PROCEED_ID) {
if (UIUtils.confirmAction(getShell(), "Create target objects", "Database metadata will be modified by creating new table(s) and column(s).\nAre you sure you want to proceed?")) {
// Create target objects
if (applySchemaChanges(dataSource, mapping, persistActions)) {
autoAssignMappings();
updateMappingsAndButtons();
}
}
}
}
}
use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by serge-rider.
the class OracleSequenceManager method addObjectDeleteActions.
@Override
protected void addObjectDeleteActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectDeleteCommand command, Map<String, Object> options) {
String sql = "DROP SEQUENCE " + command.getObject().getFullyQualifiedName(DBPEvaluationContext.DDL);
DBEPersistAction action = new SQLDatabasePersistAction("Drop Sequence", sql);
actions.add(action);
}
use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by serge-rider.
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);
}
}
use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by serge-rider.
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);
}
}
Aggregations