FileDocCategorySizeDatePackage
ProcessPaymentBean.javaAPI DocExample4501Sun Mar 10 17:27:26 GMT 2002com.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(CustomerRemote customer, double amount)

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

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

        if (card.expiration.before(new java.util.Date())) {
            System.out.println("Expiration date has passed");
           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()

		try {
			InitialContext jndiCntx = new InitialContext();
			DataSource ds = (DataSource)
				jndiCntx.lookup("java:comp/env/jdbc/Titan");
			return ds.getConnection();
		} catch(NamingException ne){throw new EJBException(ne);}
	
private java.lang.IntegergetCustomerID(CustomerRemote customer)

        try {
            return (Integer)customer.getPrimaryKey();
        } catch(RemoteException re) {
            throw new EJBException(re);
        }
    
private intgetMinCheckNumber()

		try {
			InitialContext jndiCntx = new InitialContext( );
			Integer value = (Integer)
				jndiCntx.lookup("java:comp/env/minCheckNumber");
			return value.intValue();
		} catch(NamingException ne){throw new EJBException(ne);}
	
private booleanprocess(java.lang.Integer customerID, double amount, java.lang.String type, java.lang.String checkBarCode, int checkNumber, java.lang.String creditNumber, java.sql.Date creditExpDate)


		System.out.println("process() with customerID="+customerID+" amount="+amount);
        Connection con = null;
        PreparedStatement ps = null;

        try {
            con = getConnection();
            System.out.println("Obtained Connection");
            ps = con.prepareStatement
             ("INSERT INTO \"PaymentBeanTable\" (\"_customer_id\", \"amount\", \"type\", \"checkBarCode\", \"checkNumber\", \"creditNumber\", \"creditExpDate\")"+
                  " VALUES (?,?,?,?,?,?,?)");
            ps.setInt(1,customerID.intValue());
            ps.setDouble(2,amount);
            ps.setString(3,type);
            ps.setString(4,checkBarCode);
            ps.setInt(5,checkNumber);
            ps.setString(6,creditNumber);
            ps.setDate(7,creditExpDate);
            int retVal = ps.executeUpdate();
            System.out.println("Execute on the PaymentBeanTable");
            if (retVal!=1) {
                throw new EJBException("Payment insert failed");
            }         
            return true;
        } catch(SQLException sql) {
            throw new EJBException(sql);
        } finally {
             try {
                 if (ps != null) ps.close();
                 if (con!= null) con.close();
             } catch(SQLException se){se.printStackTrace();}
        }
    
public voidsetSessionContext(javax.ejb.SessionContext ctx)

        context = ctx;