View Javadoc

1   package com.melloware.jukes.db.orm;
2   
3   import java.util.Date;
4   import java.util.HashSet;
5   import java.util.Set;
6   
7   import org.apache.commons.lang.builder.CompareToBuilder;
8   import org.apache.commons.lang.builder.EqualsBuilder;
9   import org.apache.commons.lang.builder.HashCodeBuilder;
10  import org.apache.commons.lang.builder.ToStringBuilder;
11  import org.apache.commons.lang.builder.ToStringStyle;
12  
13  import com.melloware.jukes.db.audit.Auditable;
14  
15  /**
16   * Business POJO representing an ARTIST.
17   * <p>
18   * Implements Auditable so that the user and date information is updated when
19   * this object is updated using a Hibernate Interceptor.
20   * <p>
21   * Copyright (c) 1999-2007 Melloware, Inc. <http://www.melloware.com>
22   * @author Emil A. Lefkof III <info@melloware.com>
23   * @version 4.0
24   */
25  public final class Artist
26      extends AbstractJukesObject
27      implements Auditable, Comparable {
28  
29      public static final String PROPERTYNAME_CREATED_DATE = "createdDate";
30      public static final String PROPERTYNAME_MODIFIED_DATE = "modifiedDate";
31      public static final String PROPERTYNAME_ID = "id";
32      public static final String PROPERTYNAME_CREATED_USER = "createdUser";
33      public static final String PROPERTYNAME_MODIFIED_USER = "modifiedUser";
34      public static final String PROPERTYNAME_NAME = "name";
35      public static final String PROPERTYNAME_NOTES = "notes";
36  
37      private Date createdDate;
38      private Date modifiedDate;
39      private Long id;
40      private Set discs;
41      private String createdUser;
42      private String modifiedUser;
43      private String name;
44      private String notes;
45  
46      /** default constructor */
47      public Artist() {
48          super();
49      }
50  
51      /** constructor with id */
52      public Artist(Long id) {
53          this.id = id;
54      }
55  
56      /**
57       * This date determines how the NEW flag is checked in the isNew() function.
58       * <p>
59       * @return the modified date is used to check in the isNew() function
60       */
61      public Date getAuditDate() {
62          return this.modifiedDate;
63      }
64  
65      /**
66       * This is used to fool the tree for lazy loading of tree nodes.
67       * <p>
68       * @return the number of children this object has
69       */
70      public int getChildCount() {
71          childCount = this.discs.size();
72          return childCount;
73      }
74  
75      public Date getCreatedDate() {
76          return this.createdDate;
77      }
78  
79      public String getCreatedUser() {
80          return this.createdUser;
81      }
82  
83      public Set getDiscs() {
84          return this.discs;
85      }
86  
87      public Long getId() {
88          return this.id;
89      }
90  
91      public Date getModifiedDate() {
92          return this.modifiedDate;
93      }
94  
95      public String getModifiedUser() {
96          return this.modifiedUser;
97      }
98  
99      public String getName() {
100         return this.name;
101     }
102 
103     /**
104      * Gets the notes.
105      * <p>
106      * @return Returns the notes.
107      */
108     public String getNotes() {
109         return this.notes;
110     }
111 
112     public void setCreatedDate(final Date createdDate) {
113         final Date old = getCreatedDate();
114         this.createdDate = createdDate;
115         firePropertyChange(PROPERTYNAME_CREATED_DATE, old, createdDate);
116     }
117 
118     public void setCreatedUser(final String createdUser) {
119         final String old = getCreatedUser();
120         this.createdUser = createdUser;
121         firePropertyChange(PROPERTYNAME_CREATED_USER, old, createdUser);
122     }
123 
124     public void setDiscs(final Set discs) {
125         this.discs = discs;
126     }
127 
128     public void setId(final Long id) {
129         final Long old = getId();
130         this.id = id;
131         firePropertyChange(PROPERTYNAME_ID, old, id);
132     }
133 
134     public void setModifiedDate(final Date modifiedDate) {
135         final Date old = getModifiedDate();
136         this.modifiedDate = modifiedDate;
137         firePropertyChange(PROPERTYNAME_MODIFIED_DATE, old, modifiedDate);
138     }
139 
140     public void setModifiedUser(final String modifiedUser) {
141         final String old = getModifiedUser();
142         this.modifiedUser = modifiedUser;
143         firePropertyChange(PROPERTYNAME_MODIFIED_USER, old, modifiedUser);
144     }
145 
146     public void setName(final String name) {
147         final String old = getName();
148         this.name = name;
149         firePropertyChange(PROPERTYNAME_NAME, old, name);
150     }
151 
152     /**
153      * Sets the notes.
154      * <p>
155      * @param aNotes The notes to set.
156      */
157     public void setNotes(final String aNotes) {
158         final String old = getNotes();
159         this.notes = aNotes;
160         firePropertyChange(PROPERTYNAME_NOTES, old, aNotes);
161     }
162 
163     /* (non-Javadoc)
164      * @see com.melloware.jukes.db.orm.AbstractJukesObject#isValid()
165      */
166     public boolean isValid() {
167         return true;
168     }
169 
170     @SuppressWarnings("unchecked")
171     public void addDisc(final Disc disc) {
172         if (this.discs == null) {
173             this.discs = new HashSet();
174         }
175         this.discs.add(disc);
176         disc.setArtist(this);
177     }
178 
179     /* (non-Javadoc)
180      * @see java.lang.Object#equals(java.lang.Object)
181      */
182     public boolean equals(Object obj) {
183         if (!(obj instanceof Artist)) {
184             return false;
185         }
186         if (this == obj) {
187             return true;
188         }
189         final Artist rhs = (Artist)obj;
190         final EqualsBuilder builder = new EqualsBuilder();
191         builder.append(name, rhs.name);
192         return builder.isEquals();
193     }
194 
195     /* (non-Javadoc)
196      * @see java.lang.Object#hashCode()
197      */
198     public int hashCode() {
199         return new HashCodeBuilder(17, 37).append(name).toHashCode();
200     }
201 
202     /* (non-Javadoc)
203      * @see java.lang.Object#toString()
204      */
205     public String toString() {
206         final ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);
207         builder.append("id", id);
208         builder.append("name", name);
209         return builder.toString();
210     }
211 
212     /* (non-Javadoc)
213 	 * @see java.lang.Comparable#compareTo(java.lang.Object)
214 	 */
215 	public int compareTo(Object object) {
216 		final Artist artist = (Artist)object;
217         final CompareToBuilder builder = new CompareToBuilder();
218         builder.append(this.getName().toUpperCase(), artist.getName().toUpperCase());
219         return builder.toComparison();
220 	}
221 
222 }