Search in sources :

Example 16 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(GenericTable owner, DBECommandAbstract<GenericTableColumn> command) {
    StringBuilder decl = super.getNestedDeclaration(owner, command);
    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 17 with GenericTableColumn

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

the class FireBirdUtils method getViewSourceWithHeader.

public static String getViewSourceWithHeader(DBRProgressMonitor monitor, GenericTableBase view, String source) throws DBException {
    Version version = getFireBirdServerVersion(view.getDataSource());
    StringBuilder sql = new StringBuilder();
    sql.append("CREATE ");
    if (version.getMajor() > 2 || (version.getMajor() == 2 && version.getMinor() >= 5)) {
        sql.append("OR ALTER ");
    }
    sql.append("VIEW ").append(view.getName()).append(" ");
    Collection<? extends GenericTableColumn> columns = view.getAttributes(monitor);
    if (columns != null) {
        sql.append("(");
        boolean first = true;
        for (GenericTableColumn column : columns) {
            if (!first) {
                sql.append(", ");
            }
            first = false;
            sql.append(DBUtils.getQuotedIdentifier(column));
        }
        sql.append(")\n");
    }
    sql.append("AS\n").append(source);
    return sql.toString();
}
Also used : Version(org.osgi.framework.Version) GenericTableColumn(org.jkiss.dbeaver.ext.generic.model.GenericTableColumn)

Example 18 with GenericTableColumn

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

the class FireBirdTableColumnManager 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()) + " ALTER 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 19 with GenericTableColumn

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

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

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

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)

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