Search in sources :

Example 31 with DBEPersistAction

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

the class DB2SequenceManager method addObjectDeleteActions.

@Override
protected void addObjectDeleteActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectDeleteCommand command, Map<String, Object> options) {
    String sql = String.format(SQL_DROP, 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 32 with DBEPersistAction

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

the class DB2AbstractDropOnlyManager method addObjectDeleteActions.

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

Example 33 with DBEPersistAction

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

the class SQLUtils method generateScript.

@NotNull
public static String generateScript(DBPDataSource dataSource, DBEPersistAction[] persistActions, boolean addComments) {
    final SQLDialect sqlDialect = SQLUtils.getDialectFromDataSource(dataSource);
    final String lineSeparator = GeneralUtils.getDefaultLineSeparator();
    StringBuilder script = new StringBuilder(64);
    if (addComments) {
        script.append(DBEAVER_DDL_COMMENT).append(Platform.getProduct().getName()).append(lineSeparator).append(DBEAVER_DDL_WARNING).append(lineSeparator);
    }
    if (persistActions != null) {
        String redefiner = sqlDialect.getScriptDelimiterRedefiner();
        for (DBEPersistAction action : persistActions) {
            String scriptLine = action.getScript();
            if (CommonUtils.isEmpty(scriptLine)) {
                continue;
            }
            String delimiter = getScriptLineDelimiter(sqlDialect);
            if (action.isComplex() && redefiner != null) {
                script.append(lineSeparator).append(redefiner).append(" ").append(DBEAVER_SCRIPT_DELIMITER).append(lineSeparator);
                delimiter = DBEAVER_SCRIPT_DELIMITER;
                script.append(delimiter).append(lineSeparator);
            } else if (action.getType() == DBEPersistAction.ActionType.COMMENT) {
                if (script.length() > 2) {
                    int lfCount = 0;
                    for (int i = script.length() - 1; i >= 0; i--) {
                        if (!Character.isWhitespace(script.charAt(i))) {
                            break;
                        }
                        if (script.charAt(i) == '\n')
                            lfCount++;
                    }
                    if (lfCount < 2) {
                        // Add line feed if we do not have empty line before
                        script.append(lineSeparator);
                    }
                }
            }
            script.append(scriptLine);
            if (action.getType() != DBEPersistAction.ActionType.COMMENT) {
                String testLine = scriptLine.trim();
                if (testLine.lastIndexOf(delimiter) != (testLine.length() - delimiter.length())) {
                    script.append(delimiter);
                }
            } else {
                script.append(lineSeparator);
            }
            script.append(lineSeparator);
            if (action.isComplex() && redefiner != null) {
                script.append(redefiner).append(" ").append(getScriptLineDelimiter(sqlDialect)).append(lineSeparator);
            }
        }
    }
    return script.toString();
}
Also used : BasicSQLDialect(org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect) DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) NotNull(org.jkiss.code.NotNull)

Example 34 with DBEPersistAction

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

the class SQLUtils method generateComments.

@NotNull
public static String generateComments(DBPDataSource dataSource, DBEPersistAction[] persistActions, boolean addComments) {
    final SQLDialect sqlDialect = SQLUtils.getDialectFromDataSource(dataSource);
    final String lineSeparator = GeneralUtils.getDefaultLineSeparator();
    StringBuilder script = new StringBuilder(64);
    if (addComments) {
        script.append(DBEAVER_DDL_COMMENT).append(Platform.getProduct().getName()).append(lineSeparator).append(DBEAVER_DDL_WARNING).append(lineSeparator);
    }
    if (persistActions != null) {
        String slComment;
        String[] slComments = sqlDialect.getSingleLineComments();
        if (ArrayUtils.isEmpty(slComments)) {
            slComment = "--";
        } else {
            slComment = slComments[0];
        }
        for (DBEPersistAction action : persistActions) {
            if (action.getType() != DBEPersistAction.ActionType.COMMENT) {
                String scriptLine = action.getTitle();
                if (CommonUtils.isEmpty(scriptLine)) {
                    continue;
                }
                script.append(slComment).append(" ").append(scriptLine);
            } else {
                String scriptLine = action.getScript();
                if (CommonUtils.isEmpty(scriptLine)) {
                    continue;
                }
                script.append(scriptLine);
            }
            script.append(lineSeparator);
        }
    }
    return script.toString();
}
Also used : BasicSQLDialect(org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect) DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) NotNull(org.jkiss.code.NotNull)

Example 35 with DBEPersistAction

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

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)

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