Table.java

// license-header java merge-point
//
/**
 * @author Generated on 09/21/2012 13:39:17-0400 Do not modify by hand!
 *
 * TEMPLATE:     ValueObject.vsl in andromda-java-cartridge.
 * MODEL CLASS:  JDBCMetadataModel::org.andromda.jdbcmetadata::Table
 * STEREOTYPE:   ValueObject
 */
package org.andromda.jdbcmetadata;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * <p>The SQL Table containing columns, indexes, and PK / FK.</p>
 */
public class Table
    implements Serializable, Comparable<Table>
{
    /** The serial version UID of this class. Needed for serialization. */
    private static final long serialVersionUID = -1899186184194947390L;

    // Class attributes
    /**
     * <p>Typical types are "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY",
     * "ALIAS", "SYNONYM".</p>
     */
    protected String type;
    /**
     * <p>True if table reverse engineering is excluded for this entire table.</p>
     */
    protected boolean excluded = false;
    /**
     * boolean setter for primitive attribute, so we can tell if it's initialized
     */
    protected boolean setExcluded = false;
    /**
     * <p>The SQL name of the table.</p>
     */
    protected String name;
    /**
     * <p>The name of the Primary Key for the table. A table can only have one Primary Key.</p>
     */
    protected String pkName;
    /**
     * <p>The logical Entity name translated from the Table physical name.</p>
     */
    protected String umlName;
    /**
     * <p>The SQL table comment / description.</p>
     */
    protected String description;
    /**
     * <p>The name of the class which this entity extends, in UML standard format
     * packagename::ClassName. The entity can only extend one class.</p>
     */
    protected String extend;
    /**
     * <p>The name of the classes which this entity implements, in UML standard format
     * packagename::ClassName. The entity can implement multiple interfaces. JPA standard interfaces
     * (Serializable) do not need to be specified.</p>
     */
    protected String implement;

    // Class associationEnds
    /**
     * <p>The columns belonging to this table, including excluded columns.</p>
     */
    protected List<Column> columns;

    /**
     * <p>The schema that owns this table.</p>
     */
    protected Schema schema;

    /**
     * <p>The indexes belonging to this table</p>
     */
    protected Collection<Index> indexes;

    /**
     * <p>The FKs where this table is the table referenced by the FK on another table.</p>
     */
    protected Collection<ForeignKey> referencedKeys;

    /**
     * <p>The PK Columns belonging to this table, in the correct PK column order.</p>
     */
    protected List<Column> pkColumns;

    /**
     * <p>The FKs belonging to this table</p>
     */
    protected Collection<ForeignKey> foreignKeys;

    /** Default Constructor with no properties */
    public Table()
    {
        // Documented empty block - avoid compiler warning - no super constructor
    }

    /**
     * Constructor taking only required properties
     * @param typeIn String <p>Typical types are "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY",
"ALIAS", "SYNONYM".</p>
     * @param excludedIn boolean <p>True if table reverse engineering is excluded for this entire table.</p>
     * @param nameIn String <p>The SQL name of the table.</p>
     * @param pkNameIn String <p>The name of the Primary Key for the table. A table can only have one Primary Key.</p>
     * @param umlNameIn String <p>The logical Entity name translated from the Table physical name.</p>
     * @param descriptionIn String <p>The SQL table comment / description.</p>
     * @param columnsIn List<Column> <p>The columns belonging to this table, including excluded columns.</p>
     * @param schemaIn Schema <p>The schema that owns this table.</p>
     * @param pkColumnsIn List<Column> <p>The PK Columns belonging to this table, in the correct PK column order.</p>
     */
    public Table(final String typeIn, final boolean excludedIn, final String nameIn, final String pkNameIn, final String umlNameIn, final String descriptionIn, final List<Column> columnsIn, final Schema schemaIn, final List<Column> pkColumnsIn)
    {
        this.type = typeIn;
        this.excluded = excludedIn;
        this.setExcluded = true;
        this.name = nameIn;
        this.pkName = pkNameIn;
        this.umlName = umlNameIn;
        this.description = descriptionIn;
        this.columns = columnsIn;
        this.schema = schemaIn;
        this.pkColumns = pkColumnsIn;
    }

    /**
     * Constructor with all properties
     * @param typeIn String
     * @param excludedIn boolean
     * @param nameIn String
     * @param pkNameIn String
     * @param umlNameIn String
     * @param descriptionIn String
     * @param extendIn String
     * @param implementIn String
     * @param columnsIn List<Column>
     * @param schemaIn Schema
     * @param indexesIn Collection<Index>
     * @param referencedKeysIn Collection<ForeignKey>
     * @param pkColumnsIn List<Column>
     * @param foreignKeysIn Collection<ForeignKey>
     */
    public Table(final String typeIn, final boolean excludedIn, final String nameIn, final String pkNameIn, final String umlNameIn, final String descriptionIn, final String extendIn, final String implementIn, final List<Column> columnsIn, final Schema schemaIn, final Collection<Index> indexesIn, final Collection<ForeignKey> referencedKeysIn, final List<Column> pkColumnsIn, final Collection<ForeignKey> foreignKeysIn)
    {
        this.type = typeIn;
        this.excluded = excludedIn;
        this.setExcluded = true;
        this.name = nameIn;
        this.pkName = pkNameIn;
        this.umlName = umlNameIn;
        this.description = descriptionIn;
        this.extend = extendIn;
        this.implement = implementIn;
        this.columns = columnsIn;
        this.schema = schemaIn;
        this.indexes = indexesIn;
        this.referencedKeys = referencedKeysIn;
        this.pkColumns = pkColumnsIn;
        this.foreignKeys = foreignKeysIn;
    }

    /**
     * Copies constructor from other Table
     *
     * @param otherBean Cannot be <code>null</code>
     * @throws NullPointerException if the argument is <code>null</code>
     */
    public Table(final Table otherBean)
    {
        this.type = otherBean.getType();
        this.excluded = otherBean.isExcluded();
        this.setExcluded = true;
        this.name = otherBean.getName();
        this.pkName = otherBean.getPkName();
        this.umlName = otherBean.getUmlName();
        this.description = otherBean.getDescription();
        this.extend = otherBean.getExtend();
        this.implement = otherBean.getImplement();
        this.columns = otherBean.getColumns();
        this.schema = otherBean.getSchema();
        this.indexes = otherBean.getIndexes();
        this.referencedKeys = otherBean.getReferencedKeys();
        this.pkColumns = otherBean.getPkColumns();
        this.foreignKeys = otherBean.getForeignKeys();
    }

    /**
     * Copies all properties from the argument value object into this value object.
     * @param otherBean Cannot be <code>null</code>
     */
    public void copy(final Table otherBean)
    {
        if (null != otherBean)
        {
            this.setType(otherBean.getType());
            this.setExcluded(otherBean.isExcluded());
            this.setExcluded = true;
            this.setName(otherBean.getName());
            this.setPkName(otherBean.getPkName());
            this.setUmlName(otherBean.getUmlName());
            this.setDescription(otherBean.getDescription());
            this.setExtend(otherBean.getExtend());
            this.setImplement(otherBean.getImplement());
            this.setColumns(otherBean.getColumns());
            this.setSchema(otherBean.getSchema());
            this.setIndexes(otherBean.getIndexes());
            this.setReferencedKeys(otherBean.getReferencedKeys());
            this.setPkColumns(otherBean.getPkColumns());
            this.setForeignKeys(otherBean.getForeignKeys());
        }
    }

    /**
     * <p>Typical types are "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY",
     * "ALIAS", "SYNONYM".</p>
     * Get the type Attribute
     * @return type String
     */
    public String getType()
    {
        return this.type;
    }

    /**
     * <p>Typical types are "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY",
     * "ALIAS", "SYNONYM".</p>
     * @param value String
     */
    public void setType(final String value)
    {
        this.type = value;
    }

    /**
     * <p>True if table reverse engineering is excluded for this entire table.</p>
     * Get the excluded Attribute
     * @return excluded boolean
     */
    public boolean isExcluded()
    {
        return this.excluded;
    }

    /**
     * <p>True if table reverse engineering is excluded for this entire table.</p>
     * Duplicates isBoolean method, for use as Jaxb2 compatible object
     * Get the excluded Attribute
     * @return excluded boolean
     */
    @Deprecated
    public boolean getExcluded()
    {
        return this.excluded;
    }

    /**
     * <p>True if table reverse engineering is excluded for this entire table.</p>
     * @param value boolean
     */
    public void setExcluded(final boolean value)
    {
        this.excluded = value;
        this.setExcluded = true;
    }

    /**
     * Return true if the primitive attribute excluded is set, through the setter or constructor
     * @return true if the attribute value has been set
     */
    public boolean isSetExcluded()
    {
        return this.setExcluded;
    }

    /**
     * <p>The SQL name of the table.</p>
     * Get the name Attribute
     * @return name String
     */
    public String getName()
    {
        return this.name;
    }

    /**
     * <p>The SQL name of the table.</p>
     * @param value String
     */
    public void setName(final String value)
    {
        this.name = value;
    }

    /**
     * <p>The name of the Primary Key for the table. A table can only have one Primary Key.</p>
     * Get the pkName Attribute
     * @return pkName String
     */
    public String getPkName()
    {
        return this.pkName;
    }

    /**
     * <p>The name of the Primary Key for the table. A table can only have one Primary Key.</p>
     * @param value String
     */
    public void setPkName(final String value)
    {
        this.pkName = value;
    }

    /**
     * <p>The logical Entity name translated from the Table physical name.</p>
     * Get the umlName Attribute
     * @return umlName String
     */
    public String getUmlName()
    {
        return this.umlName;
    }

    /**
     * <p>The logical Entity name translated from the Table physical name.</p>
     * @param value String
     */
    public void setUmlName(final String value)
    {
        this.umlName = value;
    }

    /**
     * <p>The SQL table comment / description.</p>
     * Get the description Attribute
     * @return description String
     */
    public String getDescription()
    {
        return this.description;
    }

    /**
     * <p>The SQL table comment / description.</p>
     * @param value String
     */
    public void setDescription(final String value)
    {
        this.description = value;
    }

    /**
     * <p>The name of the class which this entity extends, in UML standard format
     * packagename::ClassName. The entity can only extend one class.</p>
     * Get the extend Attribute
     * @return extend String
     */
    public String getExtend()
    {
        return this.extend;
    }

    /**
     * <p>The name of the class which this entity extends, in UML standard format
     * packagename::ClassName. The entity can only extend one class.</p>
     * @param value String
     */
    public void setExtend(final String value)
    {
        this.extend = value;
    }

    /**
     * <p>The name of the classes which this entity implements, in UML standard format
     * packagename::ClassName. The entity can implement multiple interfaces. JPA standard interfaces
     * (Serializable) do not need to be specified.</p>
     * Get the implement Attribute
     * @return implement String
     */
    public String getImplement()
    {
        return this.implement;
    }

    /**
     * <p>The name of the classes which this entity implements, in UML standard format
     * packagename::ClassName. The entity can implement multiple interfaces. JPA standard interfaces
     * (Serializable) do not need to be specified.</p>
     * @param value String
     */
    public void setImplement(final String value)
    {
        this.implement = value;
    }

    /**
     * <p>The columns belonging to this table, including excluded columns.</p>
     * Get the columns Association
     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the object.
     * @return this.columns List<Column>
     */
    public List<Column> getColumns()
    {
        if (this.columns == null)
        {
            this.columns = new ArrayList<Column>();
        }
        return this.columns;
    }

    /**
     * Sets the columns
     * @param value List<Column>
     */
    public void setColumns(List<Column> value)
    {
        this.columns = value;
    }

    /**
     * <p>The schema that owns this table.</p>
     * Get the schema Association
     * @return this.schema Schema
     */
    public Schema getSchema()
    {
        return this.schema;
    }

    /**
     * Sets the schema
     * @param value Schema
     */
    public void setSchema(Schema value)
    {
        this.schema = value;
    }

    /**
     * <p>The indexes belonging to this table</p>
     * Get the indexes Association
     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the object.
     * @return this.indexes Collection<Index>
     */
    public Collection<Index> getIndexes()
    {
        if (this.indexes == null)
        {
            this.indexes = new ArrayList<Index>();
        }
        return this.indexes;
    }

    /**
     * Sets the indexes
     * @param value Collection<Index>
     */
    public void setIndexes(Collection<Index> value)
    {
        this.indexes = value;
    }

    /**
     * <p>The FKs where this table is the table referenced by the FK on another table.</p>
     * Get the referencedKeys Association
     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the object.
     * @return this.referencedKeys Collection<ForeignKey>
     */
    public Collection<ForeignKey> getReferencedKeys()
    {
        if (this.referencedKeys == null)
        {
            this.referencedKeys = new ArrayList<ForeignKey>();
        }
        return this.referencedKeys;
    }

    /**
     * Sets the referencedKeys
     * @param value Collection<ForeignKey>
     */
    public void setReferencedKeys(Collection<ForeignKey> value)
    {
        this.referencedKeys = value;
    }

    /**
     * <p>The PK Columns belonging to this table, in the correct PK column order.</p>
     * Get the pkColumns Association
     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the object.
     * @return this.pkColumns List<Column>
     */
    public List<Column> getPkColumns()
    {
        if (this.pkColumns == null)
        {
            this.pkColumns = new ArrayList<Column>();
        }
        return this.pkColumns;
    }

    /**
     * Sets the pkColumns
     * @param value List<Column>
     */
    public void setPkColumns(List<Column> value)
    {
        this.pkColumns = value;
    }

    /**
     * <p>The FKs belonging to this table</p>
     * Get the foreignKeys Association
     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the object.
     * @return this.foreignKeys Collection<ForeignKey>
     */
    public Collection<ForeignKey> getForeignKeys()
    {
        if (this.foreignKeys == null)
        {
            this.foreignKeys = new ArrayList<ForeignKey>();
        }
        return this.foreignKeys;
    }

    /**
     * Sets the foreignKeys
     * @param value Collection<ForeignKey>
     */
    public void setForeignKeys(Collection<ForeignKey> value)
    {
        this.foreignKeys = value;
    }

    /**
     * @param object to compare this object against
     * @return boolean if equal
     * @see Object#equals(Object)
     */
    @Override
    public boolean equals(final Object object)
    {
        if (object==null || object.getClass() != this.getClass())
        {
             return false;
        }
        // Check if the same object instance
        if (object==this)
        {
            return true;
        }
        Table rhs = (Table) object;
        return new EqualsBuilder()
            .append(this.getType(), rhs.getType())
            .append(this.isExcluded(), rhs.isExcluded())
            .append(this.getName(), rhs.getName())
            .append(this.getPkName(), rhs.getPkName())
            .append(this.getUmlName(), rhs.getUmlName())
            .append(this.getDescription(), rhs.getDescription())
            .append(this.getExtend(), rhs.getExtend())
            .append(this.getImplement(), rhs.getImplement())
            .append(this.getColumns(), rhs.getColumns())
            .append(this.getSchema(), rhs.getSchema())
            .append(this.getIndexes(), rhs.getIndexes())
            .append(this.getReferencedKeys(), rhs.getReferencedKeys())
            .append(this.getPkColumns(), rhs.getPkColumns())
            .append(this.getForeignKeys(), rhs.getForeignKeys())
            .isEquals();
    }

    /**
     * @param object to compare this object against
     * @return int if equal
     * @see Comparable#compareTo(Object)
     */
    public int compareTo(final Table object)
    {
        if (object==null)
        {
            return -1;
        }
        // Check if the same object instance
        if (object==this)
        {
            return 0;
        }
        return new CompareToBuilder()
            .append(this.getType(), object.getType())
            .append(this.isExcluded(), object.isExcluded())
            .append(this.getName(), object.getName())
            .append(this.getPkName(), object.getPkName())
            .append(this.getUmlName(), object.getUmlName())
            .append(this.getDescription(), object.getDescription())
            .append(this.getExtend(), object.getExtend())
            .append(this.getImplement(), object.getImplement())
            .append(this.getColumns(), object.getColumns())
            .append(this.getSchema(), object.getSchema())
            .append(this.getIndexes(), object.getIndexes())
            .append(this.getReferencedKeys(), object.getReferencedKeys())
            .append(this.getPkColumns(), object.getPkColumns())
            .append(this.getForeignKeys(), object.getForeignKeys())
            .toComparison();
    }

    /**
     * @return int hashCode value
     * @see Object#hashCode()
     */
    @Override
    public int hashCode()
    {
        return new HashCodeBuilder(1249046965, -82296885)
            .append(this.getType())
            .append(this.isExcluded())
            .append(this.getName())
            .append(this.getPkName())
            .append(this.getUmlName())
            .append(this.getDescription())
            .append(this.getExtend())
            .append(this.getImplement())
            //Commented out to avoid commons-lang-2.4 recursion StackOverflowError: https://issues.apache.org/jira/browse/LANG-456
            //.append(this.getColumns())
            .append(this.getSchema())
            //Commented out to avoid commons-lang-2.4 recursion StackOverflowError: https://issues.apache.org/jira/browse/LANG-456
            //.append(this.getIndexes())
            //Commented out to avoid commons-lang-2.4 recursion StackOverflowError: https://issues.apache.org/jira/browse/LANG-456
            //.append(this.getReferencedKeys())
            //Commented out to avoid commons-lang-2.4 recursion StackOverflowError: https://issues.apache.org/jira/browse/LANG-456
            //.append(this.getPkColumns())
            //Commented out to avoid commons-lang-2.4 recursion StackOverflowError: https://issues.apache.org/jira/browse/LANG-456
            //.append(this.getForeignKeys())
            .toHashCode();
    }

    /**
     * @return String representation of object
     * @see Object#toString()
     */
    @Override
    public String toString()
    {
        return new ToStringBuilder(this)
            .append("type", this.getType())
            .append("excluded", this.isExcluded())
            .append("name", this.getName())
            .append("pkName", this.getPkName())
            .append("umlName", this.getUmlName())
            .append("description", this.getDescription())
            .append("extend", this.getExtend())
            .append("implement", this.getImplement())
            .append("columns", this.getColumns())
            .append("schema", this.getSchema())
            .append("indexes", this.getIndexes())
            .append("referencedKeys", this.getReferencedKeys())
            .append("pkColumns", this.getPkColumns())
            .append("foreignKeys", this.getForeignKeys())
            .toString();
    }

    /**
     * Compares the properties of this instance to the properties of the argument. This method will return
     * {@code false} as soon as it detects that the argument is {@code null} or not of the same type as
     * (or a sub-type of) this instance's type.
     *
     * <p/>For array, collection or map properties the comparison will be done one level deep, in other words:
     * the elements will be compared using the {@code equals()} operation.
     *
     * <p/>Note that two properties will be considered equal when both values are {@code null}.
     *
     * @param thatObject the object containing the properties to compare against this instance
     * @return this method will return {@code true} in case the argument has the same type as this class, or is a
     *      sub-type of this class and all properties as found on this class have equal values when queried on that
     *      argument instance; in all other cases this method will return {@code false}
     */
    public boolean equalProperties(final Object thatObject)
    {
        if (thatObject == null || !this.getClass().isAssignableFrom(thatObject.getClass()))
        {
            return false;
        }

        final Table that = (Table)thatObject;

        return
            equal(this.getType(), that.getType())
            && equal(this.isExcluded(), that.isExcluded())
            && equal(this.getName(), that.getName())
            && equal(this.getPkName(), that.getPkName())
            && equal(this.getUmlName(), that.getUmlName())
            && equal(this.getDescription(), that.getDescription())
            && equal(this.getExtend(), that.getExtend())
            && equal(this.getImplement(), that.getImplement())
            && equal(this.getColumns(), that.getColumns())
            && equal(this.getSchema(), that.getSchema())
            && equal(this.getIndexes(), that.getIndexes())
            && equal(this.getReferencedKeys(), that.getReferencedKeys())
            && equal(this.getPkColumns(), that.getPkColumns())
            && equal(this.getForeignKeys(), that.getForeignKeys())
        ;
    }

    /**
     * This is a convenient helper method which is able to detect whether or not two values are equal. Two values
     * are equal when they are both {@code null}, are arrays of the same length with equal elements or are
     * equal objects (this includes {@link Collection} and {@link java.util.Map} instances).
     *
     * <p/>Note that for array, collection or map instances the comparison runs one level deep.
     *
     * @param first the first object to compare, may be {@code null}
     * @param second the second object to compare, may be {@code null}
     * @return this method will return {@code true} in case both objects are equal as explained above;
     *      in all other cases this method will return {@code false}
     */
    protected static boolean equal(final Object first, final Object second)
    {
        final boolean equal;

        if (first == null)
        {
            equal = (second == null);
        }
        else if (first.getClass().isArray() && (second != null) && second.getClass().isArray())
        {
            equal = Arrays.equals((Object[])first, (Object[])second);
        }
        else // note that the following also covers Collection and java.util.Map
        {
            equal = first.equals(second);
        }

        return equal;
    }

    // Table value-object java merge-point
}