⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 musicmanage.ejb

📁 jsp版 音乐站点 j2ee+weblogic
💻 EJB
字号:
package music.ejb;import java.util.*;import javax.ejb.*;import weblogic.ejb.*;import music.ejb.db.*;import music.shared.*;/** * @ejbgen:session default-transaction="Required" type="Stateless" *   ejb-name="MusicManage" * * @ejbgen:jndi-name *   remote="ejb/MusicManage" * * @ejbgen:file-generation remote-class = "true" remote-class-name="MusicManageRemote" remote-home = "true" remote-home-name="MusicManageRemoteHome" local-class="true" local-class-name="MusicManageLocal" local-home="true" local-home-name="MusicManageLocalHome" */public class MusicManage extends GenericSessionBean implements SessionBean{  public void ejbCreate() {    // Your code here  }    /**     * create a new category, if parentId==0,     * then it is under the root category.     * if no such parent category,     * a CategoryNotFoundException will be thrown.     * @ejbgen:remote-method     */    public int newCategory(int parentId, String name)        throws IllegalArgumentException, ApplicationException    {        if(parentId!=0) {            // if not under root category,            // first we must check if the parent category is exist:            try {                CategoryLocal parent = JndiHelper.getCategoryLocalHome().findByPrimaryKey(new Integer(parentId));            }            catch(FinderException fe) {                throw new IllegalArgumentException("No such parent category with id " + parentId);            }        }        CategoryLocal category = null;        try {            JndiHelper.getCategoryLocalHome().create(parentId, name);        }        catch(CreateException ce) {            throw new ApplicationException(ce);        }        return category.getId().intValue();    }    /**     * @ejbgen:remote-method     */    public int newArtist(int categoryId, ArtistVO artistVO)        throws IllegalArgumentException, ApplicationException    {        CategoryLocal category = null;        try {            category = JndiHelper.getCategoryLocalHome().findByPrimaryKey(new Integer(categoryId));        }        catch(FinderException fe) {            throw new IllegalArgumentException("No such category with id " + categoryId);        }        // Now we got the Category!        ArtistLocal artist = null;        try {            artist = JndiHelper.getArtistLocalHome().create(artistVO.getName(),  artistVO.getGender(), artistVO.getDescription());        }        catch(CreateException ce) {            throw new ApplicationException(ce);        }        artist.setCategory(category); // OK, set the cmr!        return artist.getId().intValue();    }    /**     * @ejbgen:remote-method     */    public int newAlbum(int artistId, AlbumVO albumVO)        throws IllegalArgumentException, ApplicationException    {        ArtistLocal artist = null;        try {            artist = JndiHelper.getArtistLocalHome().findByPrimaryKey(new Integer(artistId));        }        catch(FinderException fe) {            throw new IllegalArgumentException("No such artist with id " + artistId);        }        AlbumLocal album = null;        try {            JndiHelper.getAlbumLocalHome().create(                albumVO.getTitle(), albumVO.getGenre(), albumVO.getRelease()            );        }        catch(CreateException ce) {            throw new ApplicationException(ce);        }        album.setArtist(artist); // Set the CMR!        return album.getId().intValue();    }    /**     * @ejbgen:remote-method     */    public int newSong(int albumId, SongVO songVO)        throws IllegalArgumentException, ApplicationException    {        AlbumLocal album = null;        try {            album = JndiHelper.getAlbumLocalHome().findByPrimaryKey(new Integer(albumId));        }        catch(FinderException fe) {            throw new IllegalArgumentException("No such album with id " + albumId);        }        // Now we got the album:        SongLocal song = null;        try {            JndiHelper.getSongLocalHome().create(                songVO.getTitle(), songVO.getType(),                songVO.getUrl(), songVO.getLyric()            );        }        catch(CreateException ce) {            throw new ApplicationException(ce);        }        song.setAlbum(album); // Set the CMR!        return song.getId().intValue();    }    /**     * @ejbgen:remote-method     */    public void setLyric(int songId, String lyric)        throws IllegalArgumentException    {        SongLocal song = null;        try {            song = JndiHelper.getSongLocalHome().findByPrimaryKey(new Integer(songId));        }        catch(FinderException fe) {            throw new IllegalArgumentException("No such song with id " + songId);        }        // Now we set the lyric:        song.setLyric(lyric);    }    /**     * @ejbgen:remote-method     */    public void  deleteAlbum(int albumId)        throws IllegalArgumentException, ApplicationException    {        AlbumLocal album = null;        try {            album = JndiHelper.getAlbumLocalHome().findByPrimaryKey(new Integer(albumId));            if(album.getSongs().size()>0)                throw new ApplicationException("Cannot delete unless it is EMPTY.");            album.remove();        }        catch(FinderException fe) {            throw new IllegalArgumentException("No such album with id " + albumId);        }        catch(RemoveException re) {            throw new ApplicationException(re);        }    }    /**     * @ejbgen:remote-method     */    public void  deleteSong(int songId)        throws ApplicationException, IllegalArgumentException    {        SongLocal song = null;        try {            song = JndiHelper.getSongLocalHome().findByPrimaryKey(new Integer(songId));            song.remove();        }        catch(FinderException fe) {            throw new IllegalArgumentException("No such song with id " + songId);        }        catch(RemoveException re) {            throw new ApplicationException(re);        }    }    /**     * @ejbgen:remote-method     */    public void  deleteArtist(int artistId)        throws IllegalArgumentException, ApplicationException    {        ArtistLocal artist = null;        try {            artist = JndiHelper.getArtistLocalHome().findByPrimaryKey(new Integer(artistId));            if(artist.getAlbums().size()>0)                throw new ApplicationException("Cannot delete unless it is EMPTY.");            artist.remove();        }        catch(FinderException fe) {            throw new IllegalArgumentException("No such artist with id " + artistId);        }        catch(RemoveException re) {            throw new ApplicationException(re);        }    }    /**     * @ejbgen:remote-method     */    public void  deleteCategory(int categoryId)        throws ApplicationException, IllegalArgumentException    {        CategoryLocal category = null;        try {            category = JndiHelper.getCategoryLocalHome().findByPrimaryKey(new Integer(categoryId));        }        catch(FinderException fe) {            throw new IllegalArgumentException("No such category with id " + categoryId);        }        // 获得Artists:        if(category.getArtists().size()>0)            throw new ApplicationException("Cannot delete unless it is EMPTY.");        // 获得所有下级Category:        try {            Collection c = JndiHelper.getCategoryLocalHome().findByParentId(categoryId);            if(c.size()>0)                throw new ApplicationException("Cannot delete unless it is EMPTY.");        }        catch(FinderException fe) {            throw new ApplicationException(fe);        }        try {            category.remove();        }        catch(RemoveException re) {            throw new ApplicationException(re);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -