use of org.jkiss.dbeaver.ext.generic.model.GenericTableColumn in project dbeaver by dbeaver.
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 dbeaver.
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);
}
}
use of org.jkiss.dbeaver.ext.generic.model.GenericTableColumn in project dbeaver by serge-rider.
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();
}
use of org.jkiss.dbeaver.ext.generic.model.GenericTableColumn in project dbeaver by serge-rider.
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())));
}
use of org.jkiss.dbeaver.ext.generic.model.GenericTableColumn in project dbeaver by serge-rider.
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()))));
}
}
Aggregations