Package cirrus.hibernate

Examples of cirrus.hibernate.Session


     * @see webwork.action.ActionSupport#doExecute()
     */
    protected String doExecute(  )
        throws Exception
    {
        Session     s = getHibernateSession(  );
        Transaction tx = null;

        try
        {
            tx = s.beginTransaction(  );

            /* Customer */
            Customer cst = ( Customer ) s.load( Customer.class, getUserId(  ) );

            /* Order + Items*/
            Order    order = new Order( cst );
            Map      cart = getCart(  );
            Iterator it = cart.keySet(  ).iterator(  );

            while ( it.hasNext(  ) )
            {
                String  itemId = ( String ) it.next(  );
                Item    item = ( Item ) s.load( Item.class, itemId );
                Integer quantity = ( Integer ) cart.get( itemId );
                order.add( item, quantity.intValue(  ) );
            }

            /* Save */
            s.save( order );
            tx.commit(  );

            /* Empty the cart */
            getCart(  ).clear(  );

            /* send the email */
            String subject = "[xpetstore] Order Confimation";
            String body = "Your order has been submitted.\nThe order number is: " + order.getOrderId(  );

            try
            {
                MailUtil.send( cst.getEmail(  ), subject, body );
            }
            catch ( Exception e )
            {
                _log.error( "Unexpected error while sending email", e );
            }

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

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

            throw e;
        }
        finally
        {
            s.close(  );
        }
    }
View Full Code Here


     * @see webwork.action.ActionSupport#doExecute()
     */
    protected String doExecute(  )
        throws Exception
    {
        Session s = getHibernateSession(  );

        try
        {
            _product = ( Product ) s.load( Product.class, _productId );

            /*
             * Since product.item is lazy loaded,
             * traverse the collection to load all the product to display
             */
            Iterator it = _product.getItems(  ).iterator(  );

            while ( it.hasNext(  ) )
            {
                Item i = ( Item ) it.next(  );
                i.getDescription(  );
            }

            return SUCCESS;
        }
        finally
        {
            s.close(  );
        }
    }
View Full Code Here

        if ( ( _keyword == null ) || ( _keyword.length(  ) == 0 ) )
        {
            return SUCCESS;
        }

        Session s = getHibernateSession(  );
        try
        {
            String oql = "FROM p IN CLASS " + Product.class + " WHERE" + " ( p.productId LIKE '%" + _keyword + "%' ) OR" + " ( p.name LIKE '%" + _keyword + "%' ) OR" + " ( p.description LIKE '%" + _keyword + "%' )";
            _products = s.find( oql );

            return SUCCESS;
        }
        finally
        {
            s.close(  );
        }
    }
View Full Code Here

     * @see webwork.action.ActionSupport#doExecute()
     */
    protected String doExecute(  )
        throws Exception
    {
        Session s = getHibernateSession(  );

        try
        {
            Customer c = ( Customer ) s.load( Customer.class, _userId );

            if ( c.getAccount(  ).matchPassword( _password ) )
            {
                initSession( c );

                /* Redirect */
                if ( ( _redirectUri != null ) && ( _redirectUri.length(  ) > 0 ) )
                {
                    _response.sendRedirect( _redirectUri );
                    return NONE;
                }

                /* Normal flow */
                return SUCCESS;
            }
            else
            {
                addError( "login", getText( "authentication_failed" ) );
                return ERROR;
            }
        }
        catch ( ObjectNotFoundException o )
        {
            addError( "login", getText( "authentication_failed" ) );

            return ERROR;
        }
        finally
        {
            s.close(  );
        }
    }
View Full Code Here

     * @see webwork.action.ActionSupport#doExecute()
     */
    protected String doExecute(  )
        throws Exception
    {
        Session s = getHibernateSession(  );

        try
        {
            _customer = ( Customer ) s.load( Customer.class, getUserId(  ) );

            return SUCCESS;
        }
        finally
        {
            s.close(  );
        }
    }
View Full Code Here

     * @see webwork.action.ActionSupport#doExecute()
     */
    protected String doExecute(  )
        throws Exception
    {
        Session s = getHibernateSession(  );

        try
        {
            _item = ( Item ) s.load( Item.class, _itemId );

            return SUCCESS;
        }
        finally
        {
            s.close(  );
        }
    }
View Full Code Here

     * @throws Exception
     */
    public Collection getCartItems(  )
        throws Exception
    {
        Session s = null;
        Map     cart = getCart(  );

        try
        {
            if ( _cartItems == null )
            {
                _cartItems = new ArrayList(  );

                if ( cart.size(  ) > 0 )
                {
                    s = getHibernateSession(  );

                    Iterator it = cart.keySet(  ).iterator(  );

                    while ( it.hasNext(  ) )
                    {
                        String  itemId = ( String ) it.next(  );
                        Integer quantity = ( Integer ) cart.get( itemId );
                        Item    item = ( Item ) s.load( Item.class, itemId );

                        _cartItems.add( new OrderItem( item, quantity.intValue(  ) ) );
                    }
                }
            }

            return _cartItems;
        }
        catch ( Exception e )
        {
            e.printStackTrace(  );
            throw e;
        }
        finally
        {
            if ( s != null )
            {
                s.close(  );
            }
        }
    }
View Full Code Here

     * @see webwork.action.ActionSupport#doExecute()
     */
    protected String doExecute(  )
        throws Exception
    {
        Session s = getHibernateSession(  );

        try
        {
            _category = ( Category ) s.load( Category.class, _categoryId );

            /*
             * Since category.product is lazy loaded,
             * traverse the collection to load all the product to display
             */
            Iterator it = _category.getProducts(  ).iterator(  );

            while ( it.hasNext(  ) )
            {
                Product p = ( Product ) it.next(  );
                p.getName(  );
            }

            return SUCCESS;
        }
        finally
        {
            s.close(  );
        }
    }
View Full Code Here

     * @see webwork.action.ActionSupport#doExecute()
     */
    protected String doExecute(  )
        throws Exception
    {
        Session s = getHibernateSession(  );

        try
        {
            _customer = ( Customer ) s.load( Customer.class, getUserId(  ) );

            return SUCCESS;
        }
        finally
        {
            s.close(  );
        }
    }
View Full Code Here

     */
    protected String doExecute(  )
        throws Exception
    {
        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(  );
        }
    }
View Full Code Here

TOP

Related Classes of cirrus.hibernate.Session

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.