use of org.jkiss.dbeaver.ext.generic.model.GenericTableColumn in project dbeaver by dbeaver.
the class GenericTableColumnManager method getNestedDeclaration.
@Override
public StringBuilder getNestedDeclaration(GenericTable owner, DBECommandAbstract<GenericTableColumn> command, Map<String, Object> options) {
StringBuilder decl = super.getNestedDeclaration(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 dbeaver.
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;
}
use of org.jkiss.dbeaver.ext.generic.model.GenericTableColumn in project dbeaver by serge-rider.
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;
}
use of org.jkiss.dbeaver.ext.generic.model.GenericTableColumn in project dbeaver by serge-rider.
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;
}
use of org.jkiss.dbeaver.ext.generic.model.GenericTableColumn in project dbeaver by serge-rider.
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"));
}
Aggregations