Project 1b: Entity EJBs
This is the second step of the Project.
In this step you will create a database schema and some entity beans.
Due:
19 April 2005.
The Entities
Recall our goal is a distributed Internet gambling site.
In our model,
customers place wagers on the outcome of events.
Each of these three italicized terms
corresponds to a real-world entity,
hence to an EJB class you will implement.
As you will see, our model is quite simple
compared to a real gambling operation.
Customers
A customer
is logically just an entity that can place wagers.
A customer can pay money to your site,
and your site can pay money to a customer.
The customer has attributes:
- A (perhaps fictitious) customer name for display purposes.
- An account nuumber at the Bank.
(The Bank is an external site with a Web Services
interface. It will appear in later parts of this project.)
- A credit limit,
the maximum amount of outstanding wagers you (the gambling site)
are willing to let the customer make.
You may also want to store state like
- The outstanding wagers
this customer has placed on future events.
Presumably the site will enforce a policy like
outstanding wagers may never exceed credit limit.
Events
An event in our system is a 2-participant winner-take-all contest
that takes place atomically at some specified time.
Customers can place wagers on the (future) outcome of an event,
as described below.
Minimally, an event has attributes:
- A description, a human-readable string.
- The time when the event will take place.
Eventually you will probably need to store additional state like
- The total amount that has been wagered on the event;
- The total payout if the first participant wins;
- The total payout if the second participant wins;
- Current odds for first participant (e.g. the amount returned
on a $1 wager if the first participant wins);
- Current odds for second participant.
Some of this state could in principle be computed as an aggregate
over all the outstanding wagers (see below),
but for efficiency and scalability reasons that would not be a
really good idea.
Wagers
A wager is, well, a wager. What can I say?
It has attributes
- The event and participant for the wager,
- The amount of the wager,
- The payout if the chosen participant wins.
Note that the total amount wagered on an event
and the total payout for each possible outcome of the event
could be computed by summing over all the outstanding wagers on that event,
if you had unbounded computing capacity.
EJBs and Database Schema
In this part of the project
you will implement EJBs for each of the above entities.
The EJBs will be maintained persistently in your MS SQL Server database.
At this point you have to make a choice for your EJB implementation:
- You can use container-managed persistence (CMP) for your Entity EJBs.
In this case the code to load and store entities from/to the database
is generated automatically for you;
but your database schema is pretty strictly determined by the
structure of the EJBs.
- Alternatively, you can use bean-managed persistence (BMP) for your Entity EJBs.
In this case you can design your database schema more-or-less
arbitrarily,
but you have to write your own SQL to load and store the entities.
At this point you can make either choice.
But before the project is done
you will have to do at least some programming
using BMP.
What To Build
For this part of the Project,
extend the web site you built in Part a as follows.
-
Implement Entity EJBs for the entities described above.
-
Populate your database with at least one customer and at least two events.
(You can do this directly using the SQL Server tools -- EM or QA -- rather than
writing client code to do this).
-
Write a simple form-based web page that
displays the customer's current wagers
and allows her to place an additional wager.
Use a Session EJB to help with this.
(Would a stateful Session EJB be useful here?)
There is no need to worry about login/authentication (yet).
What to Submit
Create a .zip
archive called proj1b.zip
containing the following:
- the source files of your EJBs and deployment descriptors
- your database schema and contents
(these can be screen shots from MS QU or EM).
- two screen shots of your web page
showing the result of adding a wager.
Submit the zip file to
CMS
by the due date.
As in Part a, the due date is not a big deal –
we are going to look at these, but not grade them,
and I'll set CMS to accept submissions forever.
Please do submit this, however.