Hi
In ejb-2_0-pfd2-spec.pdf have in page 158,
illustrates an Order entity bean with relationships to line items and
customers, which are other
entity beans within the same local scope. Products are indirectly related to
the Order entity bean by
means of the relationship between line items and products.

I would like code of the LineItem.

Please help.

�lvaro


package com.acme.order;
// This example shows the implementation of OrderBean, the
// entity bean class for the OrderEJB entity bean. OrderEJB has
// container managed relationships with the entity beans
// CustomerEJB and LineItemEJB.
// This example illustrates the use of local interfaces.
import java.util.Collection;
import java.util.Vector;
import java.util.Date;
import javax.naming.*;
public abstract class OrderBean implements javax.ejb.EntityBean {
private javax.ejb.EntityContext context;
// define status codes for processing
static final int BACKORDER = 1;
static final int SHIPPED = 2;
static final int UNSHIPPED = 3;
// get and set methods for the cmp fields
public abstract int getOrderStatus();
public abstract void setOrderStatus(int orderStatus);
public abstract boolean getCreditApproved();
public abstract void setCreditApproved(boolean creditapproved);
public abstract Date getOrderDate();
public abstract void setOrderDate(Date orderDate);
// get and set methods for the relationship fields
public abstract Collection getLineItems();
public abstract void setLineItems(Collection lineitems);
public abstract Customer getCustomer();
public abstract void setCustomer(Customer customer);
// business methods.
// addLineItem:
// This method is used to add a line item.
// It creates the lineitem object and adds it to the
// persistent managed relationship.
public void addLineItem(Product product,
int quantity,
Address address)
throws InsufficientInfoException
{
// create a new line item

if (validAddress(address)) {
// Address is a legacy class. It is a dependent value
// class that is available both in the client and in
// the entity bean, and is serializable.
// We will use the address as the value of a cmp field
// of lineItem.
try {
Context ic = new InitialContext();
LineItemLocalHome litemLocalHome =
(LineItemLocalHome)ic.lookup("LineItemEJB");
LineItem litem = litemLocalHome.create();
litem.setProduct(product);
litem.setQuantity(quantity);
litem.setTax(calculateTax(product.getPrice(),
quantity,
address));
litem.setStatus(UNSHIPPED);
// set the address for the line item to be shipped
litem.setAddress(address);
// The lineItem entity bean uses a dependent value
// class to represent the dates for the order status.
// This class holds shipment date, expected shipment
// date, credit approval date, and inventory
// dates which are internal to the order fullfillment
// process. Not all this information will be available
// to the client.
Dates dates = new Dates();
litem.setDates(dates);
getLineItems().add(litem);
} catch (Exception someexception) {}
} else {
throw new InsufficientInfoException();
}
}

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to