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

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

There is a newer version: 3.6.2.5.inovus
Show newest version
package liquibase.structure.core;

import liquibase.statement.NotNullConstraint;
import liquibase.util.StringUtils;

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

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

    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 = StringUtils.trimToEmpty(this.getSchema().getName()).equalsIgnoreCase(StringUtils.trimToEmpty(that.getSchema().getName()));
            if (!schemasTheSame) {
                return false;
            }
        }

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

    }

    @Override
    public int hashCode() {
        return StringUtils.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;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy