Search in sources :

Example 21 with DBEPersistAction

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();
    }
}
Also used : DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException)

Example 22 with DBEPersistAction

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();
                }
            }
        }
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL)

Example 23 with DBEPersistAction

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);
}
Also used : DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 24 with DBEPersistAction

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);
    }
}
Also used : DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) ArrayList(java.util.ArrayList) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 25 with DBEPersistAction

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);
    }
}
Also used : DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) ArrayList(java.util.ArrayList) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL)

Aggregations

DBEPersistAction (org.jkiss.dbeaver.model.edit.DBEPersistAction)94 SQLDatabasePersistAction (org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)44 DBException (org.jkiss.dbeaver.DBException)24 InvocationTargetException (java.lang.reflect.InvocationTargetException)16 ArrayList (java.util.ArrayList)14 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)10 UIServiceSQL (org.jkiss.dbeaver.runtime.ui.UIServiceSQL)10 DBERegistry (org.jkiss.dbeaver.model.edit.DBERegistry)8 OracleObjectPersistAction (org.jkiss.dbeaver.ext.oracle.model.OracleObjectPersistAction)6 DBPEvent (org.jkiss.dbeaver.model.DBPEvent)6 DBECommand (org.jkiss.dbeaver.model.edit.DBECommand)6 DBECommandContext (org.jkiss.dbeaver.model.edit.DBECommandContext)6 DBCException (org.jkiss.dbeaver.model.exec.DBCException)6 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)6 DBCStatement (org.jkiss.dbeaver.model.exec.DBCStatement)6 SQLDatabasePersistActionComment (org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistActionComment)6 SQLObjectEditor (org.jkiss.dbeaver.model.impl.sql.edit.SQLObjectEditor)6 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)6 DBSObjectState (org.jkiss.dbeaver.model.struct.DBSObjectState)6 SQLException (java.sql.SQLException)4