1 package com.melloware.jukes.db.orm;
2
3 import java.text.MessageFormat;
4 import java.util.Date;
5 import java.util.List;
6 import java.util.Arrays;
7
8 import org.apache.commons.lang.StringUtils;
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11
12 import com.jgoodies.uif.util.ResourceUtils;
13 import com.melloware.jukes.db.HibernateDao;
14 import com.melloware.jukes.db.HibernateUtil;
15 import com.melloware.jukes.gui.tool.Settings;
16
17
18
19
20
21
22
23
24
25
26 public final class Catalog
27 extends AbstractJukesObject {
28
29 private static final Log LOG = LogFactory.getLog(Catalog.class);
30
31
32
33
34 private final List artists;
35
36
37 public static Settings settings = null;
38
39
40
41 public static void setSettings(Settings aSettings) {
42 settings = aSettings;
43 }
44
45
46
47
48
49
50 public Catalog(String aFilter) {
51 super();
52 LOG.debug("Catalog created.");
53
54 HibernateUtil.getSession().clear();
55
56 if (StringUtils.isNotBlank(aFilter)) {
57 final String resource;
58
59 if ((this.settings.isShowEmptyNode()) & (aFilter.indexOf("disc.")==-1)) {
60 resource = ResourceUtils.getString("hql.filter.artist.including.empty");
61 if (aFilter.startsWith("and")) {
62 aFilter = aFilter.substring(4);
63 }
64 } else {
65 resource = ResourceUtils.getString("hql.filter.artist");
66 }
67 final String hql = MessageFormat.format(resource, new Object[] { aFilter });
68 this.artists = HibernateDao.findByQuery(hql);
69 } else {
70 LOG.debug("Start findAllArtists");
71 if (this.settings.isShowDefaultTree()) {
72 if (this.settings.isShowEmptyNode()) {
73 this.artists = findAllArtistsIncludingEmpty();}
74 else {
75 this.artists = findAllArtists();
76 }
77 }
78 else {
79 this.artists = HibernateDao.findByQuery(ResourceUtils.getString("hql.artist.all"),1);
80 this.artists.clear();
81 }
82 LOG.debug("End findAllArtists");
83 }
84 LOG.debug("Artist Count = " + this.artists.size());
85 }
86
87
88
89
90
91
92
93 public static List findAllArtists() {
94 LOG.debug("Loading ALL artists");
95
96 final String hql = ResourceUtils.getString("hql.artist.all");
97 return HibernateDao.findByQuery(hql);
98 }
99
100
101
102
103
104
105
106 public static List findAllArtistsIncludingEmpty() {
107 LOG.debug("Loading ALL artists (including empty ones)");
108
109 final String hql = ResourceUtils.getString("hql.artist.all.including.empty");
110 return HibernateDao.findByQuery(hql);
111 }
112
113
114
115
116
117
118 public List getArtists() {
119 return this.artists;
120 }
121
122
123
124
125 public Date getAuditDate() {
126 return new Date();
127 }
128
129
130
131
132 public int getChildCount() {
133 if (artists == null) {
134 return 0;
135
136 } else {
137 return artists.size();
138 }
139 }
140
141
142
143
144 public Date getCreatedDate() {
145 return new Date();
146 }
147
148
149
150
151 public Long getId() {
152 return Long.valueOf(-99);
153 }
154
155
156
157
158 public Date getModifiedDate() {
159 return new Date();
160 }
161
162 public String getName() {
163 return "Catalog";
164 }
165
166
167
168
169 public boolean isValid() {
170 return true;
171 }
172
173 }