Search in sources :

Example 51 with SQLDatabasePersistAction

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

the class MySQLTriggerManager method createOrReplaceTriggerQuery.

protected void createOrReplaceTriggerQuery(List<DBEPersistAction> actions, MySQLTrigger trigger) {
    if (trigger.isPersisted()) {
        actions.add(new SQLDatabasePersistAction("Drop trigger", "DROP TRIGGER IF EXISTS " + trigger.getFullyQualifiedName(DBPEvaluationContext.DDL)));
    }
    String ddl = "CREATE TRIGGER " + trigger.getFullyQualifiedName(DBPEvaluationContext.DDL) + "\n" + trigger.getActionTiming() + " " + trigger.getManipulationType() + "\n" + "ON " + trigger.getTable().getFullyQualifiedName(DBPEvaluationContext.DDL) + " FOR EACH ROW\n" + trigger.getBody();
    //$NON-NLS-2$
    actions.add(new SQLDatabasePersistAction("Create trigger", ddl, true));
}
Also used : SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 52 with SQLDatabasePersistAction

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

the class ExasolTableColumnManager method addObjectRenameActions.

@Override
protected void addObjectRenameActions(List<DBEPersistAction> actions, ObjectRenameCommand command) {
    final ExasolTableColumn column = command.getObject();
    actions.add(new SQLDatabasePersistAction("Rename column", "ALTER TABLE " + column.getTable().getFullyQualifiedName(DBPEvaluationContext.DDL) + " RENAME COLUMN " + DBUtils.getQuotedIdentifier(column.getDataSource(), command.getOldName()) + " TO " + DBUtils.getQuotedIdentifier(column.getDataSource(), command.getNewName())));
}
Also used : ExasolTableColumn(org.jkiss.dbeaver.ext.exasol.model.ExasolTableColumn) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 53 with SQLDatabasePersistAction

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

the class ExasolTableManager method addObjectRenameActions.

// ------
// Rename
// ------
@Override
public void addObjectRenameActions(List<DBEPersistAction> actions, ObjectRenameCommand command) {
    String sql = String.format(SQL_RENAME_TABLE, command.getObject().getFullyQualifiedName(DBPEvaluationContext.DDL), command.getNewName());
    actions.add(new SQLDatabasePersistAction(CMD_RENAME, sql));
}
Also used : SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 54 with SQLDatabasePersistAction

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

the class ExasolTableManager method addObjectModifyActions.

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

Example 55 with SQLDatabasePersistAction

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

the class SQLTableManager method addStructObjectCreateActions.

@Override
protected void addStructObjectCreateActions(List<DBEPersistAction> actions, StructCreateCommand command) {
    final OBJECT_TYPE table = command.getObject();
    final NestedObjectCommand tableProps = command.getObjectCommands().get(table);
    if (tableProps == null) {
        //$NON-NLS-1$
        log.warn("Object change command not found");
        return;
    }
    final String tableName = table.getFullyQualifiedName(DBPEvaluationContext.DDL);
    final String lineSeparator = GeneralUtils.getDefaultLineSeparator();
    StringBuilder createQuery = new StringBuilder(100);
    //$NON-NLS-1$ //$NON-NLS-2$
    createQuery.append("CREATE TABLE ").append(tableName).append(" (").append(lineSeparator);
    boolean hasNestedDeclarations = false;
    final Collection<NestedObjectCommand> orderedCommands = getNestedOrderedCommands(command);
    for (NestedObjectCommand nestedCommand : orderedCommands) {
        if (nestedCommand.getObject() == table) {
            continue;
        }
        if (excludeFromDDL(nestedCommand, orderedCommands)) {
            continue;
        }
        final String nestedDeclaration = nestedCommand.getNestedDeclaration(table);
        if (!CommonUtils.isEmpty(nestedDeclaration)) {
            // Insert nested declaration
            if (hasNestedDeclarations) {
                //$NON-NLS-1$
                createQuery.append(",").append(lineSeparator);
            }
            //$NON-NLS-1$
            createQuery.append("\t").append(nestedDeclaration);
            hasNestedDeclarations = true;
        } else {
            // This command should be executed separately
            final DBEPersistAction[] nestedActions = nestedCommand.getPersistActions();
            if (nestedActions != null) {
                Collections.addAll(actions, nestedActions);
            }
        }
    }
    //$NON-NLS-1$
    createQuery.append(lineSeparator).append(")");
    appendTableModifiers(table, tableProps, createQuery);
    actions.add(0, new SQLDatabasePersistAction(ModelMessages.model_jdbc_create_new_table, createQuery.toString()));
}
Also used : DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Aggregations

SQLDatabasePersistAction (org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)55 DBEPersistAction (org.jkiss.dbeaver.model.edit.DBEPersistAction)10 DBException (org.jkiss.dbeaver.DBException)3 MySQLTableColumn (org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn)3 DB2TableColumn (org.jkiss.dbeaver.ext.db2.model.DB2TableColumn)2 ExasolTableColumn (org.jkiss.dbeaver.ext.exasol.model.ExasolTableColumn)2 OracleTableColumn (org.jkiss.dbeaver.ext.oracle.model.OracleTableColumn)2 ArrayList (java.util.ArrayList)1 NotNull (org.jkiss.code.NotNull)1 ExasolView (org.jkiss.dbeaver.ext.exasol.model.ExasolView)1 GenericDataSource (org.jkiss.dbeaver.ext.generic.model.GenericDataSource)1 MySQLCatalog (org.jkiss.dbeaver.ext.mysql.model.MySQLCatalog)1 MySQLDataSource (org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource)1 MySQLView (org.jkiss.dbeaver.ext.mysql.model.MySQLView)1 OracleDataType (org.jkiss.dbeaver.ext.oracle.model.OracleDataType)1 OracleUser (org.jkiss.dbeaver.ext.oracle.model.OracleUser)1 OracleView (org.jkiss.dbeaver.ext.oracle.model.OracleView)1 PostgreDatabase (org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase)1 PostgreRole (org.jkiss.dbeaver.ext.postgresql.model.PostgreRole)1 PostgreSchema (org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema)1