17 May 2007

TSA504.beans.TUser - Step 03, user bean.

package org.example.TSA504.beans;

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.Table;


import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;



@Entity
@Table(name = "TUSER") // TUSER is a DB's table name
public class TUser implements Serializable {
private static final long serialVersionUID = 7769115993193444629L;
protected long id; // required
protected String userName; // required
protected String firstName; // required
protected String MI;
protected String lastName; // required
protected String email; // required
protected String password; // required

public TUser() {}

public TUser(String userName) {
this.userName = userName;
}
/**
* @param userName
* @param firstName
* @param mi
* @param lastName
* @param email
* @param password
*/
public TUser(String userName, String firstName, String mi, String lastName, String email, String password) {
super();
this.userName = userName;
this.firstName = firstName;
this.MI = mi;
this.lastName = lastName;
this.email = email;
this.password = password;
}
/**
* @return the id
*/
@Id
@Column (name="id") // the Id column in the TUSER DB table, the pimary key column
@GeneratedValue(strategy = GenerationType.AUTO) //There are several variants can be here, consult the documentation.
public long getId() {
return id;
}
/**
* @return the userName
*/
@Column (name="USERNAME", nullable=false, length = 128 ) //USERNAME column, has to be filled in.
public String getUserName() {
return userName;
}
/**
* @return the firstName
*/
@Column (name="FIRSTNAME", nullable=false, length = 128 )//FIRSTNAME column, has to be filled in.
public String getFirstName() {
return firstName;
}
/**
* @return the mI
*/
@Column (name="MI", nullable=true, length = 16 )//MI column, has not to be filled in.
public String getMI() {
return MI;
}

/**
* @return the lastName
*/
@Column (name="LASTNAME", nullable=false, length = 128 )//LASTNAME column, has to be filled in.
public String getLastName() {
return lastName;
}
/**
* @return the email
*/
@Column (name="EMAIL", nullable=false, length = 256)//EMAIL column, has to be filled in.
public String getEmail() {
return email;
}

/**
* @return the password
*/
@Column (name="PASSWORD", nullable=false, length = 128 )//PASSWORD column, has to be filled in.
public String getPassword() {
return password;
}
//---- set of setProperty() methods:
/**
* @param email the email to set
*/
public void setEmail(String email) {
this.email = email;
}

/**
* @param firstName the firstName to set
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}

/**
* @param id the id to set
*/

public void setId(long id) {
this.id = id;
}

/**
* @param lastName the lastName to set
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}

/**
* @param mi the mI to set
*/
public void setMI(String mi) {
MI = mi;
}

/**
* @param password the password to set
*/

public void setPassword(String password) {
this.password = password;
}

/**
* @param userName the userName to set
*/
public void setUserName(String userName) {
this.userName = userName;
}
//----Implementation of the Serializable interface:
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final TUser other = (TUser) obj;
if (MI == null) {
if (other.MI != null)
return false;
} else if (!MI.equals(other.MI))
return false;
if (email == null) {
if (other.email != null)
return false;
} else if (!email.equals(other.email))
return false;
if (firstName == null) {
if (other.firstName != null)
return false;
} else if (!firstName.equals(other.firstName))
return false;
if (id != other.id)
return false;
if (lastName == null) {
if (other.lastName != null)
return false;
} else if (!lastName.equals(other.lastName))
return false;
if (password == null) {
if (other.password != null)
return false;
} else if (!password.equals(other.password))
return false;
if (userName == null) {
if (other.userName != null)
return false;
} else if (!userName.equals(other.userName))
return false;
return true;
}

/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int PRIME = 31;
int result = super.hashCode();
result = PRIME * result + ((MI == null) ? 0 : MI.hashCode());
result = PRIME * result + ((email == null) ? 0 : email.hashCode());
result = PRIME * result + ((firstName == null) ? 0 : firstName.hashCode());
result = PRIME * result + (int) (id ^ (id >>> 32));
result = PRIME * result + ((lastName == null) ? 0 : lastName.hashCode());
result = PRIME * result + ((password == null) ? 0 : password.hashCode());
result = PRIME * result + ((userName == null) ? 0 : userName.hashCode());
return result;
}
//-- toStrting() implementation, uses some of org.apache.commons.lang.builder classes
public String toString() {
ToStringBuilder sb = new ToStringBuilder(this,
ToStringStyle.DEFAULT_STYLE).append("id", this.id)
.append("username", this.userName)
.append("FN", this.firstName)
.append("MI",this.MI)
.append("LN",this.lastName)
.append("email",this.email);

return sb.toString();
}
}

No comments: