Java tutorial
/*$Id: UserGroup.java 13026 2009-02-14 01:28:46Z jens $*/ /* **************************************************************************** * * * (c) Copyright 2005 ABM-utvikling * * * * This program 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 2 of the License, or (at your * * option) any later version. * * * * This program 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. http://www.gnu.org/licenses/gpl.html * * * **************************************************************************** */ package no.abmu.user.domain; import java.util.ArrayList; import java.util.List; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.OneToMany; import javax.persistence.PrimaryKeyJoinColumn; import javax.persistence.Table; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.annotations.GenericGenerator; /** * UserGroup. * * @author Erik Romson, erik@zenior.no * @author $Author: jens $ * @version $Rev: 13026 $ * @date $Date: 2009-02-14 02:28:46 +0100 (Sat, 14 Feb 2009) $ * @copyright ABM-Utvikling * * * * @hibernate.joined-subclass * @hibernate.joined-subclass-key * column="id" */ @SuppressWarnings("serial") @Entity @Table(name = "usergroup") @PrimaryKeyJoinColumn(name = "id") @GenericGenerator(name = "increment", strategy = "increment") public class UserGroup extends Principal { private static final Log logger = (Log) LogFactory.getLog(UserGroup.class); private List<Principal> principalChildren; public UserGroup() { } public UserGroup(String name) { super(name); } /** * getId, primary key. * * @return * @ hibernate.id generator-class="increment" */ // @Transient // public Long getId() { // return super.getId(); // } /** * getPrincipalChildren. * * @return * * @hibernate.bag cascade="save-update" lazy="true" inverse="false" * @hibernate.key column="FK_GROUP_ID" * @hibernate.key-column name="FK_GROUP_ID" index="principal_FK_GROUP_ID_idx" * @hibernate.one-to-many class="no.abmu.user.domain.Principal" * @hibernate.collection-key column="FK_GROUP_ID" * @hibernate.collection-key-column name="FK_GROUP_ID" index="principal_FK_GROUP_ID_idx" * @hibernate.collection-one-to-many class="no.abmu.user.domain.Principal" */ @OneToMany(cascade = { CascadeType.ALL }, targetEntity = Principal.class, mappedBy = "parentGroup", fetch = FetchType.EAGER) public List<Principal> getPrincipalChildren() { return principalChildren; } public void addPrincipalChildren(Principal principal) { if (principalChildren == null) { principalChildren = new ArrayList<Principal>(); } if (principal instanceof User) { ((User) principal).setParentGroup(this); } principalChildren.add(principal); } public void setPrincipalChildren(List<Principal> principalChildren) { this.principalChildren = principalChildren; } public boolean equals(Object o) { return super.equals(o); } public boolean equalsAttr(Object o) { if (this == o) { return true; } if (!(o instanceof UserGroup)) { return false; } if (!super.equalsAttr(o)) { return false; } final UserGroup userGroup = (UserGroup) o; if (getPrincipalChildren() != null ? !getPrincipalChildren().equals(userGroup.getPrincipalChildren()) : userGroup.getPrincipalChildren() != null) { return false; } return true; } public int hashCode() { int result = super.hashCode(); result = 29 * result + (getPrincipalChildren() != null ? getPrincipalChildren().hashCode() : 0); return result; } public String toString() { return super.toString() + " ::: UserGroup{" + "principalChildren=" + principalChildren + "}"; } }