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()));
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations