Tuesday, 12 May 2009

3-How to Develop Container-Managed-Relationships

FILE OrderARSLineItemLocalHome.java
package cmrex;

import javax.ejb.*;
import java.util.*;
public interface OrderARSLineItemLocalHome extends EJBLocalHome {
public OrderARSLineItemLocal create(String orderLineItemId,
String courseId, double fee) throws CreateException;
public OrderARSLineItemLocal findByPrimaryKey(String key)
throws FinderException;

FILE OrderARSLineItemLocal.java

package cmrex;

import weblogic.ejb.EJBLocalObject;

public interface OrderARSLineItemLocal extends javax.ejb.EJBLocalObject{
public String getOrderLineItemId();
public String getCourseId();
public void setCourseId(String courseId);
public double getFee();
public void setFee(double fee);
public OrderARSLocal getOrder();
public void setOrder(OrderARSLocal o);

FILE OrderARSLineItemEJB.java
package cmrex;

import javax.naming.*;
import javax.ejb.*;
import java.util.*;
public abstract class OrderARSLineItemEJB implements EntityBean {
protected EntityContext ctx;
/* get and set methods for cmp fields */
public OrderARSLineItemEJB() {}
public abstract String getOrderLineItemId();
public abstract void setOrderLineItemId(String id);
public abstract String getCourseId();
public abstract void setCourseId(String courseId);
public abstract double getFee();
public abstract void setFee(double fee);
/* get and set methods for relationship fields */
public abstract OrderARSLocal getOrder();
public abstract void setOrder(OrderARSLocal order);
/* Callback methods */
public void setEntityContext(EntityContext ctx) {
this.ctx = ctx;
public void unsetEntityContext() {
this.ctx = null;
public void ejbActivate() {}
public void ejbPassivate() {}
public void ejbStore() {}
public void ejbLoad() {}
public String ejbCreate(String orderLineItemId, String courseId,
double fee) throws CreateException {
print("Creating OrderLineItem id:" + orderLineItemId );
return null;
public void ejbPostCreate(String orderLineItemId, String courseId,
double fee) throws CreateException {}
public void ejbRemove() {
print("Removing OrderLineItem id:" + (String)ctx.getPrimaryKey() );
void print(String s) {

FILE ClientLineItem
package cmrex;

public class ClientLineItem implements java.io.Serializable {
private String orderLineItemId;
private String courseId;
private double fee;
public ClientLineItem(String orderLineItemId,
String courseId, double fee) {
this.orderLineItemId = orderLineItemId;
this.courseId = courseId;
this.fee = fee;
public String getOrderLineItemId() {
return orderLineItemId ;
public double getFee() {
return fee;
public String getCourseId() {
return courseId;