Search in sources :

Example 6 with GenericTableColumn

use of org.jkiss.dbeaver.ext.generic.model.GenericTableColumn in project dbeaver by serge-rider.

the class SQLiteTableColumnManager method addObjectRenameActions.

@Override
protected void addObjectRenameActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectRenameCommand command, Map<String, Object> options) {
    final GenericTableColumn column = command.getObject();
    actions.add(new SQLDatabasePersistAction("Rename column", "ALTER TABLE " + DBUtils.getQuotedIdentifier(column.getTable()) + " RENAME COLUMN " + DBUtils.getQuotedIdentifier(column.getDataSource(), command.getOldName()) + " TO " + DBUtils.getQuotedIdentifier(column.getDataSource(), command.getNewName())));
}
Also used : GenericTableColumn(org.jkiss.dbeaver.ext.generic.model.GenericTableColumn) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 7 with GenericTableColumn

use of org.jkiss.dbeaver.ext.generic.model.GenericTableColumn in project dbeaver by serge-rider.

the class VerticaTableColumnManager method addObjectModifyActions.

/**
 * Copy-pasted from PostgreSQL implementation.
 * TODO: Vertica is originally based on PG. Maybe we should refactor this stuff somehow.
 */
@Override
protected void addObjectModifyActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actionList, ObjectChangeCommand command, Map<String, Object> options) {
    final GenericTableColumn column = command.getObject();
    String prefix = "ALTER TABLE " + DBUtils.getObjectFullName(column.getTable(), DBPEvaluationContext.DDL) + " ALTER COLUMN " + DBUtils.getQuotedIdentifier(column) + " ";
    String typeClause = column.getFullTypeName();
    if (command.getProperty(DBConstants.PROP_ID_TYPE_NAME) != null || command.getProperty("maxLength") != null || command.getProperty("precision") != null || command.getProperty("scale") != null) {
        actionList.add(new SQLDatabasePersistAction("Set column type", prefix + "SET DATA TYPE " + typeClause));
    }
    if (command.getProperty(DBConstants.PROP_ID_REQUIRED) != null) {
        actionList.add(new SQLDatabasePersistAction("Set column nullability", prefix + (column.isRequired() ? "SET" : "DROP") + " NOT NULL"));
    }
    if (command.getProperty(DBConstants.PROP_ID_DEFAULT_VALUE) != 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()));
        }
    }
    super.addObjectModifyActions(monitor, executionContext, actionList, command, options);
}
Also used : GenericTableColumn(org.jkiss.dbeaver.ext.generic.model.GenericTableColumn) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 8 with GenericTableColumn

use of org.jkiss.dbeaver.ext.generic.model.GenericTableColumn in project dbeaver by serge-rider.

the class VerticaTableColumnManager method getNestedDeclaration.

@Override
public StringBuilder getNestedDeclaration(DBRProgressMonitor monitor, GenericTableBase owner, DBECommandAbstract<GenericTableColumn> command, Map<String, Object> options) {
    StringBuilder decl = super.getNestedDeclaration(monitor, owner, command, options);
    final GenericTableColumn column = command.getObject();
    if (column.isAutoIncrement()) {
        final String autoIncrementClause = column.getDataSource().getMetaModel().getAutoIncrementClause(column);
        if (autoIncrementClause != null && !autoIncrementClause.isEmpty()) {
            // $NON-NLS-1$
            decl.append(" ").append(autoIncrementClause);
        }
    }
    return decl;
}
Also used : GenericTableColumn(org.jkiss.dbeaver.ext.generic.model.GenericTableColumn)

Example 9 with GenericTableColumn

use of org.jkiss.dbeaver.ext.generic.model.GenericTableColumn in project dbeaver by dbeaver.

the class GenericTableColumnManager method getNestedDeclaration.

@Override
public StringBuilder getNestedDeclaration(DBRProgressMonitor monitor, GenericTableBase owner, DBECommandAbstract<GenericTableColumn> command, Map<String, Object> options) {
    StringBuilder decl = super.getNestedDeclaration(monitor, owner, command, options);
    final GenericTableColumn column = command.getObject();
    if (column.isAutoIncrement()) {
        final String autoIncrementClause = column.getDataSource().getMetaModel().getAutoIncrementClause(column);
        if (autoIncrementClause != null && !autoIncrementClause.isEmpty()) {
            // $NON-NLS-1$
            decl.append(" ").append(autoIncrementClause);
        }
    }
    return decl;
}
Also used : GenericTableColumn(org.jkiss.dbeaver.ext.generic.model.GenericTableColumn)

Example 10 with GenericTableColumn

use of org.jkiss.dbeaver.ext.generic.model.GenericTableColumn in project dbeaver by dbeaver.

the class SQLiteTableColumnManager method addObjectRenameActions.

@Override
protected void addObjectRenameActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectRenameCommand command, Map<String, Object> options) {
    final GenericTableColumn column = command.getObject();
    actions.add(new SQLDatabasePersistAction("Rename column", "ALTER TABLE " + DBUtils.getQuotedIdentifier(column.getTable()) + " RENAME COLUMN " + DBUtils.getQuotedIdentifier(column.getDataSource(), command.getOldName()) + " TO " + DBUtils.getQuotedIdentifier(column.getDataSource(), command.getNewName())));
}
Also used : GenericTableColumn(org.jkiss.dbeaver.ext.generic.model.GenericTableColumn) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Aggregations

GenericTableColumn (org.jkiss.dbeaver.ext.generic.model.GenericTableColumn)32 SQLDatabasePersistAction (org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)14 DBException (org.jkiss.dbeaver.DBException)4 GenericTableBase (org.jkiss.dbeaver.ext.generic.model.GenericTableBase)4 DBSDataType (org.jkiss.dbeaver.model.struct.DBSDataType)4 HiveTable (org.jkiss.dbeaver.ext.hive.model.HiveTable)2 HiveTableColumn (org.jkiss.dbeaver.ext.hive.model.HiveTableColumn)2 SQLDatabasePersistActionComment (org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistActionComment)2 Version (org.osgi.framework.Version)2