Schema.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::Schema
 * STEREOTYPE:   ValueObject
 */
package org.andromda.jdbcmetadata;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
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 UML class(es) that every Entity extends.</p>
 */
public class Schema
    implements Serializable, Comparable<Schema>
{
    /** The serial version UID of this class. Needed for serialization. */
    private static final long serialVersionUID = 1704243037384598801L;

    // Class attributes
    /**
     * <p>The schema that owns the table.</p>
     */
    protected String schemaName;
    /**
     * <p>The database catalog that the schema belongs to.</p>
     */
    protected String catalog;
    /**
     * <p>The generator type for all entities. Defaulted based on DBMS type i.e.
     * Oracle,H2=SEQUENCE.</p>
     */
    protected String generatorType;
    /**
     * <p>Regex pattern to filter table list.</p>
     */
    protected String tableNamePattern;
    /**
     * <p>The UML class(es) that every Entity extends. Populated by configuration. The class will be
     * created in the model if it does not exist.</p>
     */
    protected String tableExtends;
    /**
     * <p>The UML class(es) that every Entity implements. Populated by configuration. The class will
     * be created in the model if it does not exist.</p>
     */
    protected String tableImplements;

    // Class associationEnds
    /**
     * <p>The tables belonging to the schema, even excluded tables which are not added to the model
     * or generated.</p>
     */
    protected List<Table> tables;

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

    /**
     * Constructor taking only required properties
     * @param schemaNameIn String <p>The schema that owns the table.</p>
     * @param catalogIn String <p>The database catalog that the schema belongs to.</p>
     * @param tableNamePatternIn String <p>Regex pattern to filter table list.</p>
     * @param tablesIn List<Table> <p>The tables belonging to the schema, even excluded tables which are not added to the model or
generated.</p>
     */
    public Schema(final String schemaNameIn, final String catalogIn, final String tableNamePatternIn, final List<Table> tablesIn)
    {
        this.schemaName = schemaNameIn;
        this.catalog = catalogIn;
        this.tableNamePattern = tableNamePatternIn;
        this.tables = tablesIn;
    }

    /**
     * Constructor with all properties
     * @param schemaNameIn String
     * @param catalogIn String
     * @param generatorTypeIn String
     * @param tableNamePatternIn String
     * @param tableExtendsIn String
     * @param tableImplementsIn String
     * @param tablesIn List<Table>
     */
    public Schema(final String schemaNameIn, final String catalogIn, final String generatorTypeIn, final String tableNamePatternIn, final String tableExtendsIn, final String tableImplementsIn, final List<Table> tablesIn)
    {
        this.schemaName = schemaNameIn;
        this.catalog = catalogIn;
        this.generatorType = generatorTypeIn;
        this.tableNamePattern = tableNamePatternIn;
        this.tableExtends = tableExtendsIn;
        this.tableImplements = tableImplementsIn;
        this.tables = tablesIn;
    }

    /**
     * Copies constructor from other Schema
     *
     * @param otherBean Cannot be <code>null</code>
     * @throws NullPointerException if the argument is <code>null</code>
     */
    public Schema(final Schema otherBean)
    {
        this.schemaName = otherBean.getSchemaName();
        this.catalog = otherBean.getCatalog();
        this.generatorType = otherBean.getGeneratorType();
        this.tableNamePattern = otherBean.getTableNamePattern();
        this.tableExtends = otherBean.getTableExtends();
        this.tableImplements = otherBean.getTableImplements();
        this.tables = otherBean.getTables();
    }

    /**
     * Copies all properties from the argument value object into this value object.
     * @param otherBean Cannot be <code>null</code>
     */
    public void copy(final Schema otherBean)
    {
        if (null != otherBean)
        {
            this.setSchemaName(otherBean.getSchemaName());
            this.setCatalog(otherBean.getCatalog());
            this.setGeneratorType(otherBean.getGeneratorType());
            this.setTableNamePattern(otherBean.getTableNamePattern());
            this.setTableExtends(otherBean.getTableExtends());
            this.setTableImplements(otherBean.getTableImplements());
            this.setTables(otherBean.getTables());
        }
    }

    /**
     * <p>The schema that owns the table.</p>
     * Get the schemaName Attribute
     * @return schemaName String
     */
    public String getSchemaName()
    {
        return this.schemaName;
    }

    /**
     * <p>The schema that owns the table.</p>
     * @param value String
     */
    public void setSchemaName(final String value)
    {
        this.schemaName = value;
    }

    /**
     * <p>The database catalog that the schema belongs to.</p>
     * Get the catalog Attribute
     * @return catalog String
     */
    public String getCatalog()
    {
        return this.catalog;
    }

    /**
     * <p>The database catalog that the schema belongs to.</p>
     * @param value String
     */
    public void setCatalog(final String value)
    {
        this.catalog = value;
    }

    /**
     * <p>The generator type for all entities. Defaulted based on DBMS type i.e.
     * Oracle,H2=SEQUENCE.</p>
     * Get the generatorType Attribute
     * @return generatorType String
     */
    public String getGeneratorType()
    {
        return this.generatorType;
    }

    /**
     * <p>The generator type for all entities. Defaulted based on DBMS type i.e.
     * Oracle,H2=SEQUENCE.</p>
     * @param value String
     */
    public void setGeneratorType(final String value)
    {
        this.generatorType = value;
    }

    /**
     * <p>Regex pattern to filter table list.</p>
     * Get the tableNamePattern Attribute
     * @return tableNamePattern String
     */
    public String getTableNamePattern()
    {
        return this.tableNamePattern;
    }

    /**
     * <p>Regex pattern to filter table list.</p>
     * @param value String
     */
    public void setTableNamePattern(final String value)
    {
        this.tableNamePattern = value;
    }

    /**
     * <p>The UML class(es) that every Entity extends. Populated by configuration. The class will be
     * created in the model if it does not exist.</p>
     * Get the tableExtends Attribute
     * @return tableExtends String
     */
    public String getTableExtends()
    {
        return this.tableExtends;
    }

    /**
     * <p>The UML class(es) that every Entity extends. Populated by configuration. The class will be
     * created in the model if it does not exist.</p>
     * @param value String
     */
    public void setTableExtends(final String value)
    {
        this.tableExtends = value;
    }

    /**
     * <p>The UML class(es) that every Entity implements. Populated by configuration. The class will
     * be created in the model if it does not exist.</p>
     * Get the tableImplements Attribute
     * @return tableImplements String
     */
    public String getTableImplements()
    {
        return this.tableImplements;
    }

    /**
     * <p>The UML class(es) that every Entity implements. Populated by configuration. The class will
     * be created in the model if it does not exist.</p>
     * @param value String
     */
    public void setTableImplements(final String value)
    {
        this.tableImplements = value;
    }

    /**
     * <p>The tables belonging to the schema, even excluded tables which are not added to the model
     * or generated.</p>
     * Get the tables 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.tables List<Table>
     */
    public List<Table> getTables()
    {
        if (this.tables == null)
        {
            this.tables = new ArrayList<Table>();
        }
        return this.tables;
    }

    /**
     * Sets the tables
     * @param value List<Table>
     */
    public void setTables(List<Table> value)
    {
        this.tables = 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;
        }
        Schema rhs = (Schema) object;
        return new EqualsBuilder()
            .append(this.getSchemaName(), rhs.getSchemaName())
            .append(this.getCatalog(), rhs.getCatalog())
            .append(this.getGeneratorType(), rhs.getGeneratorType())
            .append(this.getTableNamePattern(), rhs.getTableNamePattern())
            .append(this.getTableExtends(), rhs.getTableExtends())
            .append(this.getTableImplements(), rhs.getTableImplements())
            .append(this.getTables(), rhs.getTables())
            .isEquals();
    }

    /**
     * @param object to compare this object against
     * @return int if equal
     * @see Comparable#compareTo(Object)
     */
    public int compareTo(final Schema object)
    {
        if (object==null)
        {
            return -1;
        }
        // Check if the same object instance
        if (object==this)
        {
            return 0;
        }
        return new CompareToBuilder()
            .append(this.getSchemaName(), object.getSchemaName())
            .append(this.getCatalog(), object.getCatalog())
            .append(this.getGeneratorType(), object.getGeneratorType())
            .append(this.getTableNamePattern(), object.getTableNamePattern())
            .append(this.getTableExtends(), object.getTableExtends())
            .append(this.getTableImplements(), object.getTableImplements())
            .append(this.getTables(), object.getTables())
            .toComparison();
    }

    /**
     * @return int hashCode value
     * @see Object#hashCode()
     */
    @Override
    public int hashCode()
    {
        return new HashCodeBuilder(1249046965, -82296885)
            .append(this.getSchemaName())
            .append(this.getCatalog())
            .append(this.getGeneratorType())
            .append(this.getTableNamePattern())
            .append(this.getTableExtends())
            .append(this.getTableImplements())
            //Commented out to avoid commons-lang-2.4 recursion StackOverflowError: https://issues.apache.org/jira/browse/LANG-456
            //.append(this.getTables())
            .toHashCode();
    }

    /**
     * @return String representation of object
     * @see Object#toString()
     */
    @Override
    public String toString()
    {
        return new ToStringBuilder(this)
            .append("schemaName", this.getSchemaName())
            .append("catalog", this.getCatalog())
            .append("generatorType", this.getGeneratorType())
            .append("tableNamePattern", this.getTableNamePattern())
            .append("tableExtends", this.getTableExtends())
            .append("tableImplements", this.getTableImplements())
            .append("tables", this.getTables())
            .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 Schema that = (Schema)thatObject;

        return
            equal(this.getSchemaName(), that.getSchemaName())
            && equal(this.getCatalog(), that.getCatalog())
            && equal(this.getGeneratorType(), that.getGeneratorType())
            && equal(this.getTableNamePattern(), that.getTableNamePattern())
            && equal(this.getTableExtends(), that.getTableExtends())
            && equal(this.getTableImplements(), that.getTableImplements())
            && equal(this.getTables(), that.getTables())
        ;
    }

    /**
     * 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 java.util.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 java.util.Collection and java.util.Map
        {
            equal = first.equals(second);
        }

        return equal;
    }

    // Schema value-object java merge-point
}