Search in sources :

Example 86 with DBEPersistAction

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

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

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

the class DB2SchemaManager method addObjectDeleteActions.

@Override
protected void addObjectDeleteActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectDeleteCommand command, Map<String, Object> options) {
    String schemaName = command.getObject().getName();
    DBEPersistAction action = new SQLDatabasePersistAction("Drop schema (SQL)", String.format(SQL_DROP_SCHEMA, DBUtils.getQuotedIdentifier(command.getObject())));
    actions.add(action);
}
Also used : DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 88 with DBEPersistAction

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

the class DB2TableManager method addObjectModifyActions.

// ------
// Alter
// ------
@Override
public void addObjectModifyActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actionList, ObjectChangeCommand command, Map<String, Object> options) {
    DB2Table db2Table = command.getObject();
    if (command.getProperties().size() > 1) {
        StringBuilder sb = new StringBuilder(128);
        sb.append(SQL_ALTER);
        sb.append(db2Table.getFullyQualifiedName(DBPEvaluationContext.DDL));
        sb.append(" ");
        appendTableModifiers(monitor, command.getObject(), command, sb, true);
        actionList.add(new SQLDatabasePersistAction(CMD_ALTER, sb.toString()));
    }
    DBEPersistAction commentAction = buildCommentAction(db2Table);
    if (commentAction != null) {
        actionList.add(commentAction);
    }
}
Also used : DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 89 with DBEPersistAction

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

the class DB2TableManager method addStructObjectCreateActions.

@Override
public void addStructObjectCreateActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, StructCreateCommand command, Map<String, Object> options) throws DBException {
    super.addStructObjectCreateActions(monitor, executionContext, actions, command, options);
    // Eventually add Comment
    DBEPersistAction commentAction = buildCommentAction(command.getObject());
    if (commentAction != null) {
        actions.add(commentAction);
    }
}
Also used : DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction)

Example 90 with DBEPersistAction

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

the class NavigatorObjectsDeleter method appendScript.

private void appendScript(final DBRProgressMonitor monitor, final StringBuilder sql, final DBNDatabaseNode node) throws InvocationTargetException {
    if (!(node.getParentNode() instanceof DBNContainer)) {
        return;
    }
    final DBSObject object = node.getObject();
    if (object == null) {
        return;
    }
    final DBEObjectMaker objectMaker = DBWorkbench.getPlatform().getEditorsRegistry().getObjectManager(object.getClass(), DBEObjectMaker.class);
    if (objectMaker == null) {
        return;
    }
    final boolean supportsCascade = (objectMaker.getMakerOptions(object.getDataSource()) & DBEObjectMaker.FEATURE_DELETE_CASCADE) != 0;
    final NavigatorHandlerObjectBase.CommandTarget commandTarget;
    try {
        commandTarget = NavigatorHandlerObjectBase.getCommandTarget(window, node.getParentNode(), object.getClass(), false);
    } catch (DBException e) {
        log.warn(e);
        return;
    }
    if (commandContext == null) {
        commandContext = commandTarget.getContext();
    }
    if (!object.isPersisted() || commandTarget.getEditor() != null) {
        return;
    }
    final Map<String, Object> deleteOptions;
    if (supportsCascade && deleteCascade) {
        deleteOptions = OPTIONS_CASCADE;
    } else {
        deleteOptions = Collections.emptyMap();
    }
    try {
        objectMaker.deleteObject(commandTarget.getContext(), node.getObject(), deleteOptions);
    } catch (DBException e) {
        log.warn(e);
        return;
    }
    final StringBuilder script = new StringBuilder();
    final DBECommandContext commandContext = commandTarget.getContext();
    Collection<? extends DBECommand> commands = commandContext.getFinalCommands();
    try {
        for (DBECommand command : commands) {
            final DBEPersistAction[] persistActions = command.getPersistActions(monitor, commandContext.getExecutionContext(), deleteOptions);
            script.append(SQLUtils.generateScript(commandContext.getExecutionContext().getDataSource(), persistActions, false));
            if (script.length() == 0) {
                script.append(SQLUtils.generateComments(commandContext.getExecutionContext().getDataSource(), persistActions, false));
            }
        }
    } catch (DBException e) {
        throw new InvocationTargetException(e);
    }
    commandTarget.getContext().resetChanges(true);
    if (sql.length() != 0) {
        sql.append("\n");
    }
    sql.append(script);
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBEObjectMaker(org.jkiss.dbeaver.model.edit.DBEObjectMaker) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBECommand(org.jkiss.dbeaver.model.edit.DBECommand) DBECommandContext(org.jkiss.dbeaver.model.edit.DBECommandContext) DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject)

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