edu.rice.rubis.beans
Class ItemBean

java.lang.Object
  |
  +--edu.rice.rubis.beans.ItemBean
All Implemented Interfaces:
javax.ejb.EnterpriseBean, javax.ejb.EntityBean, java.io.Serializable

public class ItemBean
extends java.lang.Object
implements javax.ejb.EntityBean

ItemBean is an entity bean with "container managed persistence". The state of an instance is stored into a relational database. The following table should exist:

 CREATE TABLE items (
    id            INTEGER UNSIGNED NOT NULL UNIQUE,
    name          VARCHAR(100),
    description   TEXT,
    initial_price FLOAT UNSIGNED NOT NULL,
    quantity      INTEGER UNSIGNED NOT NULL,
    reserve_price FLOAT UNSIGNED DEFAULT 0,
    buy_now       FLOAT UNSIGNED DEFAULT 0,
    nb_of_bids    INTEGER UNSIGNED DEFAULT 0,
    max_bid       FLOAT UNSIGNED DEFAULT 0,
    start_date    DATETIME,
    end_date      DATETIME,
    seller        INTEGER,
    category      INTEGER,
    PRIMARY KEY(id),
    INDEX seller_id (seller),
    INDEX category_id (category)
 );
 

Version:
1.1
Author:
Emmanuel Cecchet and Julie Marguerite
See Also:
Serialized Form

Field Summary
 float buyNow
           
 java.lang.Integer categoryId
           
 java.lang.String description
           
 java.lang.String endDate
           
 java.lang.Integer id
           
 float initialPrice
           
 float maxBid
           
 java.lang.String name
           
 int nbOfBids
           
 int quantity
           
 float reservePrice
           
 java.lang.Integer sellerId
           
 java.lang.String startDate
           
 
Constructor Summary
ItemBean()
           
 
Method Summary
 void addOneBid()
          Add one bid for this item
 void ejbActivate()
          This method is empty because persistence is managed by the container
 ItemPK ejbCreate(java.lang.String itemName, java.lang.String itemDescription, float itemInitialPrice, int itemQuantity, float itemReservePrice, float itemBuyNow, int duration, java.lang.Integer itemSellerId, java.lang.Integer itemCategoryId)
          This method is used to create a new Item Bean.
 void ejbLoad()
          Persistence is managed by the container and the bean becomes up to date
 void ejbPassivate()
          This method is empty because persistence is managed by the container
 void ejbPostCreate(java.lang.String itemName, java.lang.String itemDescription, float itemInitialPrice, int itemQuantity, float itemReservePrice, float itemBuyNow, int duration, java.lang.Integer itemSellerId, java.lang.Integer itemCategoryId)
          This method does currently nothing
 void ejbRemove()
          This method is empty because persistence is managed by the container
 void ejbStore()
          Persistence is managed by the container and the bean becomes up to date
 float getBuyNow()
          Get item Buy Now price set by the seller.
 java.lang.Integer getCategoryId()
          Give the category id of the item
 java.lang.String getCategoryName()
          Get the category name by finding the Bean corresponding to the category Id.
 java.lang.String getDescription()
          Get item description .
 java.lang.String getEndDate()
          End date of the auction in the format 'YYYY-MM-DD hh:mm:ss'
 java.lang.Integer getId()
          Get item id.
 float getInitialPrice()
          Get item initial price set by the seller.
 float getMaxBid()
          Get item maximum bid (if any) for this item.
 java.lang.String getName()
          Get item name.
 int getNbOfBids()
          Get number of bids for this item.
 int getQuantity()
          Get how many of this item are to be sold.
 float getReservePrice()
          Get item reserve price set by the seller.
 java.lang.Integer getSellerId()
          Give the user id of the seller
 java.lang.String getSellerNickname()
          Get the seller's nickname by finding the Bean corresponding to the user.
 java.lang.String getStartDate()
          Start date of the auction in the format 'YYYY-MM-DD hh:mm:ss'
 boolean isModified()
          Returns true if the beans has been modified.
 java.lang.String printItem()
          Display item information as an HTML table row
 java.lang.String printItemDescriptionToBuyNow(int userId)
          Display item information for the Buy Now servlet
 java.lang.String printItemUserHasBidOn(float bidMaxBid)
          Display item information for the AboutMe servlet
 java.lang.String printSell()
          Display item information as an HTML table row
 java.lang.String printUserBoughtItem(int qty)
          Display item information for the AboutMe servlet
 java.lang.String printUserWonItem()
          Display item information for the AboutMe servlet
 void setBuyNow(float newBuyNow)
          Set a new Buy Now price for the item
 void setCategoryId(java.lang.Integer id)
          Set a new category identifier.
 void setDescription(java.lang.String newDescription)
          Set a new item description
 void setEndDate(java.lang.String newDate)
          Set a new ending date for the auction
 void setEntityContext(javax.ejb.EntityContext context)
          Sets the associated entity context.
 void setInitialPrice(float newInitialPrice)
          Set a new initial price for the item
 void setMaxBid(float newMaxBid)
          Set item maximum bid.
 void setName(java.lang.String newName)
          Set a new item name
 void setNbOfBids(int newNbOfBids)
          Set the number of bids for this item
 void setQuantity(int qty)
          Set a new item quantity
 void setReservePrice(float newReservePrice)
          Set a new reserve price for the item
 void setSellerId(java.lang.Integer id)
          Set a new seller identifier.
 void setStartDate(java.lang.String newDate)
          Set a new beginning date for the auction
 void unsetEntityContext()
          Unsets the associated entity context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

id

public java.lang.Integer id

name

public java.lang.String name

description

public java.lang.String description

initialPrice

public float initialPrice

quantity

public int quantity

reservePrice

public float reservePrice

buyNow

public float buyNow

nbOfBids

public int nbOfBids

maxBid

public float maxBid

startDate

public java.lang.String startDate

endDate

public java.lang.String endDate

sellerId

public java.lang.Integer sellerId

categoryId

public java.lang.Integer categoryId
Constructor Detail

ItemBean

public ItemBean()
Method Detail

getId

public java.lang.Integer getId()
                        throws java.rmi.RemoteException
Get item id.
Returns:
item id
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

getName

public java.lang.String getName()
                         throws java.rmi.RemoteException
Get item name. This description is usually a short description of the item.
Returns:
item name
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

getDescription

public java.lang.String getDescription()
                                throws java.rmi.RemoteException
Get item description . This is usually an HTML file describing the item.
Returns:
item description
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

getInitialPrice

public float getInitialPrice()
                      throws java.rmi.RemoteException
Get item initial price set by the seller.
Returns:
item initial price
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

getQuantity

public int getQuantity()
                throws java.rmi.RemoteException
Get how many of this item are to be sold.
Returns:
item quantity
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

getReservePrice

public float getReservePrice()
                      throws java.rmi.RemoteException
Get item reserve price set by the seller. The seller can refuse to sell if reserve price is not reached.
Returns:
item reserve price
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

getBuyNow

public float getBuyNow()
                throws java.rmi.RemoteException
Get item Buy Now price set by the seller. A user can directly by the item at this price (no auction).
Returns:
item Buy Now price
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

getMaxBid

public float getMaxBid()
                throws java.rmi.RemoteException
Get item maximum bid (if any) for this item. This value should be the same as doing
SELECT MAX(bid) FROM bids WHERE item_id=?
Returns:
current maximum bid or 0 if no bid
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.1

getNbOfBids

public int getNbOfBids()
                throws java.rmi.RemoteException
Get number of bids for this item. This value should be the same as doing
SELECT COUNT(*) FROM bids WHERE item_id=?
Returns:
number of bids
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.1

getStartDate

public java.lang.String getStartDate()
                              throws java.rmi.RemoteException
Start date of the auction in the format 'YYYY-MM-DD hh:mm:ss'
Returns:
start date of the auction
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

getEndDate

public java.lang.String getEndDate()
                            throws java.rmi.RemoteException
End date of the auction in the format 'YYYY-MM-DD hh:mm:ss'
Returns:
end date of the auction
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

getSellerId

public java.lang.Integer getSellerId()
                              throws java.rmi.RemoteException
Give the user id of the seller
Returns:
seller's user id
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

getCategoryId

public java.lang.Integer getCategoryId()
                                throws java.rmi.RemoteException
Give the category id of the item
Returns:
item's category id
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

getSellerNickname

public java.lang.String getSellerNickname()
                                   throws java.rmi.RemoteException
Get the seller's nickname by finding the Bean corresponding to the user.
Returns:
nickname
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

getCategoryName

public java.lang.String getCategoryName()
                                 throws java.rmi.RemoteException
Get the category name by finding the Bean corresponding to the category Id.
Returns:
category name
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

setName

public void setName(java.lang.String newName)
             throws java.rmi.RemoteException
Set a new item name
Parameters:
newName - item name
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

setDescription

public void setDescription(java.lang.String newDescription)
                    throws java.rmi.RemoteException
Set a new item description
Parameters:
newDescription - item description
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

setInitialPrice

public void setInitialPrice(float newInitialPrice)
                     throws java.rmi.RemoteException
Set a new initial price for the item
Parameters:
newInitialPrice - item initial price
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

setQuantity

public void setQuantity(int qty)
                 throws java.rmi.RemoteException
Set a new item quantity
Parameters:
qty - item quantity
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

setReservePrice

public void setReservePrice(float newReservePrice)
                     throws java.rmi.RemoteException
Set a new reserve price for the item
Parameters:
newReservePrice - item reserve price
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

setBuyNow

public void setBuyNow(float newBuyNow)
               throws java.rmi.RemoteException
Set a new Buy Now price for the item
Parameters:
newBuyNow - item Buy Now price
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

setMaxBid

public void setMaxBid(float newMaxBid)
               throws java.rmi.RemoteException
Set item maximum bid. This function checks if newMaxBid is greater than current maxBid and only updates the value in this case.
Parameters:
newMaxBid - new maximum bid
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.1

setNbOfBids

public void setNbOfBids(int newNbOfBids)
                 throws java.rmi.RemoteException
Set the number of bids for this item
Parameters:
newNbOfBids - new number of bids
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.1

addOneBid

public void addOneBid()
               throws java.rmi.RemoteException
Add one bid for this item
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.1

setStartDate

public void setStartDate(java.lang.String newDate)
                  throws java.rmi.RemoteException
Set a new beginning date for the auction
Parameters:
newDate - auction new beginning date
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

setEndDate

public void setEndDate(java.lang.String newDate)
                throws java.rmi.RemoteException
Set a new ending date for the auction
Parameters:
newDate - auction new ending date
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

setSellerId

public void setSellerId(java.lang.Integer id)
                 throws java.rmi.RemoteException
Set a new seller identifier. This id must match the primary key of the users table.
Parameters:
id - seller id
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

setCategoryId

public void setCategoryId(java.lang.Integer id)
                   throws java.rmi.RemoteException
Set a new category identifier. This id must match the primary key of the category table.
Parameters:
id - category id
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

ejbCreate

public ItemPK ejbCreate(java.lang.String itemName,
                        java.lang.String itemDescription,
                        float itemInitialPrice,
                        int itemQuantity,
                        float itemReservePrice,
                        float itemBuyNow,
                        int duration,
                        java.lang.Integer itemSellerId,
                        java.lang.Integer itemCategoryId)
                 throws javax.ejb.CreateException,
                        java.rmi.RemoteException,
                        javax.ejb.RemoveException
This method is used to create a new Item Bean.
Parameters:
itemName - short item designation
itemDescription - long item description, usually an HTML file
itemInitialPrice - initial price fixed by the seller
itemQuantity - number to sell (of this item)
itemReservePrice - reserve price (minimum price the seller really wants to sell)
itemBuyNow - price if a user wants to buy the item immediatly
duration - duration of the auction in days (start date is when the method is called and end date is computed according to the duration)
itemSellerId - seller id, must match the primary key of table users
itemCategoryId - category id, must match the primary key of table categories
Returns:
pk primary key set to null
Throws:
javax.ejb.CreateException - if an error occurs
java.rmi.RemoteException - if an error occurs
javax.ejb.RemoveException - if an error occurs
Since:
1.0

ejbPostCreate

public void ejbPostCreate(java.lang.String itemName,
                          java.lang.String itemDescription,
                          float itemInitialPrice,
                          int itemQuantity,
                          float itemReservePrice,
                          float itemBuyNow,
                          int duration,
                          java.lang.Integer itemSellerId,
                          java.lang.Integer itemCategoryId)
This method does currently nothing

ejbActivate

public void ejbActivate()
                 throws java.rmi.RemoteException
This method is empty because persistence is managed by the container
Specified by:
ejbActivate in interface javax.ejb.EntityBean

ejbPassivate

public void ejbPassivate()
                  throws java.rmi.RemoteException
This method is empty because persistence is managed by the container
Specified by:
ejbPassivate in interface javax.ejb.EntityBean

ejbRemove

public void ejbRemove()
               throws java.rmi.RemoteException,
                      javax.ejb.RemoveException
This method is empty because persistence is managed by the container
Specified by:
ejbRemove in interface javax.ejb.EntityBean

ejbStore

public void ejbStore()
              throws java.rmi.RemoteException
Persistence is managed by the container and the bean becomes up to date
Specified by:
ejbStore in interface javax.ejb.EntityBean

ejbLoad

public void ejbLoad()
             throws java.rmi.RemoteException
Persistence is managed by the container and the bean becomes up to date
Specified by:
ejbLoad in interface javax.ejb.EntityBean

setEntityContext

public void setEntityContext(javax.ejb.EntityContext context)
                      throws java.rmi.RemoteException
Sets the associated entity context. The container invokes this method on an instance after the instance has been created. This method is called in an unspecified transaction context.
Specified by:
setEntityContext in interface javax.ejb.EntityBean
Parameters:
context - An EntityContext interface for the instance. The instance should store the reference to the context in an instance variable.
Throws:
javax.ejb.EJBException - Thrown by the method to indicate a failure caused by a system-level error.
java.rmi.RemoteException - - This exception is defined in the method signature to provide backward compatibility for enterprise beans written for the EJB 1.0 specification. Enterprise beans written for the EJB 1.1 and higher specification should throw the javax.ejb.EJBException instead of this exception.

unsetEntityContext

public void unsetEntityContext()
                        throws java.rmi.RemoteException
Unsets the associated entity context. The container calls this method before removing the instance. This is the last method that the container invokes on the instance. The Java garbage collector will eventually invoke the finalize() method on the instance. This method is called in an unspecified transaction context.
Specified by:
unsetEntityContext in interface javax.ejb.EntityBean
Throws:
javax.ejb.EJBException - Thrown by the method to indicate a failure caused by a system-level error.
java.rmi.RemoteException - - This exception is defined in the method signature to provide backward compatibility for enterprise beans written for the EJB 1.0 specification. Enterprise beans written for the EJB 1.1 and higher specification should throw the javax.ejb.EJBException instead of this exception.

isModified

public boolean isModified()
Returns true if the beans has been modified. It prevents the EJB server from reloading a bean that has not been modified.
Returns:
a boolean value

printItem

public java.lang.String printItem()
                           throws java.rmi.RemoteException
Display item information as an HTML table row
Returns:
a String containing HTML code
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

printUserBoughtItem

public java.lang.String printUserBoughtItem(int qty)
                                     throws java.rmi.RemoteException
Display item information for the AboutMe servlet
Returns:
a String containing HTML code
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

printItemUserHasBidOn

public java.lang.String printItemUserHasBidOn(float bidMaxBid)
                                       throws java.rmi.RemoteException
Display item information for the AboutMe servlet
Returns:
a String containing HTML code (Warning last link must be completed by servlet)
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

printSell

public java.lang.String printSell()
                           throws java.rmi.RemoteException
Display item information as an HTML table row
Returns:
a String containing HTML code
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

printUserWonItem

public java.lang.String printUserWonItem()
                                  throws java.rmi.RemoteException
Display item information for the AboutMe servlet
Returns:
a String containing HTML code
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0

printItemDescriptionToBuyNow

public java.lang.String printItemDescriptionToBuyNow(int userId)
                                              throws java.rmi.RemoteException
Display item information for the Buy Now servlet
Returns:
a String containing HTML code
Throws:
java.rmi.RemoteException - if an error occurs
Since:
1.0


Copyright © 2003 - ObjectWeb Consortium - All Rights Reserved.