Search in sources :

Example 31 with GenericTableColumn

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

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 32 with GenericTableColumn

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

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)

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