Search in sources :

Example 1 with SqlSchemaMetadata

use of org.molgenis.emx2.sql.SqlSchemaMetadata in project molgenis-emx2 by molgenis.

the class SqlTableMetadata method alterColumn.

@Override
public TableMetadata alterColumn(String columnName, Column column) {
    // ignore mg_ columns
    if (column.getName().startsWith("mg_"))
        return this;
    Column oldColumn = getColumn(columnName);
    if (oldColumn == null) {
        throw new MolgenisException("Alter column failed: Column  '" + getTableName() + "." + column.getName() + "' does not exist");
    }
    if (getInherit() != null && getInheritedTable().getColumn(columnName) != null) {
        throw new MolgenisException("Alter column " + getTableName() + "." + columnName + " failed: column is part of inherited table " + getInherit());
    }
    if (getInherit() != null && getInheritedTable().getColumn(column.getName()) != null) {
        throw new MolgenisException("Rename column from " + getTableName() + "." + columnName + " to " + getTableName() + "." + column.getName() + " failed: column '" + column.getName() + "' is part of inherited table " + getInherit());
    }
    getDatabase().tx(db -> sync(alterColumnTransaction(getSchemaName(), getTableName(), columnName, column, db)));
    // reload the state
    ((SqlSchemaMetadata) getSchema()).sync(getDatabase().getSchema(getSchemaName()).getMetadata());
    return this;
}
Also used : MetadataUtils.deleteColumn(org.molgenis.emx2.sql.MetadataUtils.deleteColumn)

Aggregations

MetadataUtils.deleteColumn (org.molgenis.emx2.sql.MetadataUtils.deleteColumn)1