FileDocCategorySizeDatePackage
Customer.javaAPI DocExample4181Fri Jul 18 21:04:52 BST 1997bank.server

Customer

public class Customer extends imaginary.persist.Persistent implements RemoteCustomer
This class is the business object that represents a bank customer.

Fields Summary
private static final CustomerPeer
peer
private AccountSet
accounts
private String
first_name
private String
last_name
Constructors Summary
public Customer()
Constructs a new Customer.


             
        
        super();
    
Methods Summary
public synchronized RemoteAccountSetgetAccountSet()

return
the AccountSet of accounts for this customer

        return accounts;
    
public RemoteAccount[]getAccounts()
Each customer has one or more accounts stored in an account set. This method provides those accounts in an array format.

return
an array of customer accounts

        // getPersistents() is all the synchronization we need
        RemotePersistent[] obs = accounts.getPersistents();
        RemoteAccount[] accts = new RemoteAccount[obs.length];

        // This trick is needed to make a Persistent[] an Account[]
        for(int i=0; i<obs.length; i++) {
            accts[i] = (RemoteAccount)obs[i];
        }
        return accts;
    
public synchronized java.lang.StringgetFirstName()

return
the customer's first name

        return first_name;
    
public synchronized java.lang.StringgetLastName()

return
the customer's last name

        return last_name;
    
protected synchronized imaginary.persist.PersistentPeergetPersistentPeer()

return
this object's PersistentPeer

        return Customer.peer;
    
public synchronized voidrestore(imaginary.persist.Transaction trans, java.util.Hashtable data)
The Customer implementation of the Persistent interface's restore() method. This takes a Hashtable of values and assigns them to attributes in the Customer object.

param
trans the Transaction being used for the restore
param
data the Hashtable of data pulled from the data store
exception
imaginary.persist.PersistenceException An error occurred restoring the Customer

        Hashtable hash = new Hashtable();

        /*
         * Depending on your data store and table structure, the
         * Hashtable may have different keys
         */
        // Set the ID
        setId(((Integer)data.get(CustomerPeer.CUST_ID)).intValue());
        // Set the last name
        last_name = (String)data.get(CustomerPeer.LAST_NAME);
        // Set the first name
        first_name = (String)data.get(CustomerPeer.FIRST_NAME);
        // Create an account set
        try {
            accounts = new AccountSet();
        }
        catch( RemoteException e ) {
            throw new PersistenceException(e);
        }
        // Create a Hashtable that tells the AccountSet what customer ID
        // to use for restoring the accounts
        hash.put("cust_id", new Integer(getId()));
        // Restore all accounts for this customer
        accounts.restore(trans, hash);
    
public synchronized voidsetId(java.util.Hashtable h)
The Persistent interface mandates that implementors provide a setId(Hashtable) method that pulls the ID out of a Hashtable and calls setId(int).

param
h a Hashtable of values from the data store
see
imaginary.persist.Persistent#setId

        // CustomerPeer defines the key for cust_id in the data store
        setId(((Integer)h.get(CustomerPeer.CUST_ID)).intValue());