EmailTicketDaoBase.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>EmailTicket</code>.
* </p>
*
* @see EmailTicketDao
*/
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@Local({EmailTicketDao.class})
public abstract class EmailTicketDaoBase
implements EmailTicketDao
{
/** 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 EmailTicketDao#load
*/
@Override
public Object load(final int transform, final Integer id)
throws EmailTicketDaoException
{
if (id == null)
{
throw new IllegalArgumentException(
"EmailTicket.load - 'id' can not be null");
}
try
{
final EmailTicket entity = this.emanager.find(EmailTicket.class, id);
return transformEntity(transform, entity);
}
catch (Exception ex)
{
throw new EmailTicketDaoException(ex);
}
}
/**
* @see EmailTicketDao#load( Integer)
*/
@Override
public EmailTicket load( final Integer id)
throws EmailTicketDaoException
{
return (EmailTicket)this.load(TRANSFORM_NONE, id);
}
/**
* @see EmailTicketDao#loadAll()
*/
@Override
@SuppressWarnings({"unchecked"})
public Collection<EmailTicket> loadAll()
throws EmailTicketDaoException
{
return this.loadAll(TRANSFORM_NONE);
}
/**
* @see EmailTicketDao#loadAll(int)
*/
@Override
public Collection loadAll(final int transform)
throws EmailTicketDaoException
{
try
{
TypedQuery<EmailTicket> query = this.emanager.createNamedQuery("EmailTicket.findAll", EmailTicket.class);
List<EmailTicket> results = query.getResultList();
this.transformEntities(transform, results);
return results;
}
catch (Exception ex)
{
throw new EmailTicketDaoException(ex);
}
}
/**
* Create EmailTicket with no VO transformation
* @see EmailTicketDao#create(EmailTicket)
*/
@Override
public EmailTicket create(EmailTicket emailTicket)
throws EmailTicketDaoException
{
return (EmailTicket)this.create(TRANSFORM_NONE, emailTicket);
}
/**
* Create EmailTicket with VO transformation
* @see EmailTicketDao#create(int, EmailTicket)
*/
@Override
public Object create(final int transform, final EmailTicket emailTicket)
throws EmailTicketDaoException
{
if (emailTicket == null)
{
throw new IllegalArgumentException(
"EmailTicket.create - 'emailTicket' can not be null");
}
try
{
this.emanager.persist(emailTicket);
this.emanager.flush();
return this.transformEntity(transform, emailTicket);
}
catch (Exception ex)
{
throw new EmailTicketDaoException(ex);
}
}
/**
* Create a Collection of EmailTicket with no VO transformation
* @see EmailTicketDao#create(Collection)
*/
@Override
@SuppressWarnings({"unchecked"})
public Collection<EmailTicket> create(final Collection<EmailTicket> entities)
throws EmailTicketDaoException
{
return create(TRANSFORM_NONE, entities);
}
/**
* Create a Collection of EmailTicket with VO transformation
* @see EmailTicketDao#create(int, Collection)
*/
@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public Collection create(final int transform, final Collection<EmailTicket> entities)
throws EmailTicketDaoException
{
if (entities == null)
{
throw new IllegalArgumentException(
"EmailTicket.create - 'entities' can not be null");
}
Collection results = new ArrayList();
try
{
for (final EmailTicket entity : entities)
{
results.add(create(transform, entity));
}
}
catch (Exception ex)
{
throw new EmailTicketDaoException(ex);
}
return results;
}
/**
* Create Entity EmailTicket using instance attributes with no VO transformation
* @see EmailTicketDao#create(Date, String, String)
*/
@Override
public EmailTicket create(
Date emailed,
String event,
String type)
throws EmailTicketDaoException
{
return (EmailTicket)this.create(TRANSFORM_NONE, emailed, event, type);
}
/**
* Create Entity EmailTicket using instance attributes with VO transformation
* @see EmailTicketDao#create(int, Date, String, String)
* composite=false identifiers=1
*/
@Override
public Object create(
final int transform,
Date emailed,
String event,
String type)
throws EmailTicketDaoException
{
EmailTicket entity = new EmailTicket();
entity.setEmailed(emailed);
entity.setEvent(event);
entity.setType(type);
return this.create(transform, entity);
}
/**
* @see EmailTicketDao#update(EmailTicket)
*/
@Override
public void update(EmailTicket emailTicket)
throws EmailTicketDaoException
{
if (emailTicket == null)
{
throw new IllegalArgumentException(
"EmailTicket.update - 'emailTicket' can not be null");
}
try
{
this.emanager.merge(emailTicket);
this.emanager.flush();
}
catch (Exception ex)
{
throw new EmailTicketDaoException(ex);
}
}
/**
* @see EmailTicketDao#update(Collection)
*/
@Override
public void update(final Collection<EmailTicket> entities)
throws EmailTicketDaoException
{
if (entities == null)
{
throw new IllegalArgumentException(
"EmailTicket.update - 'entities' can not be null");
}
try
{
for (final EmailTicket entity : entities)
{
update(entity);
}
}
catch (Exception ex)
{
throw new EmailTicketDaoException(ex);
}
}
/**
* @see EmailTicketDao#remove(EmailTicket)
*/
@Override
public void remove(EmailTicket emailTicket)
throws EmailTicketDaoException
{
if (emailTicket == null)
{
throw new IllegalArgumentException(
"EmailTicket.remove - 'emailTicket' can not be null");
}
try
{
this.emanager.remove(emailTicket);
this.emanager.flush();
}
catch (Exception ex)
{
throw new EmailTicketDaoException(ex);
}
}
/**
* @see EmailTicketDao#remove(Integer)
*/
@Override
public void remove(Integer id)
throws EmailTicketDaoException
{
if (id == null)
{
throw new IllegalArgumentException(
"EmailTicket.remove - 'id' can not be null");
}
try
{
final EmailTicket entity = this.load(id);
if (entity != null)
{
this.remove(entity);
}
}
catch (Exception ex)
{
throw new EmailTicketDaoException(ex);
}
}
/**
* @see EmailTicketDao#remove(Collection)
*/
@Override
public void remove(Collection<EmailTicket> entities)
throws EmailTicketDaoException
{
if (entities == null)
{
throw new IllegalArgumentException(
"EmailTicket.remove - 'entities' can not be null");
}
try
{
for (final EmailTicket entity : entities)
{
remove(entity);
}
}
catch (Exception ex)
{
throw new EmailTicketDaoException(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>EmailTicketDao</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 EmailTicketDao}
* @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 EmailTicket 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, EmailTicket)}
* 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>EmailTicketDao</code>
* @param entities the collection of entities to transform
* @see #transformEntity(int, EmailTicket)
*/
protected void transformEntities(final int transform, final Collection<EmailTicket> 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;
}
}