Created
January 21, 2015 02:48
-
-
Save chRyNaN/9636ffde6b721f1861b8 to your computer and use it in GitHub Desktop.
Simple Entity Structure Implementation for User
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Date; | |
import java.util.Map; | |
import java.util.Set; | |
import java.util.UUID; | |
import javax.persistence.Entity; | |
import javax.persistence.GeneratedValue; | |
import javax.persistence.Id; | |
import javax.persistence.NamedQuery; | |
import javax.persistence.Table; | |
@Entity | |
@Table(name = "APP_USER") | |
@NamedQuery(name = "FIND_WITH_USER_ID", query="SELECT DISTINCT u FROM User u WHERE u.userId = :userId") | |
public class User { | |
@Id @GeneratedValue | |
private long databaseId; | |
private String userId; | |
private UserInfo info; | |
private UserSocial social; | |
public User(){ | |
userId = UUID.randomUUID().toString(); | |
info = new UserInfo(); | |
social = new UserSocial(); | |
} | |
public User(String firstName, String lastName, String email, String userName){ | |
userId = UUID.randomUUID().toString(); | |
info = new UserInfo(firstName, lastName, email, userName); | |
social = new UserSocial(); | |
} | |
public User(String firstName, String lastName, String email, String userName, Date birthday){ | |
userId = UUID.randomUUID().toString(); | |
info = new UserInfo(firstName, lastName, email, userName, birthday); | |
social = new UserSocial(); | |
} | |
/** Getters and Setters */ | |
public String getUserId(){ | |
return userId; | |
} | |
public void setUserId(String userId){ | |
this.userId = userId; | |
} | |
public String getFirstName() { | |
return info.getFirstName(); | |
} | |
public void setFirstName(String firstName) { | |
this.info.setFirstName(firstName); | |
} | |
public String getLastName() { | |
return info.getLastName(); | |
} | |
public void setLastName(String lastName) { | |
this.info.setLastName(lastName);; | |
} | |
public String getEmail() { | |
return info.getEmail(); | |
} | |
public void setEmail(String email) { | |
this.info.setEmail(email);; | |
} | |
public String getUserName() { | |
return info.getUserName(); | |
} | |
public void setUserName(String userName) { | |
this.info.setUserName(userName);; | |
} | |
public Date getBirthday(){ | |
return info.getBirthday(); | |
} | |
public void setBirthday(Date birthday){ | |
this.info.setBirthday(birthday); | |
} | |
public Date getSignUpDate(){ | |
return info.getSignUpDate(); | |
} | |
public void addFriend(User friend){ | |
this.social.addFriend(friend); | |
} | |
public boolean deleteFriend(User friend){ | |
return this.social.deleteFriend(friend); | |
} | |
public Set<User> getFriends(){ | |
return social.getFriends(); | |
} | |
public void setFriends(Set<User> friends){ | |
this.social.setFriends(friends); | |
} | |
public void addSentRequest(User rec){ | |
this.social.addSentRequest(rec); | |
} | |
public boolean removeSentRequest(User rec){ | |
return this.social.removeSentRequest(rec); | |
} | |
public Set<User> getSentRequests(){ | |
return social.getSentRequests(); | |
} | |
public void setSentRequests(Set<User> requests){ | |
this.social.setSentRequests(requests); | |
} | |
public void addFriendRequest(User request){ | |
this.social.addFriendRequest(request); | |
} | |
public boolean removeFriendRequest(User request){ | |
return this.social.removeFriendRequest(request); | |
} | |
public Map<User, Boolean> getFriendRequests(){ | |
return this.social.getFriendRequests(); | |
} | |
public void setFriendRequests(Map<User, Boolean> requests){ | |
this.social.setFriendRequests(requests); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Calendar; | |
import java.util.Date; | |
import javax.persistence.Entity; | |
import javax.persistence.GeneratedValue; | |
import javax.persistence.Id; | |
import javax.persistence.Temporal; | |
import javax.persistence.TemporalType; | |
@Entity | |
public class UserInfo { | |
@Id @GeneratedValue | |
private long databaseId; | |
private String firstName; | |
private String lastName; | |
private String email; | |
private String userName; | |
private String phoneNumber; | |
private String gender; | |
@Temporal(TemporalType.TIMESTAMP) | |
private Date signUpDate; | |
@Temporal(TemporalType.DATE) | |
private Date birthday; | |
public UserInfo(){ | |
signUpDate = (Calendar.getInstance()).getTime(); | |
} | |
public UserInfo(String firstName, String lastName, String email, String userName){ | |
this.firstName = firstName; | |
this.lastName = lastName; | |
this.email = email; | |
this.userName = userName; | |
signUpDate = (Calendar.getInstance()).getTime(); | |
} | |
public UserInfo(String firstName, String lastName, String email, String userName, Date birthday){ | |
this.firstName = firstName; | |
this.lastName = lastName; | |
this.email = email; | |
this.userName = userName; | |
this.birthday = birthday; | |
signUpDate = (Calendar.getInstance()).getTime(); | |
} | |
/** Getters and Setters */ | |
public String getFirstName() { | |
return firstName; | |
} | |
public void setFirstName(String firstName) { | |
this.firstName = firstName; | |
} | |
public String getLastName() { | |
return lastName; | |
} | |
public void setLastName(String lastName) { | |
this.lastName = lastName; | |
} | |
public String getEmail() { | |
return email; | |
} | |
public void setEmail(String email) { | |
this.email = email; | |
} | |
public String getUserName() { | |
return userName; | |
} | |
public void setUserName(String userName) { | |
this.userName = userName; | |
} | |
public Date getBirthday(){ | |
return birthday; | |
} | |
public void setBirthday(Date birthday){ | |
this.birthday = birthday; | |
} | |
public Date getSignUpDate(){ | |
return signUpDate; | |
} | |
public String getGender() { | |
return gender; | |
} | |
public void setGender(String gender) { | |
this.gender = gender; | |
} | |
public String getPhoneNumber() { | |
return phoneNumber; | |
} | |
public void setPhoneNumber(String phoneNumber) { | |
this.phoneNumber = phoneNumber; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment