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