All Downloads are FREE. Search and download functionalities are using the official Maven repository.

liquibase.structure.core.Table Maven / Gradle / Ivy

The newest version!
package liquibase.structure.core;

import liquibase.statement.NotNullConstraint;
import liquibase.util.BooleanUtil;
import liquibase.util.StringUtil;

import java.util.ArrayList;
import java.util.List;

public class Table extends Relation {


    public Table() {
        setAttribute("outgoingForeignKeys", new ArrayList());
        setAttribute("indexes", new ArrayList());
        setAttribute("uniqueConstraints", new ArrayList());
        setAttribute("notNullConstraints", new ArrayList());
    }

    public Table(String catalogName, String schemaName, String tableName) {
        this.setSchema(new Schema(catalogName, schemaName));
        setName(tableName);
    }

    public PrimaryKey getPrimaryKey() {
        return getAttribute("primaryKey", PrimaryKey.class);
    }

    public void setPrimaryKey(PrimaryKey primaryKey) {
        this.setAttribute("primaryKey", primaryKey);
    }

    /**
     * Returns the list of all outgoing FOREIGN KEYS from this table
     */
    public List getOutgoingForeignKeys() {
        List fkList = getAttribute("outgoingForeignKeys", List.class);
        return ((fkList == null) ? new ArrayList<>(0) : fkList);
    }

    @Override
    public List getIndexes() {
        return getAttribute("indexes", List.class);
    }

    @Override
    public List getUniqueConstraints() {
        return getAttribute("uniqueConstraints", List.class);
    }
    public List getNotNullConstraints() {
        return getAttribute("notNullConstraints", List.class);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if ((o == null) || (getClass() != o.getClass())) return false;

        Table that = (Table) o;

        if ((this.getSchema() != null) && (that.getSchema() != null)) {
            boolean schemasTheSame = this.getSchema().equals(that.getSchema());
            if (!schemasTheSame) {
                return false;
            }
        }

        return getName().equalsIgnoreCase(that.getName());

    }

    @Override
    public int hashCode() {
        return StringUtil.trimToEmpty(getName()).toUpperCase().hashCode();
    }

    @Override
    public String toString() {
        return getName();
    }

    @Override
    public Table setName(String name) {
        return (Table) super.setName(name);
    }

    public String getTablespace() {
        return getAttribute("tablespace",String.class);
    }

    public Table setTablespace(String tablespace) {
        setAttribute("tablespace", tablespace);
        return this;
    }

    public Boolean getDefaultTablespace() {
        return getAttribute("default_tablespace", Boolean.class);
    }

    public Table setDefaultTablespace(Boolean tablespace) {
        setAttribute("default_tablespace", tablespace);
        return this;
    }

    public boolean isDefaultTablespace() {
        Boolean b = getAttribute("default_tablespace",Boolean.class);
        return BooleanUtil.isTrue(b);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy