Search in sources :

Example 11 with GenericTableColumn

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

the class SQLiteTableColumnManager method addObjectDeleteActions.

@Override
protected void addObjectDeleteActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectDeleteCommand command, Map<String, Object> options) throws DBException {
    final GenericTableColumn column = command.getObject();
    final GenericTableBase table = column.getTable();
    final List<? extends GenericTableColumn> attributes = table.getAttributes(monitor);
    if (CommonUtils.isEmpty(attributes)) {
        throw new DBException("Table was deleted");
    }
    final String tableColumns = attributes.stream().filter(x -> !x.getName().equals(column.getName()) && x.isPersisted()).map(DBUtils::getQuotedIdentifier).collect(Collectors.joining(",\n  "));
    final String tableName = DBUtils.getQuotedIdentifier(table);
    actions.add(new SQLDatabasePersistActionComment(table.getDataSource(), "Drop column " + DBUtils.getQuotedIdentifier(column)));
    actions.add(new SQLDatabasePersistAction("Create temporary table from original table", "CREATE TEMPORARY TABLE temp AS\nSELECT\n  " + tableColumns + "\nFROM " + tableName));
    actions.add(new SQLDatabasePersistAction("Drop original table", "\nDROP TABLE " + tableName + ";\n"));
    actions.add(new SQLDatabasePersistAction("Create new table", DBStructUtils.generateTableDDL(monitor, table, Collections.emptyMap(), false)));
    actions.add(new SQLDatabasePersistAction("Insert values from temporary table to new table", "INSERT INTO " + tableName + "\n (" + tableColumns + ")\nSELECT\n  " + tableColumns + "\nFROM temp"));
    actions.add(new SQLDatabasePersistAction("Drop temporary table", "\nDROP TABLE temp"));
}
Also used : DBException(org.jkiss.dbeaver.DBException) SQLDatabasePersistActionComment(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistActionComment) GenericTableColumn(org.jkiss.dbeaver.ext.generic.model.GenericTableColumn) GenericTableBase(org.jkiss.dbeaver.ext.generic.model.GenericTableBase) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 12 with GenericTableColumn

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

the class FireBirdTableColumnManager method addObjectModifyActions.

/**
 * Is is pretty standard
 */
@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 + "TYPE " + typeClause));
    }
    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()));
        }
    }
    if (command.getProperty(DBConstants.PROP_ID_DESCRIPTION) != null) {
        actionList.add(new SQLDatabasePersistAction("Set column comment", "COMMENT ON COLUMN " + DBUtils.getObjectFullName(column.getTable(), DBPEvaluationContext.DDL) + "." + DBUtils.getQuotedIdentifier(column) + " IS " + SQLUtils.quoteString(column, CommonUtils.notEmpty(column.getDescription()))));
    }
}
Also used : GenericTableColumn(org.jkiss.dbeaver.ext.generic.model.GenericTableColumn) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 13 with GenericTableColumn

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

the class FireBirdTableColumnManager 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 14 with GenericTableColumn

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

the class FireBirdView 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 15 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, GenericTable parent, Object copyFrom) {
    DBSDataType columnType = findBestDataType(parent.getDataSource(), DBConstants.DEFAULT_DATATYPE_NAMES);
    final GenericTableColumn column = new GenericTableColumn(parent);
    column.setName(getNewColumnName(monitor, context, parent));
    column.setTypeName(columnType == null ? "INTEGER" : columnType.getName());
    column.setMaxLength(columnType != null && columnType.getDataKind() == DBPDataKind.STRING ? 100 : 0);
    column.setValueType(columnType == null ? Types.INTEGER : columnType.getTypeID());
    column.setOrdinalPosition(-1);
    return column;
}
Also used : DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType) 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