View Javadoc

1   package com.atlassian.user.impl.hibernate;
2   
3   import com.atlassian.user.impl.DefaultUser;
4   import com.atlassian.user.Group;
5   
6   import java.util.Iterator;
7   import java.util.Set;
8   import java.util.HashSet;
9   
10  /**
11   * A hibernate implementation of a user.
12   *
13   * This implementation is intended to provide a collection of groups this user
14   * is a member of.  Care should taken when using this collection however as its
15   * lazy loaded you must be sure you are querying it within the same session this
16   * object was loaded.
17   *
18   * If unsure, use the {@link com.atlassian.user.GroupManager#getGroups(com.atlassian.user.User)} method.
19   *
20   * See: http://jira.atlassian.com/browse/USER-191
21   */
22  public class DefaultHibernateUser extends DefaultUser
23  {
24      private transient Set<Group> groups = new HashSet<Group>();
25      // we depend on the fact that id is NOT-transient
26      private long id;
27  
28      public DefaultHibernateUser(){}
29  
30      public DefaultHibernateUser(String name)
31      {
32          super(name);
33      }
34  
35      /**
36       * Provided for Hibernate's use only.
37       *
38       * @see com.atlassian.user.GroupManager#getGroups(com.atlassian.user.User)
39       */
40      public Set<Group> getGroups()
41      {
42          return groups;
43      }
44  
45      public void setGroups(Set<Group> groups)
46      {
47          this.groups = groups;
48      }
49  
50      public long getId()
51      {
52          return id;
53      }
54  
55      public void setId(long id)
56      {
57          this.id = id;
58      }
59  
60      public boolean equals(Object o)
61      {
62          if (this == o) return true;
63          if (!(o instanceof DefaultHibernateUser)) return false;
64          if (!super.equals(o)) return false;
65  
66          final DefaultHibernateUser defaultHibernateUser = (DefaultHibernateUser) o;
67  
68          return id == defaultHibernateUser.id;
69      }
70  
71      public String toString() {
72          StringBuffer ret = new StringBuffer("id:").append(id).
73                  append(" name:").append(name).
74                  append(" fullName:").append(fullName).
75                  append(" email:").append(email).
76                  append(" created:").append(created);
77          return ret.toString();
78      }
79  
80      public int hashCode()
81      {
82          int result = super.hashCode();
83          result = 29 * result + (int) (id ^ (id >>> 32));
84          return result;
85      }
86  }