FileDocCategorySizeDatePackage
ProcessPaymentBean.javaAPI DocExample3903Fri Dec 17 12:02:36 GMT 1999com.titan.processpayment

ProcessPaymentBean

public class ProcessPaymentBean extends Object implements javax.ejb.SessionBean

Fields Summary
public static final String
CASH
public static final String
CREDIT
public static final String
CHECK
public javax.ejb.SessionContext
context
Constructors Summary
Methods Summary
public booleanbyCash(Customer customer, double amount)

        return process(getCustomerID(customer),amount,
                       CASH,null,-1,-1,null);
    
public booleanbyCheck(Customer customer, Check check, double amount)

        int minCheckNumber = getMinCheckNumber();
        if (check.checkNumber > minCheckNumber){
            return process(getCustomerID(customer), amount, CHECK, 
                           check.checkBarCode,check.checkNumber,-1,null);
        }
        else {
           throw new PaymentException(
              "Check number is too low. Must be at least "+minCheckNumber);
        }
    
public booleanbyCredit(Customer customer, CreditCard card, double amount)

        if (card.expiration.before(new java.util.Date())){
             throw new PaymentException("Expiration date has passed");
        }
        else {
            return process(getCustomerID(customer), amount, CREDIT, null,
                           -1, card.number,
                           new java.sql.Date(card.expiration.getTime()));
        }
    
public voidejbActivate()

public voidejbCreate()


      
    
public voidejbPassivate()

public voidejbRemove()

private java.sql.ConnectiongetConnection()

        return DriverManager.getConnection(
        context.getEnvironment().getProperty("jdbcURL"));
    
private intgetCustomerID(Customer customer)

        return ((CustomerPK)customer.getPrimaryKey()).id;
    
private intgetMinCheckNumber()

        String min_check_string = context.getEnvironment().getProperty("minCheckNumber");
        return Integer.parseInt(min_check_string);
    
private booleanprocess(long customerID, double amount, java.lang.String type, java.lang.String checkBarCode, int checkNumber, long creditNumber, java.sql.Date creditExpDate)


        Connection con = null;
        
        PreparedStatement ps = null;
        ResultSet rslt = null;
        try {
            con = getConnection();
            ps = con.prepareStatement
                ("INSERT INTO payment (customer_id, amount, type,"+ 
                  "check_bar_code,check_number,credit_number,"+
                  "credit_exp_date) VALUES (?,?,?,?,?,?,?)");
            ps.setLong(1,customerID);
            ps.setDouble(2,amount);
            ps.setString(3,type);
            ps.setString(4,checkBarCode);
            ps.setInt(5,checkNumber);
            ps.setLong(6,creditNumber);
            ps.setDate(7,creditExpDate);
            int retVal = ps.executeUpdate();
            if (retVal!=1){
                throw new RemoteException("Payment insert failed");
            }
            
            return true;
        } catch(SQLException sql){
             throw new RemoteException("",sql);
        } finally {
             try {
                 if (rslt != null) rslt.close();
                 if (ps != null) ps.close();
                 if (con!= null) con.close();
             } catch(SQLException se){se.printStackTrace();}
        }
    
public voidsetSessionContext(javax.ejb.SessionContext ctx)

        context = ctx;