EJBs: Entity Beans (EJB Components)

You learned about entity beans on Days 12 and 13. Listings C.17 C.27 are the detailed listings for each of the entity beans described in Chapter 13 for the MVC application. These files are to be placed in the directory called ejb_components_src, discussed on Day 16.

Listing C.17 FlightHome.java
 /******************************************************************************  * Class Name:FlightHome.java  * Description:Home Interface for FlightBean. Defines the finder methods  * @author Mandar S. Chitnis, Pravin S. Tiwari, Lakshmi AM.       @version 11.5  * Copyright (c) by Sams Publishing. All Rights Reserved. ******************************************************************************/ package com.sams.learnweblogic7.airlines.entitybean; import javax.ejb.*; import java.util.*; import javax.ejb.FinderException; import java.rmi.RemoteException; public interface FlightHome extends EJBLocalHome {   public FlightInterface findByPrimaryKey(FlightPK key)     throws FinderException;   public Collection findAvailableFlights(String fromLocation, String toLocation,           java.sql.Date travelDate)throws FinderException;   public FlightInterface findFlightForADate(int flightId,           java.sql.Date travelDate)throws FinderException; } 
Listing C.18 FlightInterface.java
 /******************************************************************************  * Class Name:FlightInterface.java  * Description:Local Interface for FlightBean. Defines the getter setter methods                for the container managed fields.  * @author Mandar S. Chitnis, Pravin S. Tiwari, Lakshmi AM.       @version 11.5  * Copyright (c) by Sams Publishing. All Rights Reserved. ******************************************************************************/ package com.sams.learnweblogic7.airlines.entitybean; import javax.ejb.*; import java.rmi.*; import java.sql.Time; import java.sql.Date; import com.sams.learnweblogic7.airlines.businessobject.*; import com.sams.learnweblogic7.airlines.constants.*; public interface FlightInterface extends EJBLocalObject { //airlineId getter-setter methods   public int getAirlineId();   public void setAirlineId(int airlineId);   //airlineName getter-setter methods   public String getAirlineName();   public void setAirlineName(String airlineName);   //flightId getter-setter methods   public int getFlightId();   public void setFlightId(int flightId); //fromLocation getter-setter methods   public String getFromLocation();   public void setFromLocation(String fromLocation); //toLocation getter-setter methods   public String getToLocation();   public void setToLocation(String toLocation); //departureTime getter-setter methods   public Time getDepartureTime();   public void setDepartureTime(Time departureTime); //arrivalTime getter-setter methods   public Time getArrivalTime();   public void setArrivalTime(Time arrivalTime); //duration getter-setter methods   public double getDuration();   public void setDuration(double duration); //totalSeats getter-setter methods   public int getTotalSeats();   public void setTotalSeats(int totalSeats); //price getter-setter methods   public double getPrice();   public void setPrice(double price); //departureDate getter-setter methods   public Date getFlightDepartureDate();   public void setFlightDepartureDate(Date flightDepartureDate); //availableSeats getter-setter methods   public int getAvailableSeats();   public void setAvailableSeats(int availableSeats); } 
Listing C.19 FlightBean.java
 /******************************************************************************  * Class Name:FlightBean.java  * Description: FlightBean. Gives the signatures as per EJB specifications.  * @author Mandar S. Chitnis, Pravin S. Tiwari, Lakshmi AM.       @version 11.5  * Copyright (c) by Sams Publishing. All Rights Reserved. ******************************************************************************/ package com.sams.learnweblogic7.airlines.entitybean; import java.sql.Time; import java.sql.Date; import javax.ejb.EntityBean; import javax.ejb.EntityContext; public abstract class FlightBean implements EntityBean {   //The container assigned reference to the entity   private EntityContext context;   public FlightBean() {   }   //signatures for the getter setter methods of the container managed fields   abstract public int getAirlineId();   abstract public void setAirlineId(int airlineId);   abstract public String getAirlineName();   abstract public void setAirlineName(String airlineName);   abstract public int getFlightId();   abstract public void setFlightId(int flightId);   abstract public String getFromLocation();   abstract public void setFromLocation(String fromLocation);   abstract public String getToLocation();   abstract public void setToLocation(String toLocation);   abstract public Time getDepartureTime();   abstract public void setDepartureTime(Time departureTime);   abstract public Time getArrivalTime() ;   abstract public void setArrivalTime(Time arrivalTime);   abstract public double getDuration();   abstract public void setDuration(double duration);   abstract public int getTotalSeats();   abstract public void setTotalSeats(int totalSeats);   abstract public double getPrice();   abstract public void setPrice(double price);   abstract public Date getFlightDepartureDate() ;   abstract public void setFlightDepartureDate(Date flightDepartureDate);   abstract public int getAvailableSeats();   abstract public void setAvailableSeats(int availableSeats);   //Sets the context of the bean   public void setEntityContext(EntityContext ec) {     context=ec;   }   //Clears the context of the bean   public void unsetEntityContext() {     this.context=null;   }   /**    * This method is called when the container picks this entity object    * and assigns it to a specific entity object. Insert code here to    * acquire any additional resources that it needs when it is in the    * ready state.   */   public void ejbActivate() {   }   /**    * This method is called when the container disassociates the bean    * from the entity object identity and puts the instance back into    * the pool of available instances. Insert code to release any    * resources that should not be held while the instance is in the    * pool.   */   public void ejbPassivate() {   }   /**    * The container invokes this method on the bean whenever it    * becomes necessary to synchronize the bean's state with the    * state in the database. This method is called after the container    * has loaded the bean's state from the database.   */   public void ejbLoad() {   }   /**    * The container invokes this method on the bean whenever it    * becomes necessary to synchronize the state in the database    * with the state of the bean. This method is called before the    * container extracts the fields and writes them into the database.    */   public void ejbStore() {   }   /**    * This method is invoked when a client invokes the matching create()    * on the home interface. Initialize the fields that will be used    * by the container to create a record in the database.    * param airlineId    * param airlineName    * param flightId    * param fromLocation    * param toLocation    * param departureTime    * param arrivalTime    * param duration    * param totalSeats    * param price    * param flightDepartureDate    * param availableSeats    * return Returns the primary key of the new entity    */   public FlightPK ejbCreate(int airlineId, String airlineName, int flightId,           String fromLocation, String toLocation, Time departureTime,           Time arrivalTime, int duration, int price, int totalSeats,           Date flightDepartureDate, int availableSeats) {     setAirlineId(airlineId);     setAirlineName(airlineName);     setFlightId(flightId);     setFromLocation(fromLocation);     setToLocation(toLocation);     setDepartureTime(departureTime);     setArrivalTime(arrivalTime);     setDuration(duration);     setPrice(price);     setTotalSeats(totalSeats);     setFlightDepartureDate(flightDepartureDate);     setAvailableSeats(availableSeats);     return null;   }   /**    * The container invokes this method after invoking the ejbCreate    * method with the same arguments.    * param airlineId    * param airlineName    * param flightId    * param fromLocation    * param toLocation    * param departureTime    * param arrivalTime    * param duration    * param totalSeats    * param price    * param flightDepartureDate    * param availableSeats    */   public void ejbPostCreate(int airlineId, String airlineName, int flightId,           String fromLocation, String toLocation, Time departureTime,           Time arrivalTime, int duration, int price, int totalSeats,           Date flightDepartureDate, int availableSeats) {   }   /**    * The container invokes this method in response to a client-invoked    * remove request. Insert code to implement any actions before the    * bean is removed from the database.    */   public void ejbRemove() {   } } 
Listing C.20 FlightPK.java
 /******************************************************************************  * Class Name:FlightPK.java  * Description: Primary key class for FlightBean. *  @author Mandar S. Chitnis, Pravin S. Tiwari, Lakshmi AM.       @version 11.5  * Copyright (c) by Sams Publishing. All Rights Reserved. ******************************************************************************/ package com.sams.learnweblogic7.airlines.entitybean; import java.io.Serializable; public class FlightPK implements Serializable {   public int flightId;   public FlightPK() {   }   //Method hashcode using airlineId   public int hashCode() {     return (flightId); }   //compare class using airline_id   public boolean equals(Object that) {     if(!(that instanceof FlightPK)){       return false;     }     FlightPK tmp=(FlightPK)that;     return (this.flightId==tmp.flightId);   } } 
Listing C.21 PassengerHome.java
 /******************************************************************************  * Class Name:PassengerHome.java  * Description:Home Interface for PassengerBean. Defines the finder methods  * @author Mandar S. Chitnis, Pravin S. Tiwari, Lakshmi AM.       @version 11.5  * Copyright (c) by Sams Publishing. All Rights Reserved. ******************************************************************************/ package com.sams.learnweblogic7.airlines.entitybean; import javax.ejb.*; import java.util.*; import javax.ejb.FinderException; import java.rmi.RemoteException; public interface PassengerHome extends EJBLocalHome {   public PassengerInterface create(String profileId, String password,           String firstName, String lastName, String address, String telNo,           String emailId, String cardNumber, String cardType,           int expirationMonth, int expirationYear)throws FinderException,           CreateException;   public PassengerInterface findByPrimaryKey(String key)     throws FinderException;   public PassengerInterface findByPassword(String profileID , String password)     throws FinderException; } 
Listing C.22 PassengerInterface.java
 /******************************************************************************  * Class Name:PassengerInterface.java  * Description:Local Interface for PassengerBean. Defines the getter-setter                methods for the cmp fields and business methods.  * @author Mandar S. Chitnis, Pravin S. Tiwari, Lakshmi AM.       @version 11.5  * Copyright (c) by Sams Publishing. All Rights Reserved. ******************************************************************************/ package com.sams.learnweblogic7.airlines.entitybean; import javax.ejb.*; import java.rmi.*; import com.sams.learnweblogic7.airlines.businessobject.PassengerProfile; import java.rmi.RemoteException; public interface PassengerInterface extends EJBLocalObject {   //business method   public PassengerProfile getPassengerDetails(String profileID, String password);   //getter-setter methods for the cmp fields   public String getProfileId();   public void setProfileId(String profileId);   public String getPassword();   public void setPassword(String password);   public String getFirstName();   public void setFirstName(String firstName);   public String getLastName();   public void setLastName(String lastName);   public String getAddress();   public void setAddress(String address);   public String getTelNo();   public void setTelNo(String telNo);   public String getEmailId();   public void setEmailId(String emailId);   public String getCardNumber();   public void setCardNumber(String cardNumber);   public String getCardType();   public void setCardType(String cardType);   public int getExpirationMonth();   public void setExpirationMonth(int expirationMonth);   public int getExpirationYear();   public void setExpirationYear(int expirationYear); } 
Listing C.23 PassengerBean.java
 /******************************************************************************  * Class Name:PassengerBean.java  * Description:Implementation of PassengerBean.  * @author Mandar S. Chitnis, Pravin S. Tiwari, Lakshmi AM.       @version 11.5  * Copyright (c) by Sams Publishing. All Rights Reserved. ******************************************************************************/ package com.sams.learnweblogic7.airlines.entitybean; import java.sql.Time; import java.sql.Date; import javax.ejb.EntityBean; import javax.ejb.EntityContext; import com.sams.learnweblogic7.airlines.businessobject.PassengerProfile; abstract public class PassengerBean implements EntityBean {   /**    * The container assigned reference to the entity    */   private EntityContext context;   public PassengerBean() {   }   //abstract getter-setter methods for cmp fields   abstract public String getProfileId();   abstract public void setProfileId(String profileId);   abstract public String getPassword();   abstract public void setPassword(String password) ;   abstract public String getFirstName();   abstract public void setFirstName(String firstName);   abstract public String getLastName();   abstract public void setLastName(String lastName);   abstract public String getAddress() ;   abstract public void setAddress(String address);   abstract public String getTelNo();   abstract public void setTelNo(String telNo);   abstract public String getEmailId();   abstract public void setEmailId(String emailId) ;   abstract public String getCardNumber();   abstract public void setCardNumber(String cardNumber);   abstract public String getCardType();   abstract public void setCardType(String cardType);   abstract public int getExpirationMonth();   abstract public void setExpirationMonth(int expirationMonth);   abstract public int getExpirationYear();   abstract public void setExpirationYear(int expirationYear);   /**    * Sets the context of the bean    * param ec    */   public void setEntityContext(EntityContext ec) {     context=ec;   }   /**    * Clears the context of the bean    */   public void unsetEntityContext() {     this.context=null;   }   /**    * This method is called when the container picks this entity object    * and assigns it to a specific entity object. Insert code here to    * acquire any additional resources that it needs when it is in the    * ready state.    */   public void ejbActivate() {   }   /**    * This method is called when the container disassociates the bean    * from the entity object identity and puts the instance back into    * the pool of available instances. Insert code to release any    * resources that should not be held while the instance is in the    * pool.    */   public void ejbPassivate() {   }   /**    * The container invokes this method on the bean whenever it    * becomes necessary to synchronize the bean's state with the    * state in the database. This method is called after the container    * has loaded the bean's state from the database.    */   public void ejbLoad() {   }   /**    * The container invokes this method on the bean whenever it    * becomes necessary to synchronize the state in the database    * with the state of the bean. This method is called before the    * container extracts the fields and writes them into the database.    */   public void ejbStore() {   }   /**    * This method is invoked when a client invokes the matching create()    * on the home interface. Initialize the fields that will be used    * by the container to create a record in the database.    *    *param profileId    *param password    *param firstName    *param lastName    *param address    *param telNo    *param emailId    *param cardNumber    *param profileId0    *param cardType    *param expirationMonth    *param expirationYear    *return Returns the primary key of the new entity    */   public String ejbCreate(String profileId, String password, String firstName,           String lastName, String address, String telNo, String emailId,           String cardNumber, String cardType, int expirationMonth,           int expirationYear) {     setProfileId(profileId);     setPassword(password);     setFirstName(firstName);     setLastName(lastName);     setAddress(address);     setTelNo(telNo);     setEmailId(emailId);     setCardNumber(cardNumber);     setCardType(cardType);     setExpirationMonth(expirationMonth);     setExpirationYear(expirationYear);     return null;   }   /**    * The container invokes this method after invoking the ejbCreate    * method with the same arguments.    *param profileId    *param password    *param firstName    *param lastName    *param address    *param telNo    *param emailId    *param cardNumber    *param profileId    *param cardType    *param expirationMonth    *param expirationYear    */   public void ejbPostCreate(String profileId, String password, String firstName,           String lastName, String address, String telNo, String emailId,           String cardNumber, String cardType, int expirationMonth,           int expirationYear){   }   /**    * The container invokes this method in response to a client-invoked    * remove request. Insert code to implement any actions before the    * bean is removed from the database.    */   public void ejbRemove() {   }   /**    *returns Business Object PassengerProfile    */   public PassengerProfile getPassengerDetails(String profileID, String password)  {     return (null);   } } 
Listing C.24 TicketInfoHome.java
 /******************************************************************************  * Class Name:TicketInfoHome.java  * Description:Home interface for TicketInfoBean.  * @author Mandar S. Chitnis, Pravin S. Tiwari, Lakshmi AM.       @version 11.5  * Copyright (c) by Sams Publishing. All Rights Reserved. ******************************************************************************/ package com.sams.learnweblogic7.airlines.entitybean; import javax.ejb.*; import java.sql.Date; import java.util.*; import javax.ejb.FinderException; import java.rmi.RemoteException; public interface TicketInfoHome extends EJBLocalHome {   public TicketInfoInterface create(long ticketId, String profileId, String           status, int flightId, Date departureDate) throws FinderException,           CreateException;   public TicketInfoInterface findByPrimaryKey(TicketInfoPK key)     throws FinderException;   public Collection findByProfileID(String profileId)     throws FinderException; } 
Listing C.25 TicketInfoInterface.java
 /******************************************************************************  * Class Name:TicketInfoInterface.java  * Description:Local interface for TicketInfoBean.  * @author Mandar S. Chitnis, Pravin S. Tiwari, Lakshmi AM.       @version 11.5  * Copyright (c) by Sams Publishing. All Rights Reserved. ******************************************************************************/ package com.sams.learnweblogic7.airlines.entitybean; import javax.ejb.*; import com.sams.learnweblogic7.airlines.businessobject.TicketDetails; import java.rmi.RemoteException; import java.sql.Date; public interface TicketInfoInterface extends EJBLocalObject { //getter-setter methods for cmp fields   public long getTicketId();   public void setTicketId(long ticketId);   public String getProfileId();   public void setProfileId(String profileId);   public String getStatus();   public void setStatus(String status);   public int getFlightId();   public void setFlightId(int flightId);   public Date getDepartureDate();   public void setDepartureDate(Date departureDate); } 
Listing C.26 TicketInfoBean.java
 /******************************************************************************  * Class Name:TicketInfoBean.java  * Description:Implementation class of TicketInfoBean.  * @author Mandar S. Chitnis, Pravin S. Tiwari, Lakshmi AM.       @version 11.5  * Copyright (c) by Sams Publishing. All Rights Reserved. ******************************************************************************/ package com.sams.learnweblogic7.airlines.entitybean; import java.sql.Date; import javax.ejb.EntityBean; import javax.ejb.EntityContext; import com.sams.learnweblogic7.airlines.businessobject.TicketDetails; abstract public class TicketInfoBean implements EntityBean {   /**    * The container assigned reference to the entity    */   private EntityContext context;   public TicketInfoBean() {   }   //getter-setter methods for cmp fields   abstract public long getTicketId();   abstract public void setTicketId(long ticketId);   abstract public String getProfileId() ;   abstract public void setProfileId(String profileId);   abstract public String getStatus();   abstract public void setStatus(String status);   abstract public int getFlightId();   abstract public void setFlightId(int flightId);   abstract public Date getDepartureDate();   abstract public void setDepartureDate(Date departureDate);   /**    * Sets the context of the bean    */   public void setEntityContext(EntityContext ec) {     context=ec;   }   /**    * Clears the context of the bean    */   public void unsetEntityContext() {     this.context=null;   }   /**    * This method is called when the container picks this entity object    * and assigns it to a specific entity object. Insert code here to    * acquire any additional resources that it needs when it is in the    * ready state.    */   public void ejbActivate() {   }   /**    * This method is called when the container disassociates the bean    * from the entity object identity and puts the instance back into    * the pool of available instances. Insert code to release any    * resources that should not be held while the instance is in the    * pool.    */   public void ejbPassivate() {   }   /**    * The container invokes this method on the bean whenever it    * becomes necessary to synchronize the bean's state with the    * state in the database. This method is called after the container    * has loaded the bean's state from the database.    */   public void ejbLoad() {   }   /**    * The container invokes this method on the bean whenever it    * becomes necessary to synchronize the state in the database    * with the state of the bean. This method is called before the    * container extracts the fields and writes them into the database.    */   public void ejbStore() {   }   /**    * This method is invoked when a client invokes the matching create()    * on the home interface. Initialize the fields that will be used    * by the container to create a record in the database.    *    * @param ticketId    * @param profileId    * @param departureDate    * @param status    * @param flightId    * @return Returns the primary key of the new entity    */   public TicketInfoPK ejbCreate(long ticketId, String profileId, String status,           int flightId, Date departureDate) {     setTicketId(ticketId);     setProfileId(profileId);     setStatus(status);     setFlightId(flightId);     setDepartureDate(departureDate);     return null;   }   /**    * The container invokes this method after invoking the ejbCreate    * method with the same arguments.    * @param ticketId    * @param profileId    * @param departureDate    * @param status    * @param flightId    */   public void ejbPostCreate(long ticketId, String profileId, String status,           int flightId, Date departureDate) {   }   /**    * The container invokes this method in response to a client-invoked    * remove request. Insert code to implement any actions before the    * bean is removed from the database.    */   public void ejbRemove() {   } } 
Listing C.27 TicketInfoPK.java
 /******************************************************************************  * Class Name:TicketInfoPK.java  * Description:Primary key class for TicketInfoBean.  * @author Mandar S. Chitnis, Pravin S. Tiwari, Lakshmi AM.       @version 11.5  * Copyright (c) by Sams Publishing. All Rights Reserved. ******************************************************************************/ package com.sams.learnweblogic7.airlines.entitybean; import java.io.Serializable; public class TicketInfoPK implements Serializable {   public long ticketId;   public TicketInfoPK() {   }    //Method hashcode using profile_id, flight_id   public int hashCode() {     return (200);   }   //Method compare class using profile_id, flight_id   public boolean equals(Object that) {     if (!(that instanceof TicketInfoPK))       return false;     TicketInfoPK tmp=(TicketInfoPK)that;     return true;   } } 


Sams Teach Yourself BEA WebLogic Server 7. 0 in 21 Days
Sams Teach Yourself BEA WebLogic Server 7.0 in 21 Days
ISBN: 0672324334
EAN: 2147483647
Year: 2002
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net