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

📄 musicview.ejb

📁 J2EE的一个开发实例
💻 EJB
字号:
package music.ejb;import java.io.*;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 = "MusicView" * * @ejbgen:jndi-name remote="ejb/MusicView" * * @ejbgen:file-generation remote-class="true" remote-class-name = "MusicViewRemote" remote-home="true" remote-home-name="MusicViewRemoteHome" local-class="true" local-class-name = "MusicViewLocal" local-home="true" local-home-name = "MusicViewLocalHome" */public class MusicView  extends GenericSessionBean  implements SessionBean{  public void ejbCreate() {    // Your code here  }    /**     * @ejbgen:remote-method     */    public Collection getCategories(int parentId)        throws IllegalArgumentException    {        Collection c = null;        try {            c = JndiHelper.getCategoryLocalHome().findByParentId(parentId);        }        catch(FinderException fe) {            throw new IllegalArgumentException("No such parent category with id = " + parentId);        }        Iterator it = c.iterator();        Collection ret = new ArrayList();        while(it.hasNext()) {            ret.add(((CategoryLocal)it.next()).copy());        }        return ret;    }    /**     * @ejbgen:remote-method     */    public Collection getArtists(int categoryId)        throws IllegalArgumentException    {        // first find out the category:        CategoryLocalHome categoryHome = JndiHelper.getCategoryLocalHome();        CategoryLocal local = null;        try {            local = categoryHome.findByPrimaryKey(new Integer(categoryId));        }        catch(FinderException fe) {            throw new IllegalArgumentException("No such category with id " + categoryId);        }        Iterator it = local.getArtists().iterator();        Collection ret = new ArrayList();        while(it.hasNext()) {            ret.add(((ArtistLocal)it.next()).copy());        }        return ret;    }    /**     * 返回指定艺术家的所有专辑集合,类型为AlbumVO     * @param artistId 指定艺术家的ID     * @throw IllegalArgumentException 指定的艺术家不存在     * @ejbgen:remote-method     */    public Collection getAlbums(int artistId)        throws IllegalArgumentException    {        ArtistLocal artist = null;        try {            artist = JndiHelper.getArtistLocalHome().findByPrimaryKey(new Integer(artistId));        }        catch(FinderException fe) {            throw new IllegalArgumentException("No such artist with id " + artistId);        }        Iterator it = artist.getAlbums().iterator();        Collection ret = new ArrayList();        while(it.hasNext()) {            ret.add(((AlbumLocal)it.next()).copy());        }        return ret;    }    /**     * @ejbgen:remote-method     */    public Collection getSongs(int albumId)        throws IllegalArgumentException    {        AlbumLocal album = null;        try {            album = JndiHelper.getAlbumLocalHome().findByPrimaryKey(new Integer(albumId));        }        catch(FinderException fe) {            throw new IllegalArgumentException("No such album with id " + albumId);        }        Iterator it = album.getSongs().iterator();        Collection ret = new ArrayList();        while(it.hasNext()) {            ret.add(((SongLocal)it.next()).copy());        }        return ret;    }    /**     * @ejbgen:remote-method     */    public String getLyric(int songId)        throws IllegalArgumentException, LyricNotFoundException    {        SongLocal song = null;        try {            song = JndiHelper.getSongLocalHome().findByPrimaryKey(new Integer(songId));        }        catch(FinderException fe) {            throw new IllegalArgumentException("No such song with id " + songId);        }        if(!song.hasLyric())            throw new LyricNotFoundException("No lyric of this song.");        return song.getLyric();    }    /**     * @ejbgen:remote-method     */    public int rate(int songId, int mark) 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);        }        return song.rate(mark);    }    /**     * 返回对应的文件路径,例如:     * /pop/english/female/dido/no angel/thank you.mp3     * 如果song.hasUrl()==false, throw FileNotFoundException     * @ejbgen:remote-method     */    public String download(int songId)        throws IllegalArgumentException, FileNotFoundException    {        SongLocal song = null;        try {            song = JndiHelper.getSongLocalHome().findByPrimaryKey(new Integer(songId));        }        catch(FinderException fe) {            throw new IllegalArgumentException("No such song with id " + songId);        }        // then get the file:        if(!song.hasUrl())            throw new FileNotFoundException("No file associated with this song.");        return song.getUrl();    }    /**     * @ejbgen:remote-method     */    public Collection searchSongs(String title)        throws IllegalArgumentException    {        if(title==null)            throw new IllegalArgumentException("Title is NULL.");        title = title.trim().toLowerCase();        if(title.equals(""))            throw new IllegalArgumentException("Title is EMPTY.");        try {            Collection c = JndiHelper.getSongLocalHome().findByTitle(title);            Collection ret = new ArrayList(c.size());            Iterator it = c.iterator();            while(it.hasNext())                ret.add(((SongLocal)it.next()).copy());            return ret;        }        catch(FinderException fe) {}        return new ArrayList();    }    /**     * @ejbgen:remote-method     */    public Collection getCategoryFullPath(int categoryId)        throws IllegalArgumentException    {        CategoryLocal category = null;        try {            category = JndiHelper.getCategoryLocalHome().findByPrimaryKey(new Integer(categoryId));        }        catch(FinderException fe) {            throw new IllegalArgumentException("No such category with id " + categoryId);        }        return category.fullPath();    }    /**     * @ejbgen:remote-method     */    public ArtistVO getArtist(int albumId)        throws IllegalArgumentException    {        AlbumLocal album = null;        try {            album = JndiHelper.getAlbumLocalHome().findByPrimaryKey(new Integer(albumId));        }        catch(FinderException fe) {            throw new IllegalArgumentException("No such album with id " + albumId);        }        return album.getArtist().copy();    }    /**     * @ejbgen:remote-method     */    public AlbumVO getAlbum(int songId)        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);        }        return song.getAlbum().copy();    }}

⌨️ 快捷键说明

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