attendeemanager.java

来自「100多M的J2EE培训内容」· Java 代码 · 共 94 行

JAVA
94
字号
package com.borland.training.meetings.sessions;import java.util.*;import javax.ejb.*;import javax.naming.*;import com.borland.training.meetings.entities.*;import com.borland.training.meetings.sessions.*;class AttendeeManager {  private static AttendeeManager instance = null;  private AttendeeValueFactory attendeeValueFactory;  private MeetingValueFactory meetingValueFactory;  private EJBHomeFactory homeFactory;  private AttendeeManager() throws NamingException {    homeFactory = EJBHomeFactory.getInstance();    attendeeValueFactory = AttendeeValueFactory.getInstance();    meetingValueFactory = MeetingValueFactory.getInstance();  }  public static AttendeeManager getInstance() throws NamingException {    if(instance == null) {      instance = new AttendeeManager();    }    return instance;  }  public Long createAttendee(AttendeeValue attendeeValue)    throws FinderException, NamingException {    try {      AttendeeHome attendeeHome =        (AttendeeHome) homeFactory.lookupByLocalEJBReference("Attendee");      Attendee attendee = attendeeHome.create(attendeeValue.getName(),        attendeeValue.getPosition(),        attendeeValue.getTitle(),        attendeeValue.getPhone(),        attendeeValue.getEmail());      return attendee.getId();    }    catch(Exception e) {      throw new EJBException(e);    }  }  // Updating the attendee's meeting list is not supported here.  // This functionality is provided by the Meeting bean.  public void updateAttendee(AttendeeValue attendeeValue)    throws FinderException, NamingException {    try {      Attendee attendee = attendeeValueFactory.findAttendee(attendeeValue.getId());      attendee.setName(attendeeValue.getName());      attendee.setPosition(attendeeValue.getPosition());      attendee.setTitle(attendeeValue.getTitle());      attendee.setPhone(attendeeValue.getPhone());      attendee.setEmail(attendeeValue.getEmail());    }    catch(Exception e) {      throw new EJBException(e);    }  }  public void removeAttendee(Long id)    throws FinderException, NamingException {    try {      Attendee attendee = attendeeValueFactory.findAttendee(id);      attendee.remove();    }    catch(Exception e) {      throw new EJBException(e);    }  }  public void removeAllAttendees()    throws FinderException, NamingException {    try {      Collection attendees = attendeeValueFactory.findAllAttendees();      Iterator iterator = attendees.iterator();      Attendee attendee = null;      while(iterator.hasNext()) {        attendee = (Attendee) iterator.next();        attendee.remove();      }    }    catch(Exception e) {      throw new EJBException(e);    }  }}

⌨️ 快捷键说明

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