OrderInfoDaoBase.java

// license-header java merge-point
//
// Attention: Generated code! Do not modify by hand!
// Generated by DaoBase.vsl in andromda-ejb3-cartridge on 08/08/2014 12:21:06.
//
package org.andromda.demo.ejb3.order;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.annotation.Resource;
import javax.ejb.Local;
import javax.ejb.SessionContext;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import org.hibernate.Session;

/**
 * <p>
 * Base EJB3 DAO Class: is able to create, update, remove, load, and find
 * objects of type <code>OrderInfo</code>.
 * </p>
 *
 * @see OrderInfoDao
 */
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@Local({OrderInfoDao.class})
public abstract class OrderInfoDaoBase
    implements OrderInfoDao
{
    /** Session Context Injection */
    @Resource
    protected SessionContext context;

    /**
     * Inject persistence context demo-ejb3
     */
    @PersistenceContext(unitName = "demo-ejb3")
    protected EntityManager emanager;

    /**
     * Inject Hibernate Session
     */
    @PersistenceContext(unitName = "demo-ejb3")
    protected Session hibernateSession;

    /**
     * @see OrderInfoDao#load
     */
    @Override
    public Object load(final int transform, final Long id)
        throws OrderInfoDaoException
    {
        if (id == null)
        {
            throw new IllegalArgumentException(
                "OrderInfo.load - 'id' can not be null");
        }
        try
        {
            final OrderInfo entity = this.emanager.find(OrderInfo.class, id);
            return transformEntity(transform, entity);
        }
        catch (Exception ex)
        {
            throw new OrderInfoDaoException(ex);
        }
    }

    /**
     * @see OrderInfoDao#load( Long)
     */
    @Override
    public OrderInfo load( final Long id)
        throws OrderInfoDaoException
    {
        return (OrderInfo)this.load(TRANSFORM_NONE, id);
    }

    /**
     * @see OrderInfoDao#loadAll()
     */
    @Override
    @SuppressWarnings({"unchecked"})
    public Collection<OrderInfo> loadAll()
        throws OrderInfoDaoException
    {
        return this.loadAll(TRANSFORM_NONE);
    }

    /**
     * @see OrderInfoDao#loadAll(int)
     */
    @Override
    public Collection loadAll(final int transform)
        throws OrderInfoDaoException
    {
        try
        {
            TypedQuery<OrderInfo> query = this.emanager.createNamedQuery("OrderInfo.findAll", OrderInfo.class);
            List<OrderInfo> results = query.getResultList();
            this.transformEntities(transform, results);
            return results;
        }
        catch (Exception ex)
        {
            throw new OrderInfoDaoException(ex);
        }
    }

    /**
     * Create OrderInfo with no VO transformation
     * @see OrderInfoDao#create(OrderInfo)
     */
    @Override
    public OrderInfo create(OrderInfo orderInfo)
        throws OrderInfoDaoException
    {
        return (OrderInfo)this.create(TRANSFORM_NONE, orderInfo);
    }

    /**
     * Create OrderInfo with VO transformation
     * @see OrderInfoDao#create(int, OrderInfo)
     */
    @Override
    public Object create(final int transform, final OrderInfo orderInfo)
        throws OrderInfoDaoException
    {
        if (orderInfo == null)
        {
            throw new IllegalArgumentException(
                "OrderInfo.create - 'orderInfo' can not be null");
        }

        try
        {
            this.emanager.persist(orderInfo);
            this.emanager.flush();
            return this.transformEntity(transform, orderInfo);
        }
        catch (Exception ex)
        {
            throw new OrderInfoDaoException(ex);
        }
    }

    /**
     * Create a Collection of OrderInfo with no VO transformation
     * @see OrderInfoDao#create(Collection)
     */
    @Override
    @SuppressWarnings({"unchecked"})
    public Collection<OrderInfo> create(final Collection<OrderInfo> entities)
        throws OrderInfoDaoException
    {
        return create(TRANSFORM_NONE, entities);
    }

    /**
     * Create a Collection of OrderInfo with VO transformation
     * @see OrderInfoDao#create(int, Collection)
     */
    @Override
    @SuppressWarnings({"unchecked", "rawtypes"})
    public Collection create(final int transform, final Collection<OrderInfo> entities)
        throws OrderInfoDaoException
    {
        if (entities == null)
        {
            throw new IllegalArgumentException(
                "OrderInfo.create - 'entities' can not be null");
        }
        Collection results = new ArrayList();
        try
        {
            for (final OrderInfo entity : entities)
            {
                results.add(create(transform, entity));
            }
        }
        catch (Exception ex)
        {
            throw new OrderInfoDaoException(ex);
        }
        return results;
    }

    /**
     * Create Entity OrderInfo using instance attributes with no VO transformation
     * @see OrderInfoDao#create(String, int)
     */
    @Override
    public OrderInfo create(
        String description,
        int volume)
        throws OrderInfoDaoException
    {
        return (OrderInfo)this.create(TRANSFORM_NONE, description, volume);
    }

    /**
     * Create Entity OrderInfo using instance attributes with VO transformation
     * @see OrderInfoDao#create(int, String, int)
     * composite=false identifiers=1
     */
    @Override
    public Object create(
        final int transform,
        String description,
        int volume)
        throws OrderInfoDaoException
    {
        OrderInfo entity = new OrderInfo();
        entity.setDescription(description);
        entity.setVolume(volume);
        return this.create(transform, entity);
    }

    /**
     * @see OrderInfoDao#update(OrderInfo)
     */
    @Override
    public void update(OrderInfo orderInfo)
        throws OrderInfoDaoException
    {
        if (orderInfo == null)
        {
            throw new IllegalArgumentException(
                "OrderInfo.update - 'orderInfo' can not be null");
        }
        try
        {
            this.emanager.merge(orderInfo);
            this.emanager.flush();
        }
        catch (Exception ex)
        {
            throw new OrderInfoDaoException(ex);
        }
    }

    /**
     * @see OrderInfoDao#update(Collection)
     */
    @Override
    public void update(final Collection<OrderInfo> entities)
        throws OrderInfoDaoException
    {
        if (entities == null)
        {
            throw new IllegalArgumentException(
                "OrderInfo.update - 'entities' can not be null");
        }
        try
        {
            for (final OrderInfo entity : entities)
            {
                update(entity);
            }
        }
        catch (Exception ex)
        {
            throw new OrderInfoDaoException(ex);
        }
    }

    /**
     * @see OrderInfoDao#remove(OrderInfo)
     */
    @Override
    public void remove(OrderInfo orderInfo)
        throws OrderInfoDaoException
    {
        if (orderInfo == null)
        {
            throw new IllegalArgumentException(
                "OrderInfo.remove - 'orderInfo' can not be null");
        }
        try
        {
            this.emanager.remove(orderInfo);
            this.emanager.flush();
        }
        catch (Exception ex)
        {
            throw new OrderInfoDaoException(ex);
        }
    }

    /**
     * @see OrderInfoDao#remove(Long)
     */
    @Override
    public void remove(Long id)
        throws OrderInfoDaoException
    {
        if (id == null)
        {
            throw new IllegalArgumentException(
                "OrderInfo.remove - 'id' can not be null");
        }
        try
        {
            final OrderInfo entity = this.load(id);
            if (entity != null)
            {
                this.remove(entity);
            }
        }
        catch (Exception ex)
        {
            throw new OrderInfoDaoException(ex);
        }
    }

    /**
     * @see OrderInfoDao#remove(Collection)
     */
    @Override
    public void remove(Collection<OrderInfo> entities)
        throws OrderInfoDaoException
    {
        if (entities == null)
        {
            throw new IllegalArgumentException(
                "OrderInfo.remove - 'entities' can not be null");
        }
        try
        {
            for (final OrderInfo entity : entities)
            {
                remove(entity);
            }
        }
        catch (Exception ex)
        {
            throw new OrderInfoDaoException(ex);
        }
    }

    /**
     * @see OrderInfoDao#findAllByIndex(int)
     */
    @Override
    public Collection findAllByIndex(int index)
        throws OrderInfoDaoException
    {
        return this.findAllByIndex(TRANSFORM_NONE, index);
    }

    /**
     * @see OrderInfoDao#findAllByIndex(String, int)
     */
    @Override
    public Collection findAllByIndex(final String queryString, final int index)
        throws OrderInfoDaoException
    {
        return this.findAllByIndex(TRANSFORM_NONE, queryString, index);
    }

    /**
     * @see OrderInfoDao#findAllByIndex(int, int)
     */
    @Override
    public List findAllByIndex(final int transform, final int index)
        throws OrderInfoDaoException
    {
        try
        {
            TypedQuery<OrderInfo> queryObject = this.emanager.createNamedQuery("OrderInfo.findAllByIndex", OrderInfo.class);
            queryObject.setFirstResult(index);
            List results = queryObject.getResultList();
            transformEntities(transform, results);
            return results;
        }
        catch (Exception ex)
        {
            throw new OrderInfoDaoException(ex);
        }
    }

    /**
     * @see OrderInfoDao#findAllByIndex(int, String, int)
     */
    @Override
    public List findAllByIndex(final int transform, final String queryString, final int index)
        throws OrderInfoDaoException
    {
        try
        {
            TypedQuery<OrderInfo> queryObject = this.emanager.createQuery(queryString, OrderInfo.class);
            queryObject.setFirstResult(index);
            List results = queryObject.getResultList();
            transformEntities(transform, results);
            return results;
        }
        catch (Exception ex)
        {
            throw new OrderInfoDaoException(ex);
        }
    }

    /**
     * @see OrderInfoDao#findAllWithLimits(int, int)
     */
    @Override
    public Collection findAllWithLimits(int index, int max)
        throws OrderInfoDaoException
    {
        return this.findAllWithLimits(TRANSFORM_NONE, index, max);
    }

    /**
     * @see OrderInfoDao#findAllWithLimits(String, int, int)
     */
    @Override
    public Collection findAllWithLimits(final String queryString, final int index, final int max)
        throws OrderInfoDaoException
    {
        return this.findAllWithLimits(TRANSFORM_NONE, queryString, index, max);
    }

    /**
     * @see OrderInfoDao#findAllWithLimits(int, int, int)
     */
    @Override
    public List findAllWithLimits(final int transform, final int index, final int max)
        throws OrderInfoDaoException
    {
        try
        {
            TypedQuery<OrderInfo> queryObject = this.emanager.createNamedQuery("OrderInfo.findAllWithLimits", OrderInfo.class);
            queryObject.setFirstResult(index);
            queryObject.setMaxResults(max);
            List results = queryObject.getResultList();
            transformEntities(transform, results);
            return results;
        }
        catch (Exception ex)
        {
            throw new OrderInfoDaoException(ex);
        }
    }

    /**
     * @see OrderInfoDao#findAllWithLimits(int, String, int, int)
     */
    @Override
    public List findAllWithLimits(final int transform, final String queryString, final int index, final int max)
        throws OrderInfoDaoException
    {
        try
        {
            TypedQuery<OrderInfo> queryObject = this.emanager.createQuery(queryString, OrderInfo.class);
            queryObject.setFirstResult(index);
            queryObject.setMaxResults(max);
            List results = queryObject.getResultList();
            transformEntities(transform, results);
            return results;
        }
        catch (Exception ex)
        {
            throw new OrderInfoDaoException(ex);
        }
    }

    /**
     * Allows transformation of entities into value objects
     * (or something else for that matter), when the <code>transform</code>
     * flag is set to one of the constants defined in <code>OrderInfoDao</code>, please note
     * that the {@link #TRANSFORM_NONE} constant denotes no transformation, so the entity itself
     * will be returned.
     *
     * If the integer argument value is unknown {@link #TRANSFORM_NONE} is assumed.
     *
     * @param transform one of the constants declared in {@link OrderInfoDao}
     * @param entity an entity that was found
     * @return the transformed entity (i.e. new value object, etc)
     * @see #transformEntities(int,Collection)
     */
    protected Object transformEntity(final int transform, final OrderInfo entity)
    {
        Object target = null;
        if (entity != null)
        {
            switch (transform)
            {
                case TRANSFORM_NONE : // fall-through
                default:
                    target = entity;
            }
        }
        return target;
    }

    /**
     * Transforms a collection of entities using the
     * {@link #transformEntity(int, OrderInfo)}
     * method. This method does not instantiate a new collection.
     * <p/>
     * Transforms into the same collection as the argument, but this time containing the transformed entities
     * This method is to be used internally only.
     *
     * @param transform one of the constants declared in <code>OrderInfoDao</code>
     * @param entities the collection of entities to transform
     * @see #transformEntity(int, OrderInfo)
     */
    protected void transformEntities(final int transform, final Collection<OrderInfo> entities)
    {
        switch (transform)
        {
            case TRANSFORM_NONE : // fall-through
                default:
                // do nothing;
        }
    }


    // For unit testing outside of container - persistence context not injected
    /**
     * @return the context
     */
    public SessionContext getContext()
    {
        return this.context;
    }

    /**
     * @param contextIn the context to set
     */
    public void setContext(SessionContext contextIn)
    {
        this.context = contextIn;
    }

    /**
     * @return the emanager
     */
    public EntityManager getEmanager()
    {
        return this.emanager;
    }

    /**
     * @param emanagerIn the emanager to set
     */
    public void setEmanager(EntityManager emanagerIn)
    {
        this.emanager = emanagerIn;
    }

    /**
     * @return the hibernateSession
     */
    public Session getHibernateSession()
    {
        return this.hibernateSession;
    }

    /**
     * @param hibernateSessionIn the hibernateSession to set
     */
    public void setHibernateSession(Session hibernateSessionIn)
    {
        this.hibernateSession = hibernateSessionIn;
    }
}