Search in sources :

Example 21 with SQLDatabasePersistAction

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

the class ExasolScriptManager method createOrReplaceScriptQuery.

private void createOrReplaceScriptQuery(List<DBEPersistAction> actions, ExasolScript script, Boolean replace) {
    actions.add(new SQLDatabasePersistAction("Create Script", "OPEN SCHEMA " + script.getSchema().getName()));
    if (replace) {
        actions.add(new SQLDatabasePersistAction("Create Script", "DROP SCRIPT " + script.getFullyQualifiedName(DBPEvaluationContext.DDL)));
    }
    actions.add(new SQLDatabasePersistAction("Create Script: ", script.getSql(), true));
}
Also used : SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 22 with SQLDatabasePersistAction

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

the class ExasolTableColumnManager method addObjectModifyActions.

// -----
// Alter
// -----
@Override
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command) {
    ExasolTableColumn exasolColumn = command.getObject();
    if (!command.getProperties().isEmpty()) {
        // build nullability tring
        String nullability = "";
        if (exasolColumn.isOriRequired() != null && exasolColumn.isOriRequired() != exasolColumn.isRequired())
            nullability = exasolColumn.isRequired() ? "NOT NULL" : "NULL";
        final String deltaSQL = exasolColumn.getName() + " " + exasolColumn.getFormatType() + " " + (exasolColumn.getDefaultValue() == null ? "" : " DEFAULT " + exasolColumn.getDefaultValue()) + " " + formatIdentiy(exasolColumn.isAutoGenerated(), exasolColumn.getIdentityValue()) + " " + nullability;
        if (!deltaSQL.isEmpty()) {
            String sqlAlterColumn = String.format(SQL_ALTER, exasolColumn.getTable().getFullyQualifiedName(DBPEvaluationContext.DDL), deltaSQL);
            actionList.add(new SQLDatabasePersistAction(CMD_ALTER, sqlAlterColumn));
        }
    }
    // Comment
    DBEPersistAction commentAction = buildCommentAction(exasolColumn);
    if (commentAction != null) {
        actionList.add(commentAction);
    }
}
Also used : DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) ExasolTableColumn(org.jkiss.dbeaver.ext.exasol.model.ExasolTableColumn) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 23 with SQLDatabasePersistAction

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

the class SQLConstraintManager method addObjectCreateActions.

@Override
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command) {
    final TABLE_TYPE table = command.getObject().getTable();
    actions.add(new SQLDatabasePersistAction(ModelMessages.model_jdbc_create_new_constraint, "ALTER TABLE " + table.getFullyQualifiedName(DBPEvaluationContext.DDL) + " ADD " + getNestedDeclaration(table, command)));
}
Also used : SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 24 with SQLDatabasePersistAction

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

the class SQLForeignKeyManager method addObjectCreateActions.

@Override
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command) {
    final TABLE_TYPE table = command.getObject().getTable();
    actions.add(new SQLDatabasePersistAction(ModelMessages.model_jdbc_create_new_foreign_key, //$NON-NLS-1$ //$NON-NLS-2$
    "ALTER TABLE " + table.getFullyQualifiedName(DBPEvaluationContext.DDL) + " ADD " + getNestedDeclaration(table, command)));
}
Also used : SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 25 with SQLDatabasePersistAction

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

the class SQLIndexManager method addObjectCreateActions.

@Override
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command) {
    final TABLE_TYPE table = command.getObject().getTable();
    final OBJECT_TYPE index = command.getObject();
    // Create index
    final String indexName = DBUtils.getQuotedIdentifier(index.getDataSource(), index.getName());
    index.setName(indexName);
    StringBuilder decl = new StringBuilder(40);
    decl.append("CREATE ");
    if (index.isUnique()) {
        decl.append("UNIQUE ");
    }
    //$NON-NLS-1$
    decl.append("INDEX ").append(indexName).append(" ON ").append(//$NON-NLS-1$
    table.getFullyQualifiedName(DBPEvaluationContext.DDL)).append(//$NON-NLS-1$
    " (");
    try {
        // Get columns using void monitor
        boolean firstColumn = true;
        for (DBSTableIndexColumn indexColumn : CommonUtils.safeCollection(command.getObject().getAttributeReferences(VoidProgressMonitor.INSTANCE))) {
            //$NON-NLS-1$
            if (!firstColumn)
                decl.append(",");
            firstColumn = false;
            decl.append(indexColumn.getName());
            appendIndexColumnModifiers(decl, indexColumn);
        }
    } catch (DBException e) {
        log.error(e);
    }
    //$NON-NLS-1$
    decl.append(")");
    actions.add(new SQLDatabasePersistAction(ModelMessages.model_jdbc_create_new_index, decl.toString()));
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBSTableIndexColumn(org.jkiss.dbeaver.model.struct.rdb.DBSTableIndexColumn) 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