FileDocCategorySizeDatePackage
AccountSetPeer.javaAPI DocExample1928Sun Mar 02 21:30:20 GMT 1997bank.server

AccountSetPeer

public class AccountSetPeer extends imaginary.persist.DatabaseSetPeer
The AccountSetPeer provides the runtime class name for the accounts it is responsible for as well as the SQL for restoring them.

Fields Summary
Constructors Summary
Methods Summary
public java.lang.StringgetPersistentClass(java.util.Hashtable h)
Depending on the account type for the account being restored, this method will return either "CheckingAccount" or "SavingsAccount".

param
h the values from the database
return
the class name to instantiate for this row

        String tmp = (String)h.get("t_accounts.account_type");

        if( tmp.equals("C") ) {
            return "bank.server.CheckingAccount";
        }
        else {
            return "bank.server.SavingsAccount";
        }
    
public java.lang.StringgetSql(java.util.Hashtable h)
Provides the proper SQL SELECT statement based on the values that come from a database row stored in the Hashtable. If the Hashtable is null, then all accounts are retrieved. If a customer ID is passed, then all accounts for that customer ID are provided.

param
h a Hashtable containing the customer ID
return
the SELECT SQL to get the accounts from the database with

        if( h == null ) { // If no query criteria are specified
            return "SELECT * from t_accounts";
        }
        else {
            String tmp = "SELECT * from t_accounts WHERE ";
            int cust_id = -1;

            // SELECT * from t_accounts
            // WHERE cust_id = 1
            if( h.containsKey("cust_id") ) {
                cust_id = ((Integer)h.get("cust_id")).intValue();
            }
            return tmp + "cust_id = " + cust_id;
        }