FileDocCategorySizeDatePackage
CustomerPeer.javaAPI DocExample3253Sun Mar 02 21:42:02 GMT 1997bank.server

CustomerPeer

public class CustomerPeer extends imaginary.persist.DatabasePeer
The CustomerPeer handles database access for the Customer business object. The DatabasePeer that it extends specifically prescribes for it methods that allow it to create SQL statements.

Fields Summary
public static final String
CUST_ID
The column header for the customer ID field in the t_customer table
public static final String
FIRST_NAME
The column header for the last_name field in the t_customer table
public static final String
LAST_NAME
The column header for the last name field in the t_customer table
Constructors Summary
Methods Summary
protected java.lang.StringgetInsertSql(imaginary.persist.Persistent p)
Provides the SQL used to insert a customer object into the database.

param
p the Customer being inserted
return
the SQL to insert the customer


                                  
        
        Customer cust = (Customer)p;        // Cast it to a Customer
        int cust_id = cust.getId();         // The customer id
        String last = cust.getLastName();   // The last name
        String first = cust.getFirstName(); // The first name

        // INSERT INTO t_customer (cust_id, last_name, first_name)
        // VALUES (1, 'the Clown', 'Bozo')
        return "INSERT INTO t_customer (cust_id, last_name, first_name) " +
            "VALUES (" + cust_id + ", '" + last + "', '" + first +
            "')";
    
public java.lang.StringgetRemoveSql(imaginary.persist.Persistent p)
Provides the SQL used to delete a customer from the database

param
p the Customer being deleted
return
the SQL used to delete the customer

        // DELETE FROM t_customer WHERE cust_id = 1
        return "DELETE FROM t_customer WHERE cust_id = " + p.getId();
    
public java.lang.StringgetRestoreSql(imaginary.persist.Persistent p)
Provides the SQL used to restore a customer from the database

param
p the Customer being restored (only the ID field is filled in)
return
the SQL used to restore that customer

        // SELECT * from t_customer WHERE cust_id = 1
        return "SELECT * from t_customer WHERE cust_id = " +
            p.getId();
    
public java.lang.StringgetUpdateSql(imaginary.persist.Persistent p)
Provides the SQL used to update a customer in the database

param
p the Customer being updated
return
the SQL used to UPDATE that customer

        Customer cust = (Customer)p;             // Cast p to Customer
        int cust_id = cust.getId();              // Get the cust_id
        String last_name = cust.getLastName();   // Get the last name
        String first_name = cust.getFirstName(); // Get the first name

        // UPDATE t_customer
        // SET last_name  = 'the Clown',
        //     first_name = 'Bozo'
        // WHERE cust_id  = 1
        return "UPDATE t_customer " +
            "SET last_name = '" + last_name + "', " +
            "first_name = '" + first_name + "' " +
            "WHERE cust_id = " + cust_id;