Person.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.rental;
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
* <p>
* TODO: Model Documentation for org.andromda.demo.ejb3.rental.Person
* </p>
*
* Autogenerated POJO EJB class for Person containing the
* bulk of the entity implementation.
*
* This is autogenerated by AndroMDA using the EJB3
* cartridge.
*
* DO NOT MODIFY this class.
*/
@Entity
@Table(name="PERSON")
@NamedQueries
({
@NamedQuery(name="Person.findAll", query="SELECT p FROM Person AS p"),
@NamedQuery(name="Person.findByName", query="SELECT p from Person as p WHERE p.name = :name")
})
public class Person
implements Serializable, Comparable<Person>{
private static final long serialVersionUID = 2947355414596128205L;
protected PersonPK pk;
// ----------- 4 Attribute Definitions ------------
protected String name;
protected Date birthDate;
// --------- 1 Relationship Definitions -----------
protected Set<RentalCar> rentalCars = new HashSet<RentalCar>();
// ---- Manageable Display Attributes (Transient) -----
// ----- Composite PK Accessors ------
/**
* Return the composite primary key for Person
* @return The composite primary key
*/
@EmbeddedId
@JoinColumns({
@JoinColumn(name="ID", nullable=false),
@JoinColumn(name="TAG", nullable=false)
})
public PersonPK getPk()
{
return this.pk;
}
/**
* Set the composite primary key for Person
* @param pkIn The composite primary key
*/
public void setPk(PersonPK pkIn)
{
this.pk = pkIn;
}
// -------- 4 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=50)
@NotNull(message="name is required")
@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;
}
/**
* <p>
* TODO: Model Documentation for birthDate
* </p>
* Get the birthDate property.
* @return Date The value of birthDate
*/
@Column(name="BIRTH_DATE", nullable=false, insertable=true, updatable=true)
@Temporal(TemporalType.TIMESTAMP)
@NotNull(message="birthDate is required")
public Date getBirthDate()
{
return this.birthDate;
}
/**
* <p>
* TODO: Model Documentation for birthDate
* </p>
* Set the birthDate property.
* @param value the new value
*/
public void setBirthDate(Date value)
{
this.birthDate = value;
}
// ------------- 1 Relations ------------------
/**
* <p>
* TODO: Model Documentation for rentalCars
* </p>
* Get the rentalCars Collection
* @return Set<RentalCar>
*/
@OneToMany(mappedBy="owner")
public Set<RentalCar> getRentalCars()
{
return this.rentalCars;
}
/**
* <p>
* TODO: Model Documentation for rentalCars
* </p>
* Set the rentalCars
* @param rentalCarsIn
*/
public void setRentalCars (Set<RentalCar> rentalCarsIn)
{
this.rentalCars = rentalCarsIn;
}
// --------------- Constructors -----------------
/**
* Default empty no-arg constructor
*/
public Person()
{
// Default empty constructor
}
/**
* Constructor with all updatable Entity attributes except auto incremented identifiers.
*
* @param pk PersonPK The composite primary key class
* @param name String value for the name property required=true lower=1
* @param birthDate Date value for the birthDate property required=true lower=1
*/
public Person(PersonPK pk, String name, Date birthDate)
{
setPk(pk);
this.name = name;
this.birthDate = birthDate;
}
/**
* Constructor with all Entity attribute values and CMR relations.
*
* @param pk PersonPK The composite primary key class
* @param name String value for the name property
* @param birthDate Date value for the birthDate property
* @param rentalCars Set<RentalCar> value for the rentalCars relation
*/
public Person(PersonPK pk, String name, Date birthDate, Set<RentalCar> rentalCars)
{
setPk(pk);
// 2 updatableAttributes
setName(name);
setBirthDate(birthDate);
// 1 relations
setRentalCars(rentalCars);
}
/**
* Constructor with composite primary key arg only.
*
* @param pkIn PersonPK Composite primary key
*/
public Person(PersonPK pkIn)
{
this.pk = pkIn;
}
// -------- 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 Person))
{
return false;
}
final Person that = (Person)object;
if (this.getPk().getId() == null || that.getPk().getId() == null || !this.getPk().getId().equals(that.getPk().getId()))
{
return false;
}
if (this.getPk().getTag() == null || that.getPk().getTag() == null || !this.getPk().getTag().equals(that.getPk().getTag()))
{
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 + (getPk().getId() == null ? 0 : getPk().getId().hashCode());
hashCode = 29 * hashCode + (getPk().getTag() == null ? 0 : getPk().getTag().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("Person(");
sb.append(this.pk);
sb.append(" name=").append(getName());
sb.append(" birthDate=").append(getBirthDate());
sb.append(")");
return sb.toString();
}
/**
* @see Comparable#compareTo
*/
@Override
public int compareTo(Person o)
{
int cmp = 0;
if (this.getPk() != null)
{
cmp = this.getPk().compareTo(o.getPk());
}
else
{
if (this.getName() != null)
{
cmp = (cmp != 0 ? cmp : this.getName().compareTo(o.getName()));
}
if (this.getBirthDate() != null)
{
cmp = (cmp != 0 ? cmp : this.getBirthDate().compareTo(o.getBirthDate()));
}
}
return cmp;
}
}