Search in sources :

Example 26 with GenericTableColumn

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

the class FireBirdTableColumnManager method addObjectReorderActions.

// /////////////////////////////////////////////
// Reorder
@Override
protected void addObjectReorderActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectReorderCommand command, Map<String, Object> options) {
    final GenericTableColumn column = command.getObject();
    actions.add(new SQLDatabasePersistAction("Reorder column", "ALTER TABLE " + DBUtils.getQuotedIdentifier(command.getObject().getTable()) + " ALTER COLUMN " + DBUtils.getQuotedIdentifier(command.getObject()) + " POSITION " + column.getOrdinalPosition()));
}
Also used : GenericTableColumn(org.jkiss.dbeaver.ext.generic.model.GenericTableColumn) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 27 with GenericTableColumn

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

the class FireBirdTable method getAttributes.

@Override
public synchronized List<FireBirdTableColumn> getAttributes(@NotNull DBRProgressMonitor monitor) throws DBException {
    Collection<? extends GenericTableColumn> childColumns = super.getAttributes(monitor);
    if (childColumns == null) {
        return Collections.emptyList();
    }
    List<FireBirdTableColumn> columns = new ArrayList<>();
    for (GenericTableColumn gtc : childColumns) {
        columns.add((FireBirdTableColumn) gtc);
    }
    columns.sort(DBUtils.orderComparator());
    return columns;
}
Also used : GenericTableColumn(org.jkiss.dbeaver.ext.generic.model.GenericTableColumn)

Example 28 with GenericTableColumn

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

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

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

the class GenericTableColumnManager method createDatabaseObject.

@Override
protected GenericTableColumn createDatabaseObject(DBRProgressMonitor monitor, DBECommandContext context, Object container, Object copyFrom, Map<String, Object> options) throws DBException {
    GenericTableBase tableBase = (GenericTableBase) container;
    DBSDataType columnType = findBestDataType(tableBase.getDataSource(), DBConstants.DEFAULT_DATATYPE_NAMES);
    int columnSize = columnType != null && columnType.getDataKind() == DBPDataKind.STRING ? 100 : 0;
    GenericTableColumn column = tableBase.getDataSource().getMetaModel().createTableColumnImpl(monitor, null, tableBase, getNewColumnName(monitor, context, tableBase), columnType == null ? "INTEGER" : columnType.getName(), columnType == null ? Types.INTEGER : columnType.getTypeID(), columnType == null ? Types.INTEGER : columnType.getTypeID(), -1, columnSize, columnSize, null, null, 10, false, null, null, false, false);
    column.setPersisted(false);
    return column;
}
Also used : DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType) GenericTableColumn(org.jkiss.dbeaver.ext.generic.model.GenericTableColumn) GenericTableBase(org.jkiss.dbeaver.ext.generic.model.GenericTableBase)

Example 30 with GenericTableColumn

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

the class HiveTableColumnManager method addObjectDeleteActions.

@Override
protected void addObjectDeleteActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectDeleteCommand command, Map<String, Object> options) throws DBException {
    HiveTableColumn hiveTableColumn = (HiveTableColumn) command.getObject();
    HiveTable table = (HiveTable) hiveTableColumn.getParentObject();
    try {
        List<? extends GenericTableColumn> attributes = table.getAttributes(monitor);
        // It may not be the best option. Some of the column data may still be lost. It might be worth using a temporary table
        StringBuilder ddl = new StringBuilder();
        ddl.append("ALTER TABLE ").append(DBUtils.getObjectFullName(table, DBPEvaluationContext.DDL)).append(" REPLACE COLUMNS (");
        if (attributes != null) {
            for (int i = 0; i < attributes.size(); i++) {
                GenericTableColumn column = attributes.get(i);
                if (column != hiveTableColumn) {
                    if (i != 0) {
                        ddl.append(" ");
                    }
                    ddl.append(DBUtils.getQuotedIdentifier(column)).append(" ").append(column.getTypeName());
                    String typeModifiers = SQLUtils.getColumnTypeModifiers(table.getDataSource(), column, column.getTypeName(), column.getDataKind());
                    if (typeModifiers != null) {
                        ddl.append(typeModifiers);
                    }
                    String description = column.getDescription();
                    if (column.getDescription() != null) {
                        ddl.append(" COMMENT '").append(description).append("'");
                    }
                    if (i != attributes.size() - 1) {
                        ddl.append(",");
                    }
                }
            }
        }
        ddl.append(")");
        actions.add(new SQLDatabasePersistAction("Drop table column", ddl.toString()));
    } catch (DBException e) {
        log.debug("Columns not found in table: " + table.getName(), e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) HiveTableColumn(org.jkiss.dbeaver.ext.hive.model.HiveTableColumn) GenericTableColumn(org.jkiss.dbeaver.ext.generic.model.GenericTableColumn) HiveTable(org.jkiss.dbeaver.ext.hive.model.HiveTable) 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