FileDocCategorySizeDatePackage
BaseSaveCustomerAction.javaAPI DocJBoss 4.2.14275Fri Jul 13 20:55:40 BST 2007xpetstore.web.webwork.action.customer

BaseSaveCustomerAction

public abstract class BaseSaveCustomerAction extends xpetstore.web.webwork.action.BaseAction implements webwork.action.ServletResponseAware
author
Herve Tchepannou

Fields Summary
protected xpetstore.domain.Customer
_customer
private HttpServletResponse
_response
Constructors Summary
Methods Summary
protected java.lang.StringdoExecute()

see
webwork.action.ActionSupport#doExecute()


    //~ Methods ----------------------------------------------------------------

           
        
         
    
        Transaction tx = null;
        Session     s = getHibernateSession(  );
        String      customerId = _customer.getUserId(  );

        try
        {
            tx = s.beginTransaction(  );

            /* Make sure that the user-id is unique */
            try
            {
                Customer c = ( Customer ) s.load( Customer.class, customerId );

                if ( !c.getUserId(  ).equalsIgnoreCase( _customer.getUserId(  ) ) )
                {
                    addError( "customer", getText( "duplicate_account" ) );

                    return ERROR;
                }
            }
            catch ( ObjectNotFoundException o ) {}

            /* Make sure that the email is unique */
            String     oql = "FROM cst IN CLASS " + Customer.class + " WHERE cst.email=?";
            Collection col = s.find( oql, _customer.getEmail(  ), Hibernate.STRING );

            if ( col.size(  ) > 0 )
            {
                Customer c = ( Customer ) col.iterator(  ).next(  );

                if ( !c.getUserId(  ).equalsIgnoreCase( customerId ) )
                {
                    addError( "customer", getText( "duplicate_email" ) );

                    return ERROR;
                }
            }

            save( _customer, s );
            tx.commit(  );

            return SUCCESS;
        }
        catch ( Exception e )
        {
            _log.error( "Unexpected error", e );

            if ( tx != null )
            {
                tx.rollback(  );
            }

            throw e;
        }
        finally
        {
            s.close(  );
        }
    
protected voiddoValidation()

see
webwork.action.ActionSupport#doValidation()

        System.out.println( getClass(  ).getName(  ) + ".doValidation()" );

        /* Account */
        Account account = _customer.getAccount(  );
        checkLength( "customerId", "userId_length", account.getUserId(  ), 4 );
        checkLength( "password", "password_length", account.getPassword(  ), 4 );

        /* Email */
        checkNotEmpty( "email", "email_required", _customer.getEmail(  ) );

        /* Credit card */
        CreditCard cc = _customer.getCreditCard(  );
        checkNotEmpty( "ccEmail", "ccType_required", cc.getType(  ) );
        checkNotEmpty( "ccNumber", "ccNumber_required", cc.getNumber(  ) );
        checkNotEmpty( "ccExpiryDate", "ccExpiryDate_required", cc.getExpiryDate(  ) );

        super.doValidation(  );
    
public xpetstore.domain.CustomergetCustomer()

return
Customer

        return _customer;
    
public abstract voidsave(xpetstore.domain.Customer customer, cirrus.hibernate.Session session)

public voidsetCustomer(xpetstore.domain.Customer customer)
Sets the customer.

param
customer The customer to set

        _customer = customer;
    
public voidsetServletResponse(javax.servlet.http.HttpServletResponse response)

see
webwork.action.ServletResponseAware#setServletResponse(javax.servlet.http.HttpServletResponse)

        _response = response;