Appendix B. The Code for Rosa's System

The SQL Code for Rosa's System

The following code snippet is the SQL script to create the tables for Rosa's Breakfast Service:

CREATE TABLE Comestible (
    comestibleID                   INTEGER                       NOT NULL,
    name                           VARCHAR (40)                  NULL,
    price                          REAL                          NULL,
    minimalQuantity                INTEGER                       NULL,
    transportForm                  VARCHAR (40)                  NULL,
    PRIMARY KEY (comestibleID)
);

CREATE TABLE StandardBreakfast (
    standardBreakfastID            INTEGER                       NOT NULL,
    name                           VARCHAR (40)                  NULL,
    price                          REAL                          NULL,
    style                          INTEGER                       NULL,
    PRIMARY KEY (tabelID)
);

CREATE TABLE Part (
    standardBreakfastID            INTEGER                       NOT NULL,
    comestibleID                   INTEGER                       NOT NULL,
    quantity                       INTEGER                       NULL,
    PRIMARY KEY (standardBreakfastID, comestibleID)
);

CREATE TABLE Customer (
    customerID                     INTEGER                       NOT NULL,
    accountNumber                  DECIMAL                       NULL,
    addressStreet                  VARCHAR (40)                  NULL,
    addressCity                    VARCHAR (40)                  NULL,
    addressStreetNumber            VARCHAR (40)                  NULL,
    addressPostalCode              VARCHAR (40)                  NULL,
    addressTelephoneNumber         VARCHAR (40)                  NULL,
    PRIMARY KEY (customerID)
);

CREATE TABLE BreakfastOrder (
    breakfastOrderID               INTEGER                       NOT NULL,
    customerId                     INTEGER                       NOT NULL,
    orderDate                      DATE                          NULL,
    deliveryAddressStreet          VARCHAR (40)                  NULL,
    deliveryAddressCity            VARCHAR (40)                  NULL,
    deliveryAddressStreetNumber    VARCHAR (40)                  NULL,
    deliveryAddressPostalCode      VARCHAR (40)                  NULL,
    deliveryAddressTelephoneNumber VARCHAR (40)                  NULL,
    deliveryDate                   DATE                          NULL,
    deliveryTime                   TIME                          NULL,
    discount                       REAL                          NULL,
    PRIMARY KEY (breakfastOrderID)
);

CREATE TABLE Breakfast (
    breakfastID                    INTEGER                       NOT NULL,
    breakfastOrderID               INTEGER                       NOT NULL,
    standardBreakfastID            INTEGER                       NOT NULL,
    number                         INTEGER                       NULL,
    PRIMARY KEY (breakfastID)
);

CREATE TABLE Change (
    breakfastID                    INTEGER                       NOT NULL,
    comestibleID                   INTEGER                       NOT NULL,
    quantity                       INTEGER                       NULL,
    PRIMARY KEY (breakfastId, comestibleID)
);

The EJB Code for Rosa's System

The following code sniplet describes the remote interface of the entity bean called BreakfastOrder:

import java.rmi.*;
import javax.naming.*;
import javax.ejb.*;
import breakfast.ejb.breakfastorder.*;

public interface BreakfastOrder extends EJBObject {

    public BreakfastOrderDataObject getBreakfastOrder()
                        throws  RemoteException;

    public void setBreakfastOrder(BreakfastOrderDataObject update)
                        throws  NamingException,
                                FinderException,
                                CreateException,
                                RemoteException;

    public float calculatePrice()
                        throws RemoteException;
}

The following code snippet shows the implementation of the data class for BreakfastOrder:

import breakfast.ejb.*;
import java.util.*;

public class BreakfastOrderDataObject
                       extends DataObject implements java.io.Serializable {

    private BreakfastOrderKey key;

    /**
     * Creates a new BreakfastOrderDataObject.
     * @param key initialize all fields necessary to uniquely identify
     * this object
     */
    public BreakfastOrderDataObject(BreakfastOrderKey key) {
        this.key = key;
        this.deliveryAddress = new Address();
    }

    public int getBreakfastOrderID() {
        return key.getBreakfastOrderID();
    }

    // References to associated single classes:
    private CustomerKey customercustomerKey;

    /**
     * Sets the foreign key CustomerKey of the singular referenced
     * Customer
     * @param  CustomerKey
     */
    public void setCustomerCustomer(CustomerKey s) {
        this.customercustomerKey = s;
    }

    /**
     * Returns the foreign key CustomerKey of the singular referenced Customer
     * @return  CustomerKey
     */
    public CustomerKey getCustomerCustomer() {
        return customercustomerKey;
    }

    // References to by-value-treated collections of objects:

    private breakfast.ejb.breakfastorder.BreakfastDataObjectCollection
                                  breakfastbreakfast;

    public void addBreakfast(
            breakfast.ejb.breakfastorder.BreakfastDataObject added) {
        this.breakfastbreakfast.add(added);
    }

    public void removeBreakfast(
            breakfast.ejb.breakfastorder.BreakfastDataObject removed) {
        this.breakfastbreakfast.remove(removed);
    }

    /**
     * Returns the internal BreakfastDataObjectCollection of the multiple
     * contained Breakfast.
     * @return breakfast.ejb.breakfastorder.
     *                                   BreakfastDataObjectCollection
     */
    public breakfast.ejb.breakfastorder.BreakfastDataObjectCollection
            getBreakfast() {
        if (breakfast == null) {
            breakfast =
        new breakfast.ejb.breakfastorder.BreakfastDataObjectListImpl();
        }
        return breakfast;
    }

    // No associated collections of objects by reference

    // Attributes:

    private java.util.Date orderDate;

    /**
     * Returns attribute orderDate.
     * @return java.util.Date
     */
    public java.util.Date getOrderDate() {
      return  orderDate;
    }

    public void setOrderDate(java.util.Date value) {
        this.orderDate = value;
    }

    private Address deliveryAddress;

    /**
     * Returns a copy of attribute deliveryAddress.
     * Since deliveryAddress is a StructType, we do not want that the
     * object returned by getDeliveryAddress() can implicitly change the
     * state of the owner BreakfastOrder.
     * Therefore a copy is returned.
     * @return Address
     */
    public Address getDeliveryAddress() {
      return deliveryAddress != null ? deliveryAddress.deepCopy() : null;
    }

    public void setDeliveryAddress(Address value) {
        this.deliveryAddress = value;
    }

    private java.util.Date deliveryDate;

    /**
     * Returns attribute deliveryDate.
     * @return java.util.Date
     */
    public java.util.Date getDeliveryDate() {
      return  deliveryDate;
    }

    public void setDeliveryDate(java.util.Date value) {
        this.deliveryDate = value;
    }

    private java.util.Date deliveryTime;

    /**
     * Returns attribute deliveryTime.
     * @return java.util.Date
     */
    public java.util.Date getDeliveryTime() {
      return  deliveryTime;
    }

    public void setDeliveryTime(java.util.Date value) {
        this.deliveryTime = value;
    }

    private floatdiscount;

    /**
     * Returns attribute discount.
     * @return float
     */
    public float getDiscount() {
      return  discount;
    }

    public void setDiscount(float value) {
        this.discount = value;
    }

}

The JSP Code for Rosa's System

<%-- Page Directives  --%>
<%@ page import    = "java.util.*" %>
<%@ page import    = "breakfast.ejb.*"%>
<%@ page import    = "breakfast.ejb.customer.*"%>
<%@ page errorPage ="AppError.jsp" %>
<%-- Include Directives --%>

<%-- Tag Library Directives --%>

<%-- Variable and Method declarations --%>
<%!
Collection CustomerCollection;
CustomerDataObject Customer;
Iterator it;
%>
<%-- Actions --%>
<jsp:useBean id="CustomerDom" scope="request"
class="breakfast.ejb.CustomerDataObjectManager"/>

<HTML>
<head>
<title>moduleseparatorCustomer</title>
<link href="css/ApplicationStyle.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table class="layout-table">

<tr class="layout-row"><td class="layout-cell">


<p>
This Page illustrates how a Retrieve is executed on the EJB tier.
</p>
<p>
It is written as pure Jsp, with a connection to basic OptimalJ
data-structures.
</p>
<p></p>
<table align="center" border="1" summary="">
  <!-- table heading -->
  <tr>
    <th align=left><font size="5"><b>Customer</b></font></th>
  </tr>
  <tr>
    <td align=left><font size="3"><b>id</b></font></td>
    <td align=left><font size="3"><b>address</b></font></td>
    <td align=left><font size="3"><b>accountNumber</b></font></td>
  </tr>
  <!-- table data -->
  <%
  // let Remote View Manager retrieve data
  CustomerCollection = CustomerDom.retrieve();

  it = CustomerCollection.iterator();

  // iterate collection and write data elements
  while (it.hasNext()) {
    Customer = (CustomerDataObject) it.next();
    request.setAttribute("Customer", Customer);
  %>
  <tr>
    <td align=left><font size="3"><jsp:getProperty name="Customer"
property="id"/></font></td>
    <td align=left><font size="3"><jsp:getProperty name="Customer"
property="address"/></font></td>
    <td align=left><font size="3"><jsp:getProperty name="Customer"
property="accountNumber"/></font></td>
  </tr>
  <%
  }
  %>
</table>
<p></p>
</td></tr>

</table>

</body>

</HTML>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.55.14