Mobile.java

// license-header java merge-point
//
// Attention: Generated code! Do not modify by hand!
// Generated by EntityEmbeddable.vsl in andromda-ejb3-cartridge on 08/08/2014 12:21:03.
//
package org.andromda.demo.ejb3.mobile;

import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.andromda.demo.ejb3.user.User;

/**
 * <p>
 * TODO: Model Documentation for org.andromda.demo.ejb3.mobile.Mobile
 * </p>
 *
 * Autogenerated POJO EJB class for Mobile containing the
 * bulk of the entity implementation.
 *
 * This is autogenerated by AndroMDA using the EJB3
 * cartridge.
 *
 * DO NOT MODIFY this class.
 */
@Entity
@Table(name="MOBILE")
@NamedQuery(name="Mobile.findAll", query="SELECT m FROM Mobile AS m")
public class Mobile
    implements Serializable, Comparable<Mobile>{
    private static final long serialVersionUID = 7786760865496048921L;

    // ----------- 2 Attribute Definitions ------------
    protected String number;
    protected String network;

    // --------- 1 Relationship Definitions -----------
    protected User user;

    // ---- Manageable Display Attributes (Transient) -----

    // -------- 2 Attribute Accessors ----------
    /**
     * <p>
     * TODO: Model Documentation for number
     * </p>
     * Get the number property.
     * @return String The value of number
     */
    @Id
    @Column(name="NUMBER", nullable=false, insertable=true, updatable=true, length=12)
    @NotNull(message="number is required")
    @Size(max=12)
    public String getNumber()
    {
        return this.number;
    }

    /**
     * <p>
     * TODO: Model Documentation for number
     * </p>
     * Set the number property.
     * @param value the new value
     */
    public void setNumber(String value)
    {
        this.number = value;
    }

    /**
     * <p>
     * TODO: Model Documentation for network
     * </p>
     * Get the network property.
     * @return String The value of network
     */
    @Column(name="NETWORK", nullable=false, insertable=true, updatable=true, length=20)
    @NotNull(message="network is required")
    @Size(max=20)
    public String getNetwork()
    {
        return this.network;
    }

    /**
     * <p>
     * TODO: Model Documentation for network
     * </p>
     * Set the network property.
     * @param value the new value
     */
    public void setNetwork(String value)
    {
        this.network = value;
    }


    // ------------- 1 Relations ------------------
    /**
     * <p>
     * TODO: Model Documentation for user
     * </p>
     * Get the user
     * @return User
     */
    @ManyToOne(optional=false, cascade={CascadeType.ALL})
    @JoinColumn(name="USER_FK", insertable=true, updatable=true)
    public User getUser()
    {
        return this.user;
    }

    /**
     * <p>
     * TODO: Model Documentation for user
     * </p>
     * Set the user
     * @param userIn
     */
    public void setUser(User userIn)
    {
        this.user = userIn;
    }

    // --------------- Constructors -----------------

    /**
     * Default empty no-arg constructor
     */
    public Mobile()
    {
        // Default empty constructor
    }

    /**
     * Constructor with all updatable Entity attributes except auto incremented identifiers.
     *
     * @param number String value for the number property required=true lower=1
     * @param network String value for the network property required=true lower=1
     */
    public Mobile(String number, String network)
    {
        this.number = number;
        this.network = network;
    }


    /**
     * Constructor with all Entity attribute values and CMR relations.
     *
     * @param number String value for the number property
     * @param network String value for the network property
     * @param user User value for the user relation
     */
    public Mobile(String number, String network, User user)
    {
        // 2 updatableAttributes
        setNumber(number);
        setNetwork(network);

        // 1 relations
        setUser(user);
    }

    // -------- Common Methods -----------
    /**
     * Indicates if the argument is of the same type and all values are equal.
     * @param object The target object to compare with
     * @return boolean True if both objects a 'equal'
     * @see Object#equals(Object)
     */
    @Override
    public boolean equals(Object object)
    {
        if (null == object)
        {
            return false;
        }
        if (this == object)
        {
            return true;
        }
        if (!(object instanceof Mobile))
        {
            return false;
        }
        final Mobile that = (Mobile)object;
        if (this.getNumber() == null || that.getNumber() == null || !this.getNumber().equals(that.getNumber()))
        {
            return false;
        }
        return true;
    }

    /**
     * Returns a hash code value for the object
     * @return int The hash code value
     * @see Object#hashCode
     */
    @Override
    public int hashCode()
    {
        int hashCode = 0;
        hashCode = 29 * hashCode + (getNumber() == null ? 0 : getNumber().hashCode());

        return hashCode;
    }

    /**
     * Returns a String representation of the object
     * @return String Textual representation of the object displaying name/value pairs for all attributes
     * @see Object#toString
     */
    @Override
    public String toString()
    {
        StringBuilder sb = new StringBuilder();
        sb.append("Mobile(");
        sb.append(" number=").append(getNumber());
        sb.append(" network=").append(getNetwork());
        sb.append(" user=").append(getUser());
        sb.append(")");
        return sb.toString();
    }

    /**
     * @see Comparable#compareTo
     */
    @Override
    public int compareTo(Mobile o)
    {
        int cmp = 0;
        if (this.getNumber() != null)
        {
            cmp = this.getNumber().compareTo(o.getNumber());
        }
        else
        {
            if (this.getNetwork() != null)
            {
                cmp = (cmp != 0 ? cmp : this.getNetwork().compareTo(o.getNetwork()));
            }
        }
        return cmp;
    }


}