1 package com.melloware.jukes.db.orm;
2
3 import java.text.MessageFormat;
4 import java.util.Date;
5 import java.util.List;
6
7 import org.apache.commons.lang.StringUtils;
8 import org.apache.commons.logging.Log;
9 import org.apache.commons.logging.LogFactory;
10
11 import com.jgoodies.uif.util.ResourceUtils;
12 import com.melloware.jukes.db.HibernateDao;
13 import com.melloware.jukes.db.HibernateUtil;
14
15 /**
16 * References all relevant project data: the project description and a
17 * list of artists. The artists refer to their child components.
18 * <p>
19 * Copyright (c) 1999-2007 Melloware, Inc. <http://www.melloware.com>
20 * @author Emil A. Lefkof III <info@melloware.com>
21 * @version 4.0
22 */
23 public final class Catalog
24 extends AbstractJukesObject {
25
26 private static final Log LOG = LogFactory.getLog(Catalog.class);
27
28 /**
29 * Holds a list of artists
30 */
31 private final List artists;
32
33 /**
34 * Constructs a <code>Catalog</code> with the given name and
35 * and loads all the artists.
36 *
37 * @param aFilter the filter if there is one to apply
38 */
39 public Catalog(String aFilter) {
40 super();
41 LOG.debug("Catalog created.");
42
43 HibernateUtil.getSession().clear();
44 // if a filter was applied the use the filter HQL
45 if (StringUtils.isNotBlank(aFilter)) {
46 final String resource = ResourceUtils.getString("hql.filter.artist");
47 final String hql = MessageFormat.format(resource, new Object[] { aFilter });
48 this.artists = HibernateDao.findByQuery(hql);
49 } else {
50 this.artists = findAllArtists();
51 }
52 LOG.debug("Artist Count = " + this.artists.size());
53 }
54
55 /**
56 * Loads all artists in the catalog and will return quickly if they are
57 * already cached.
58 * <p>
59 * @return the complete list of artists
60 */
61 public static List findAllArtists() {
62 LOG.debug("Loading ALL artists");
63 // now just get the cached artists
64 final String hql = ResourceUtils.getString("hql.artist.all");
65 return HibernateDao.findByQuery(hql);
66 }
67
68 /**
69 * Gets the artists.
70 * <p>
71 * @return Returns the artists.
72 */
73 public List getArtists() {
74 return this.artists;
75 }
76
77 /**
78 * This date determines how the NEW flag is checked in the isNew() function.
79 */
80 public Date getAuditDate() {
81 return new Date();
82 }
83
84 /* (non-Javadoc)
85 * @see com.melloware.jukes.gui.domain.Model#getCount()
86 */
87 public int getChildCount() {
88 if (artists == null) {
89 return 0;
90
91 } else {
92 return artists.size();
93 }
94 }
95
96 /* (non-Javadoc)
97 * @see com.melloware.jukes.db.orm.AbstractJukesObject#getCreatedDate()
98 */
99 public Date getCreatedDate() {
100 return new Date();
101 }
102
103 /* (non-Javadoc)
104 * @see com.melloware.jukes.db.orm.AbstractJukesObject#getId()
105 */
106 public Long getId() {
107 return Long.valueOf(-99);
108 }
109
110 /* (non-Javadoc)
111 * @see com.melloware.jukes.db.orm.AbstractJukesObject#getModifiedDate()
112 */
113 public Date getModifiedDate() {
114 return new Date();
115 }
116
117 public String getName() {
118 return "Catalog";
119 }
120
121 /* (non-Javadoc)
122 * @see com.melloware.jukes.db.orm.AbstractJukesObject#isValid()
123 */
124 public boolean isValid() {
125 return true;
126 }
127
128 }