BaseSaveCustomerActionpublic abstract class BaseSaveCustomerAction extends xpetstore.web.webwork.action.BaseAction implements webwork.action.ServletResponseAware
Fields Summary |
---|
protected xpetstore.domain.Customer | _customer | private HttpServletResponse | _response |
Methods Summary |
---|
protected java.lang.String | 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 void | 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.Customer | getCustomer()
return _customer;
| public abstract void | save(xpetstore.domain.Customer customer, cirrus.hibernate.Session session)
| public void | setCustomer(xpetstore.domain.Customer customer)Sets the customer.
_customer = customer;
| public void | setServletResponse(javax.servlet.http.HttpServletResponse response)
_response = response;
|
|