The Music session bean will be called by a page flow application to work with band and recording data. Here you will add component methods to work with recording data. The tasks in this step are:
In this step you add the corresponding business methods addRecording and getRecordings to the Music bean:
/** * @ejbgen:local-method */ public void addRecording(String band, String recording) { try { Band bandBean = bandHome.findByPrimaryKey(new BandPK(band)); if(bandBean != null) { bandBean.addRecording(recording); } } catch(CreateException ce) { throw new EJBException(ce); } catch(FinderException fe) { throw new EJBException(fe); } }
Notice that the method uses the Band bean's findByPrimaryKey method to locate the band bean and uses the band bean's method addRecording to add the recording to the database.
/** * @ejbgen:local-method */ public Collection getRecordings(String band) { Collection result = new ArrayList(); try { Band theBand = bandHome.findByPrimaryKey(new BandPK(band)); result.addAll(theBand.getRecordingValues()); } catch(Exception e) { System.out.println("error getting recordings from music bean: " + e.getMessage()); } return result; }
Notice that the method uses the Band bean's findByPrimaryKey to locate the band bean and uses the band bean's method getRecordingValues to receive a list of the band's recordings.
If you encounter build errors related to the component methods, verify that the methods have been defined correctly. A build error might be followed by a deployment error, in particular for WebAppOne_Standard and related to an unresolved ejb-link. The link cannot be resolved because the EJB JAR was not created. Fixing the build problem should resolve this deployment error. If you encounter deployment errors that seem to be related to one of the web applications, make sure that you build the EJB project and not the entire application (because the application contains page flow applications that have different EJB dependencies from what you have created in this step).
Click one of the following arrows to navigate through the tutorial: