1 package song; 2 3 5 import org.ozoneDB.*; 6 7 17 18 public class SongServices { 19 20 private static SongCollection allSongs = null; 22 23 private static OzoneInterface db = null; 25 26 27 28 32 public static void init(OzoneInterface database) { 33 34 db = database; 35 36 try { 37 38 try { 40 41 allSongs = (SongCollection)db.objectForName("_AllSongs"); 42 43 if (allSongs == null) { 45 System.out.println("init(): _AllSongs collection null. Creating..."); 46 allSongs = (SongCollection)db.createObject( SongCollectionImpl.class.getName(), 47 OzoneInterface.Public, "_AllSongs"); 48 } else { 49 System.out.println("init() allSongs found."); 50 } 51 52 } catch (org.ozoneDB.PermissionDeniedException e) { 54 System.out.println("init(): _AllSongs collection not found. Creating..."); 55 56 allSongs = (SongCollection)db.createObject( SongCollectionImpl.class.getName(), 57 OzoneInterface.Public, "_AllSongs"); 58 59 } 60 } catch (Exception e) { 61 System.out.println("init(): Problem getting or creating allSong collection."); 62 e.printStackTrace(); 63 64 } 65 } 66 67 71 public static void term() { 72 allSongs = null; 74 db = null; 75 } 76 77 81 public static SongCollection getAllSongs() { 82 return allSongs; 83 } 84 85 96 public static Song createSong(String title) throws Exception { 97 98 Song song = null; 99 try { 100 101 song = (Song)db.createObject( SongImpl.class.getName(), 102 OzoneInterface.Public); 103 104 song.setTitle(title); 105 allSongs.addSong(title.toUpperCase(), song); 106 107 } catch (Exception e){ 108 System.out.println("createSong(): something went wrong adding to Ozone."); 109 throw e; 110 } 111 112 return song; 113 } 114 115 126 public static boolean deleteSong(String title) { 127 System.out.println("deleteSong <" + title + ">" ); 128 129 Song song = allSongs.deleteSong(title.toUpperCase()); 130 131 return (song != null); 132 } 133 134 135 136 143 public static Song songForTitle(String title){ 144 145 Song song = null; 146 try { 147 song = allSongs.findSong(title.toUpperCase()); 148 149 if (song == null) { 150 System.out.println("song.Song not found by title <" + title + ">" ); 151 } 152 } catch (Exception e){ 153 System.out.println("songForHandle(): something went wrong finding song."); 154 e.printStackTrace(); 155 } 156 157 return song; 158 } 159 160 167 public static Song songForHandle(String handle) { 168 169 Song song = null; 170 try { 171 172 song = (Song)db.objectForHandle(handle); 173 174 if (song == null) { 175 System.out.println("song.Song not found by handle <" + handle + ">" ); 176 } 177 } catch (Exception e){ 178 System.out.println("songForHandle(): something went wrong finding song."); 179 e.printStackTrace(); 180 } 181 182 return song; 183 } 184 185 186 } 187 188 189 | Popular Tags |