User.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.user;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.andromda.demo.ejb3.account.Account;
import org.andromda.demo.ejb3.mobile.Mobile;

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

    // ----------- 2 Attribute Definitions ------------
    protected String principalId;
    protected String name;

    // --------- 2 Relationship Definitions -----------
    protected Account account;
    protected Set<Mobile> mobiles = new HashSet<Mobile>();

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

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

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

    /**
     * <p>
     * TODO: Model Documentation for name
     * </p>
     * Get the name property.
     * @return String The value of name
     */
    @Column(name="NAME", insertable=true, updatable=true, length=50)
    @Size(max=50)
    public String getName()
    {
        return this.name;
    }

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


    // ------------- 2 Relations ------------------
    /**
     * <p>
     * TODO: Model Documentation for account
     * </p>
     * Get the account
     * @return Account
     */
    @OneToOne(cascade={CascadeType.PERSIST, CascadeType.REMOVE}, mappedBy="user")
    public Account getAccount()
    {
        return this.account;
    }

   /**
     * <p>
     * TODO: Model Documentation for account
     * </p>
    * Set the account
    * @param accountIn
    */
    public void setAccount(Account accountIn)
    {
        this.account = accountIn;
    }

    /**
     * <p>
     * TODO: Model Documentation for mobiles
     * </p>
     * Get the mobiles Collection
     * @return Set<Mobile>
     */
    @OneToMany(mappedBy="user")
    public Set<Mobile> getMobiles()
    {
        return this.mobiles;
    }

    /**
     * <p>
     * TODO: Model Documentation for mobiles
     * </p>
     * Set the mobiles
     * @param mobilesIn
     */
    public void setMobiles (Set<Mobile> mobilesIn)
    {
        this.mobiles = mobilesIn;
    }

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

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

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

    /**
     * Constructor with required Entity attributes except auto incremented identifiers.
     *
     * @param principalId Value for the principalId property
     */
    public User(String principalId)
    {
        this.principalId = principalId;
    }

    /**
     * Constructor with all Entity attribute values and CMR relations.
     *
     * @param principalId String value for the principalId property
     * @param name String value for the name property
     * @param account Account value for the account relation
     * @param mobiles Set<Mobile> value for the mobiles relation
     */
    public User(String principalId, String name, Account account, Set<Mobile> mobiles)
    {
        // 2 updatableAttributes
        setPrincipalId(principalId);
        setName(name);

        // 2 relations
        setAccount(account);
        setMobiles(mobiles);
    }

    /**
     * Constructor with required Entity attribute values and required CMR relations.
     *
     * @param principalId String value for the principalId property
     * @param account Account value for the account relation
     */
    public User(String principalId, Account account)
    {
        // 1 requiredAttributes
        setPrincipalId(principalId);

        // 1 required association relations
        setAccount(account);
    }

    // -------- 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 User))
        {
            return false;
        }
        final User that = (User)object;
        if (this.getPrincipalId() == null || that.getPrincipalId() == null || !this.getPrincipalId().equals(that.getPrincipalId()))
        {
            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 + (getPrincipalId() == null ? 0 : getPrincipalId().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("User(");
        sb.append(" principalId=").append(getPrincipalId());
        sb.append(" name=").append(getName());
        sb.append(")");
        return sb.toString();
    }

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


}