Rental ローカルエンティティビーン

[ 戻る ]
LocalHomeインターフェース
package refactor;

import javax.ejb.*;

public interface RentalHome extends javax.ejb.EJBLocalHome {
  public Rental create(String title, String custname, int daysrented) throws CreateException;
  public Rental findByPrimaryKey(RentalPK pk) throws FinderException;
}
Localインターフェース
package refactor;

public interface Rental extends javax.ejb.EJBLocalObject {
  public String getTitle();
  public String getCustname();
  public int getDaysrented();
  public Movie getMovie(); // Movieエンティティビーンへのリレーションシップ
  public double getCharge();
  public int getFrequentRenterPoints();
}
Beanクラス
package refactor;

import javax.ejb.*;

abstract public class RentalBean implements EntityBean {
  EntityContext entityContext;
  public RentalPK ejbCreate(String title, String custname, int daysrented) throws CreateException {
    setTitle(title);
    setCustname(custname);
    setDaysrented(daysrented);
    return null;
  }
  public void ejbPostCreate(String title, String custname, int daysrented) throws CreateException {
  }
  public void ejbRemove() throws RemoveException {
  }
  public abstract void setTitle(java.lang.String title);
  public abstract void setCustname(java.lang.String custname);
  public abstract void setDaysrented(int daysrented);
  public abstract void setMovie(refactor.Movie movie);
  public abstract java.lang.String getTitle();
  public abstract java.lang.String getCustname();
  public abstract int getDaysrented();
  public abstract refactor.Movie getMovie(); // Movieエンティティビーンへのリレーションシップ
  public void ejbLoad() {
  }
  public void ejbStore() {
  }
  public void ejbActivate() {
  }
  public void ejbPassivate() {
  }
  public void unsetEntityContext() {
    this.entityContext = null;
  }
  public void setEntityContext(EntityContext entityContext) {
    this.entityContext = entityContext;
  }

  /**
    * @return
    */
  public double getCharge() {
    return getMovie().getCharge(getDaysrented()); // Movieエンティティビーンに委譲
  }

  /**
    * @return
    */
  public int getFrequentRenterPoints() {
    return getMovie().getFrequentRenterPoints(getDaysrented()); // Movieエンティティビーンに委譲
  }
}
プライマリキークラス
package refactor;

import java.io.*;

public class RentalPK implements Serializable {

  public String title;
  public String custname;

  public RentalPK() {
  }
  public RentalPK(String title, String custname) {
    this.title = title;
    this.custname = custname;
  }
  public boolean equals(Object obj) {
    if (obj != null) {
      if (this.getClass().equals(obj.getClass())) {
        RentalPK that = (RentalPK) obj;
          return (((this.title == null) && (that.title == null)) || (this.title != null && this.title.equals(that.title))) &&
                    (((this.custname == null) && (that.custname == null)) || (this.custname != null &&
                     this.custname.equals(that.custname)));
      }
    }
    return false;
  }
  public int hashCode() {
    return (title + custname).hashCode();
  }
}

[ 戻る ]