Book.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.book;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
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.book.Book
 * </p>
 *
 * Autogenerated POJO EJB class for Book containing the
 * bulk of the entity implementation.
 *
 * This is autogenerated by AndroMDA using the EJB3
 * cartridge.
 *
 * DO NOT MODIFY this class.
 */
@Entity
@Table(name="BOOK")
@NamedQuery(name="Book.findAll", query="SELECT b FROM Book AS b")
public class Book
    implements Serializable, Comparable<Book>{
    private static final long serialVersionUID = 8537009934439409645L;

    // ----------- 3 Attribute Definitions ------------
    protected String name;
    protected long pages;
    protected Long bookId;

    // -------- 3 Attribute Accessors ----------
    /**
     * <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=100)
    @NotNull(message="name is required")
    @Size(max=100)
    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 pages
     * </p>
     * Get the pages property.
     * @return long The value of pages
     */
    @Column(name="PAGES", nullable=false, insertable=true, updatable=true)
    @NotNull(message="pages is required")
    public long getPages()
    {
        return this.pages;
    }

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

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

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


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

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

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



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

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


}