1: package cz.cvut.x33eja.macosond.business.music;
2:
3: import cz.cvut.x33eja.macosond.persistence.entity.Album;
4: import cz.cvut.x33eja.macosond.persistence.entity.Song;
5: import java.util.Collection;
6: import javax.annotation.security.PermitAll;
7: import javax.annotation.security.RolesAllowed;
8: import javax.ejb.Stateless;
9: import javax.persistence.EntityManager;
10: import javax.persistence.PersistenceContext;
11:
12: 13: 14: 15:
16: @Stateless
17: public class SongBean implements SongLocal
18: {
19: @PersistenceContext(unitName="Musico-PU")
20: private EntityManager em;
21:
22: @RolesAllowed({"member","admin"})
23: public void add(Song song)
24: {
25: em.persist(song);
26: }
27:
28: @RolesAllowed({"member","admin"})
29: public void edit(Song song)
30: {
31: song = em.merge(song);
32: em.persist(song);
33: }
34:
35: @RolesAllowed({"member","admin"})
36: public void delete(Song song)
37: {
38: song = em.merge(song);
39: em.remove(song);
40: }
41:
42: @PermitAll
43: public Song get(Song song)
44: {
45: return em.find(Song.class, song.getSongID());
46: }
47:
48: @PermitAll
49: public Song get(Integer SongID)
50: {
51: return em.find(Song.class, SongID);
52: }
53:
54: @PermitAll
55: public Collection<Song> getAll()
56: {
57: return em.createNamedQuery("Song.list").getResultList();
58: }
59:
60: @PermitAll
61: public Collection<Song> getByAlbum(Album album)
62: {
63: album = em.find(Album.class, album.getAlbumID());
64: return album.getSongs();
65: }
66: }
67: