Customer.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:04.
//
package org.andromda.demo.ejb3.customer;

import java.io.Serializable;
import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

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

    // ----------- 5 Attribute Definitions ------------
    protected String username;
    protected String password;
    protected String name;
    protected Credential credentials;
    protected Long customerId;

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

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

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

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

    /**
     * <p>
     * TODO: Model Documentation for name
     * </p>
     * Get the name property.
     * @return String The value of name
     */
    @Column(name="NAME", nullable=false, insertable=true, updatable=true, length=64)
    @NotNull(message="name is required")
    @Size(max=64)
    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;
    }

    /**
     * <p>
     * TODO: Model Documentation for credentials
     * </p>
     * Get the credentials property.
     * @return Credential The value of credentials
     */
    @Embedded
    @AttributeOverrides
    ({
        @AttributeOverride(name="name", column=@Column(name="CREDENTIALS_NAME", nullable=false, insertable=true, updatable=true, length=64)),
        @AttributeOverride(name="mobileNumber", column=@Column(name="CREDENTIALS_MOBILE_NUMBER", insertable=true, updatable=true, length=14))
    })
    @AssociationOverrides
    ({
        @AssociationOverride(name="contact", joinColumns=@JoinColumn(name="CREDENTIALS_CONTACT"))
    })
    public Credential getCredentials()
    {
        return this.credentials;
    }

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

    /**
     * <p>
     * TODO: Model Documentation for customerId
     * </p>
     * Get the customerId property.
     * @return Long The value of customerId
     */
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="CUSTOMER_ID", nullable=false, insertable=true, updatable=true)
    public Long getCustomerId()
    {
        return this.customerId;
    }

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


    // ------------- 0 Relations ------------------
    // --------------- Constructors -----------------

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

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

    /**
     * Constructor with required Entity attributes except auto incremented identifiers.
     *
     * @param username Value for the username property
     * @param password Value for the password property
     * @param name Value for the name property
     */
    public Customer(String username, String password, String name)
    {
        this.username = username;
        this.password = password;
        this.name = name;
    }


    // -------- 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 Customer))
        {
            return false;
        }
        final Customer that = (Customer)object;
        if (this.getCustomerId() == null || that.getCustomerId() == null || !this.getCustomerId().equals(that.getCustomerId()))
        {
            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 + (getCustomerId() == null ? 0 : getCustomerId().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("Customer(");
        sb.append(" username=").append(getUsername());
        sb.append(" password=").append(getPassword());
        sb.append(" name=").append(getName());
        sb.append(" credentials=").append(getCredentials().toString());
        sb.append(" customerId=").append(getCustomerId());
        sb.append(")");
        return sb.toString();
    }

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


}