Search in sources :

Example 26 with DBEPersistAction

use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by serge-rider.

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 27 with DBEPersistAction

use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by serge-rider.

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 28 with DBEPersistAction

use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by serge-rider.

the class DBStructUtils method generateTableDDL.

public static String generateTableDDL(@NotNull DBRProgressMonitor monitor, @NotNull DBSEntity table, Map<String, Object> options, boolean addComments) throws DBException {
    final DBERegistry editorsRegistry = table.getDataSource().getContainer().getPlatform().getEditorsRegistry();
    final SQLObjectEditor entityEditor = editorsRegistry.getObjectManager(table.getClass(), SQLObjectEditor.class);
    if (entityEditor instanceof SQLTableManager) {
        DBEPersistAction[] ddlActions = ((SQLTableManager) entityEditor).getTableDDL(monitor, table, options);
        return SQLUtils.generateScript(table.getDataSource(), ddlActions, addComments);
    }
    log.debug("Table editor not found for " + table.getClass().getName());
    return SQLUtils.generateCommentLine(table.getDataSource(), "Can't generate DDL: table editor not found for " + table.getClass().getName());
}
Also used : SQLTableManager(org.jkiss.dbeaver.model.impl.sql.edit.struct.SQLTableManager) DBERegistry(org.jkiss.dbeaver.model.edit.DBERegistry) DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) SQLObjectEditor(org.jkiss.dbeaver.model.impl.sql.edit.SQLObjectEditor)

Example 29 with DBEPersistAction

use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by serge-rider.

the class MySQLCommandChangeUser method getPersistActions.

@Override
public DBEPersistAction[] getPersistActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, Map<String, Object> options) {
    List<DBEPersistAction> actions = new ArrayList<>();
    boolean newUser = !getObject().isPersisted();
    if (newUser) {
        actions.add(new // $NON-NLS-2$
        SQLDatabasePersistAction(// $NON-NLS-2$
        MySQLUIMessages.edit_command_change_user_action_create_new_user, // $NON-NLS-2$
        "CREATE USER " + getObject().getFullName()) {

            @Override
            public void afterExecute(DBCSession session, Throwable error) {
                if (error == null) {
                    getObject().setPersisted(true);
                }
            }
        });
    }
    boolean hasSet;
    final MySQLDataSource dataSource = getObject().getDataSource();
    if (MySQLUtils.isAlterUSerSupported(dataSource)) {
        StringBuilder script = new StringBuilder();
        if (generateAlterScript(script)) {
            actions.add(new SQLDatabasePersistAction(MySQLUIMessages.edit_command_change_user_action_update_user_record, script.toString()));
        }
    } else {
        String updateSQL = generateUpdateScript();
        if (updateSQL != null) {
            actions.add(new SQLDatabasePersistAction(MySQLUIMessages.edit_command_change_user_action_update_user_record, updateSQL));
        }
        updateSQL = generatePasswordSet();
        if (updateSQL != null) {
            actions.add(new SQLDatabasePersistAction(MySQLUIMessages.edit_command_change_user_action_update_user_record, updateSQL));
        }
    }
    return actions.toArray(new DBEPersistAction[0]);
}
Also used : MySQLDataSource(org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource) DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) ArrayList(java.util.ArrayList) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction) DBCSession(org.jkiss.dbeaver.model.exec.DBCSession)

Example 30 with DBEPersistAction

use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by serge-rider.

the class ACLCommandChangePrivilege method getPersistActions.

@Override
public DBEPersistAction[] getPersistActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, Map<String, Object> options) {
    DBAPrivilegeOwner object = getObject();
    String grantScript = aclManager.generatePermissionChangeScript(monitor, object, grant, privilege, privilegeTypes, options);
    return new DBEPersistAction[] { new SQLDatabasePersistAction(ACLMessages.edit_command_grant_privilege_action_grant_privilege, grantScript) };
}
Also used : DBAPrivilegeOwner(org.jkiss.dbeaver.model.access.DBAPrivilegeOwner) DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

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