Package cirrus.hibernate

Examples of cirrus.hibernate.Transaction


     */
    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
View Full Code Here


     * @see webwork.action.ActionSupport#doExecute()
     */
    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
View Full Code Here

                                  URL    url,
                                  String description,
                                  User   user )
    {
        Session     session = null;
        Transaction tx = null;

        try
        {
            session = _sessionFactory.openSession(  );

            BookmarkImpl bk = new BookmarkImpl( null, title, url.toString(), description, user );

            tx = session.beginTransaction(  );
            session.save( bk );
            tx.commit(  );

            return bk.getId(  );
        }
        catch ( HibernateException e )
        {
View Full Code Here

                                URL    url,
                                String description )
        throws ObjectNotFoundException
    {
        Session     session = null;
        Transaction tx = null;

        try
        {
            session = _sessionFactory.openSession(  );

            BookmarkImpl bk = ( BookmarkImpl ) session.load( BookmarkImpl.class, id );
            bk.setTitle( title );
            bk.setUrl( url.toString() );
            bk.setDescription( description );

            tx = session.beginTransaction(  );
            session.update( bk );
            tx.commit(  );
        }
        catch( cirrus.hibernate.ObjectNotFoundException o )
        {
            throw new ObjectNotFoundException( "Bookmark#" + id + " not found" );
        }
View Full Code Here

     * @see net.sf.jportlet.portlets.bookmark.BookmarkManager#deleteBookmarks(java.lang.String[])
     */
    public void deleteBookmarks( String ids[] )
    {
        Session     session = null;
        Transaction tx = null;

        try
        {
            session = _sessionFactory.openSession(  );

            tx = session.beginTransaction(  );
            for ( int i = 0; i < ids.length; i++ )
            {
                BookmarkImpl bk = ( BookmarkImpl ) session.load( BookmarkImpl.class, ids[ i ] );
                try
                {
                  session.delete( bk );
                }
                catch( ObjectDeletedException o )
                {
                  o.printStackTrace();
                }
            }

            tx.commit(  );
        }
        catch ( HibernateException e )
        {
            rollback( tx );
            throw new PersistenceException( e );
View Full Code Here

TOP

Related Classes of cirrus.hibernate.Transaction

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.