PaperTicketDaoBase.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.ticket;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
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>PaperTicket</code>.
 * </p>
 *
 * @see PaperTicketDao
 */
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@Local({PaperTicketDao.class})
public abstract class PaperTicketDaoBase
    implements PaperTicketDao
{
    /** 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 PaperTicketDao#load
     */
    @Override
    public Object load(final int transform, final Integer id)
        throws PaperTicketDaoException
    {
        if (id == null)
        {
            throw new IllegalArgumentException(
                "PaperTicket.load - 'id' can not be null");
        }
        try
        {
            final PaperTicket entity = this.emanager.find(PaperTicket.class, id);
            return transformEntity(transform, entity);
        }
        catch (Exception ex)
        {
            throw new PaperTicketDaoException(ex);
        }
    }

    /**
     * @see PaperTicketDao#load( Integer)
     */
    @Override
    public PaperTicket load( final Integer id)
        throws PaperTicketDaoException
    {
        return (PaperTicket)this.load(TRANSFORM_NONE, id);
    }

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

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

    /**
     * Create PaperTicket with no VO transformation
     * @see PaperTicketDao#create(PaperTicket)
     */
    @Override
    public PaperTicket create(PaperTicket paperTicket)
        throws PaperTicketDaoException
    {
        return (PaperTicket)this.create(TRANSFORM_NONE, paperTicket);
    }

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

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

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

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

    /**
     * Create Entity PaperTicket using instance attributes with no VO transformation
     * @see PaperTicketDao#create(Date, long, String, String)
     */
    @Override
    public PaperTicket create(
        Date posted,
        long handlingFee,
        String event,
        String type)
        throws PaperTicketDaoException
    {
        return (PaperTicket)this.create(TRANSFORM_NONE, posted, handlingFee, event, type);
    }

    /**
     * Create Entity PaperTicket using instance attributes with VO transformation
     * @see PaperTicketDao#create(int, Date, long, String, String)
     * composite=false identifiers=1
     */
    @Override
    public Object create(
        final int transform,
        Date posted,
        long handlingFee,
        String event,
        String type)
        throws PaperTicketDaoException
    {
        PaperTicket entity = new PaperTicket();
        entity.setPosted(posted);
        entity.setHandlingFee(handlingFee);
        entity.setEvent(event);
        entity.setType(type);
        return this.create(transform, entity);
    }

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

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

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

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

    /**
     * @see PaperTicketDao#remove(Collection)
     */
    @Override
    public void remove(Collection<PaperTicket> entities)
        throws PaperTicketDaoException
    {
        if (entities == null)
        {
            throw new IllegalArgumentException(
                "PaperTicket.remove - 'entities' can not be null");
        }
        try
        {
            for (final PaperTicket entity : entities)
            {
                remove(entity);
            }
        }
        catch (Exception ex)
        {
            throw new PaperTicketDaoException(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>PaperTicketDao</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 PaperTicketDao}
     * @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 PaperTicket 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, PaperTicket)}
     * 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>PaperTicketDao</code>
     * @param entities the collection of entities to transform
     * @see #transformEntity(int, PaperTicket)
     */
    protected void transformEntities(final int transform, final Collection<PaperTicket> 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;
    }
}