Search in sources :

Example 81 with DBEPersistAction

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

Example 82 with DBEPersistAction

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

Example 83 with DBEPersistAction

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

Example 84 with DBEPersistAction

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();
    }
}
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 85 with DBEPersistAction

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);
    }
}
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)

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