Java Reference
In-Depth Information
public
double getPrice(
long
code){
Item it
#
dbm.getItem(code);
if
(it
##
null
)
return
-1;
return
it.price;
}
public long
startTransaction(
long
customer,
long
employee)
throws
Exception {
return
dbm.startTransaction(customer, employee);
}
public
void buy(
long
item,
long
quantity,
long
transaction)
throws
Exception {
dbm.buy(item,quantity,transaction);
}
public
void endTransaction(
long
transaction)
throws
Exception {
dbm.closeTransaction(transaction);
}
}
The interface
DBManager
defines the operations offered by a database. It
is similar to the
Market
interface but is more data oriented.
package
MarketDB;
public interface
DBManager {
// return information about an employee
Employee getEmployee(
long
code);
// return information about a customer
Customer getCustomer(
long
code);
// return information about a product
Item getItem(
long
code);
// start a new transaction and return its code
long
startTransaction(
long
customer,
long
employee)
throws
Exception;
// record the acquisition of a product
// in a transaction
void
buy(
long
item,
long
quantity,
long
transaction)
throws
Exception;
// close a transaction
void
endTransaction(
long
code)
throws
Exception;
}
The information stored in the database is handled through four data
classes:
Item
,
Customer
,
Employee
,
Transaction
. These classes hold information
in public attributes.
package
MarketDB;
public class
Item {