1 package org.musicontroller.repair;
2
3 import java.io.File;
4 import java.util.List;
5
6 import org.apache.log4j.Logger;
7 import org.musicontroller.core.Link;
8 import org.musicontroller.core.Song;
9 import org.musicontroller.dao.Dao;
10 import org.varienaja.util.DenseSet;
11
12 public class ConsistencyChecker {
13 private static final Logger log = Logger.getLogger(ConsistencyChecker.class);
14 private static DenseSet _brokenSongIDs = new DenseSet();
15
16
17
18
19
20
21
22 public static synchronized DenseSet checkLinks(Dao dao) {
23 DenseSet errors = new DenseSet();
24 List<Long> songIDs = dao.getSongIds();
25 int count = songIDs.size();
26 for (Long songid : songIDs) {
27 Song song = dao.getSongById(songid);
28 Link link = song.getLink();
29 if (link==null || !(link.getFile()).exists()) {
30 errors.add(songid);
31 log.debug("Incorrect filesystem link for song: "+song.getName());
32 }
33 dao.evict(link);
34 dao.evict(song);
35 if (log.isDebugEnabled()) {
36 count--;
37 if (count % 250 == 0) {
38 log.debug("Songlinks to check: "+count);
39 }
40 }
41 }
42 _brokenSongIDs = errors;
43 return errors;
44 }
45
46
47
48
49
50 public static DenseSet getBrokenSongIDs() {
51 return _brokenSongIDs;
52 }
53 }