Java tutorial
/* * Copyright 2011 GantzGulch, Inc. * * This file is part of GantzFileSharing. * * GantzFileSharing is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GantzFileSharing is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GantzFileSharing. If not, see <http://www.gnu.org/licenses/>. */ package com.gantzgulch.sharing.domain; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.OneToMany; import javax.persistence.Table; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import com.google.common.collect.Collections2; @Entity @Table(name = "sec_user") public class User extends AbstractDomain { @Column(name = "username") private String username; @Column(name = "password") private String password; @Column(name = "enabled") private boolean isEnabled; @Column(name = "name") private String name; @Column(name = "email") private String email; @OneToMany(mappedBy = "user", cascade = { CascadeType.ALL }) private Set<UserRole> userRoles = new HashSet<UserRole>(); @OneToMany(mappedBy = "user", cascade = { CascadeType.ALL }) private Set<SharedFileLog> userLogs; public User() { } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public boolean getIsEnabled() { return isEnabled; } public void setIsEnabled(boolean isEnabled) { this.isEnabled = isEnabled; } public Collection<String> gerUserRoleNames() { return Collections2.transform(userRoles, new UserRole.UserRoleToStringFunction()); } public List<UserRole> getUserRoles() { return new ArrayList<UserRole>(userRoles); } public void addUserRole(UserRole userRole) { userRole.setUser(this); this.userRoles.add(userRole); } public void clearUserRoles() { this.userRoles.clear(); } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public List<SharedFileLog> getLogs() { return new ArrayList<SharedFileLog>(userLogs); } @Override public String toString() { return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE). // append("id", getId()). // append("username", username). // toString(); } }