Methods Summary |
---|
public synchronized void | deposit(imaginary.persist.RemoteLockHolder h, float amount)Deposits the specified amount of money into the account.
// will throw a LockException if another lock is held
modify(h);
if( amount < 0 ) {
throw new AccountException("Deposits may not be negative.");
}
balance += amount;
|
public synchronized java.lang.String | getAccountType()The account type can be "S" for savings and "C" for checking.
return type;
|
public synchronized float | getBalance()The account balance is how much money is currently in the account
return balance;
|
public synchronized RemoteCustomer | getCustomer()
return customer;
|
public synchronized int | getCustomerId()The customer ID is an attribute that unique identifies the owning
customer.
return customer.getId();
|
protected synchronized imaginary.persist.PersistentPeer | getPersistentPeer()Implementation of the Persistent method that specifies what
PersistentPeer to use for data store operations.
return Account.peer;
|
public synchronized void | restore(imaginary.persist.Transaction t, java.util.Hashtable h)Implementation of the Persistent method for filling in
object attributes based on a Hashtable of values from
a data store.
Integer i = (Integer)h.get("t_accounts.account_id");
Float f = (Float)h.get("t_accounts.balance");
setId(i.intValue()); // Set the ID
i = (Integer)h.get("t_accounts.cust_id");
// Get the customer object for this account
customer =
(Customer)Persistent.getPersistent(t, i.intValue(),
"bank.server.Customer");
// Set the account type
type = (String)h.get("t_accounts.account_type");
// Set the balance
balance = f.floatValue();
|
public synchronized void | setId(java.util.Hashtable h)Implementation of the Persistent method setId(Hashtable).
Allows this object to pick the account ID out of a Hashtable
and set the ID using that value.
setId(((Integer)h.get("t_accounts.account_id")).intValue());
|
public synchronized void | transfer(imaginary.persist.RemoteLockHolder h, float amount, RemoteAccount acct)Transfers the specified amount of money from this account to another
This is done as a withdraw from this account followed by a
deposit into the remote account.
float current_balance = getBalance();
try {
withdraw(h, amount);
acct.deposit(h, amount);
}
catch( AccountException e ) {
balance = current_balance; // restore the balance here!
throw e;
}
catch( LockException e ) {
balance = current_balance; // restore the balance here!
throw e;
}
catch( RemoteException e ) {
balance = current_balance; // you know the routine
throw e;
}
|
public synchronized void | withdraw(imaginary.persist.RemoteLockHolder h, float amount)Withdraws the specified amount of money from the account.
This method places no restrictions on what may or may not be
withdrawn (negative balances allowed).
// will throw a LockException if another lock is held
modify(h);
if( amount < 0 ) {
throw new AccountException("Attempt to withdraw a negative " +
"amount of money.");
}
balance -= amount;
|