Search in sources :

Example 11 with SQLDatabasePersistAction

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

the class DB2SchemaManager method addObjectCreateActions.

@Override
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command) {
    SQLDatabasePersistAction action = new SQLDatabasePersistAction("Create schema", String.format(SQL_CREATE_SCHEMA, DBUtils.getQuotedIdentifier(command.getObject())));
    actions.add(action);
}
Also used : SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 12 with SQLDatabasePersistAction

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

the class DB2SequenceManager method addObjectDeleteActions.

@Override
protected void addObjectDeleteActions(List<DBEPersistAction> actions, ObjectDeleteCommand command) {
    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 13 with SQLDatabasePersistAction

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

the class PostgreTableColumnManager method addObjectModifyActions.

@Override
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command) {
    final PostgreAttribute column = command.getObject();
    // PostgreSQL can't perform all changes by one query
    //        ALTER [ COLUMN ] column [ SET DATA ] TYPE data_type [ COLLATE collation ] [ USING expression ]
    //        ALTER [ COLUMN ] column SET DEFAULT expression
    //        ALTER [ COLUMN ] column DROP DEFAULT
    //        ALTER [ COLUMN ] column { SET | DROP } NOT NULL
    //        ALTER [ COLUMN ] column SET STATISTICS integer
    //        ALTER [ COLUMN ] column SET ( attribute_option = value [, ... ] )
    //        ALTER [ COLUMN ] column RESET ( attribute_option [, ... ] )
    //        ALTER [ COLUMN ] column SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN }
    String prefix = "ALTER TABLE " + DBUtils.getObjectFullName(column.getTable(), DBPEvaluationContext.DDL) + " ALTER COLUMN " + DBUtils.getQuotedIdentifier(column) + " ";
    String typeClause = column.getFullTypeName();
    if (column.getDataType() != null) {
        typeClause += " USING " + DBUtils.getQuotedIdentifier(column) + "::" + column.getDataType().getName();
    }
    if (command.getProperty("dataType") != null || command.getProperty("maxLength") != null || command.getProperty("precision") != null || command.getProperty("scale") != null) {
        actionList.add(new SQLDatabasePersistAction("Set column type", prefix + "TYPE " + typeClause));
    }
    if (command.getProperty("required") != null) {
        actionList.add(new SQLDatabasePersistAction("Set column nullability", prefix + (column.isRequired() ? "SET" : "DROP") + " NOT NULL"));
    }
    if (command.getProperty("defaultValue") != null) {
        if (CommonUtils.isEmpty(column.getDefaultValue())) {
            actionList.add(new SQLDatabasePersistAction("Drop column default", prefix + "DROP DEFAULT"));
        } else {
            actionList.add(new SQLDatabasePersistAction("Set column default", prefix + "SET DEFAULT " + column.getDefaultValue()));
        }
    }
    if (command.getProperty("description") != null) {
        actionList.add(new SQLDatabasePersistAction("Set column comment", "COMMENT ON COLUMN " + DBUtils.getObjectFullName(column.getTable(), DBPEvaluationContext.DDL) + "." + DBUtils.getQuotedIdentifier(column) + " IS '" + SQLUtils.escapeString(CommonUtils.toString(column.getDescription())) + "'"));
    }
}
Also used : SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 14 with SQLDatabasePersistAction

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

the class PostgreTableManager method addObjectModifyActions.

@Override
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command) {
    final PostgreTableBase table = command.getObject();
    if (command.getProperties().size() > 1 || command.getProperty("description") == null) {
        //$NON-NLS-1$
        StringBuilder query = new StringBuilder("ALTER TABLE ");
        //$NON-NLS-1$
        query.append(table.getFullyQualifiedName(DBPEvaluationContext.DDL)).append(" ");
        appendTableModifiers(table, command, query);
        actionList.add(new SQLDatabasePersistAction(query.toString()));
    }
}
Also used : SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 15 with SQLDatabasePersistAction

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

the class PostgreDatabaseManager method addObjectCreateActions.

@Override
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command) {
    final PostgreDatabase database = command.getObject();
    actions.add(//$NON-NLS-2$
    new SQLDatabasePersistAction("Create database", "CREATE DATABASE " + DBUtils.getQuotedIdentifier(database)));
}
Also used : PostgreDatabase(org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase) 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