BioDaoBase.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 java.util.Set;
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>Bio</code>.
* </p>
*
* @see BioDao
*/
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@Local({BioDao.class})
public abstract class BioDaoBase
implements BioDao
{
/** 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 BioDao#load
*/
@Override
public Object load(final int transform, final Long bioId)
throws BioDaoException
{
if (bioId == null)
{
throw new IllegalArgumentException(
"Bio.load - 'bioId' can not be null");
}
try
{
final Bio entity = this.emanager.find(Bio.class, bioId);
return transformEntity(transform, entity);
}
catch (Exception ex)
{
throw new BioDaoException(ex);
}
}
/**
* @see BioDao#load( Long)
*/
@Override
public Bio load( final Long bioId)
throws BioDaoException
{
return (Bio)this.load(TRANSFORM_NONE, bioId);
}
/**
* @see BioDao#loadAll()
*/
@Override
@SuppressWarnings({"unchecked"})
public Collection<Bio> loadAll()
throws BioDaoException
{
return this.loadAll(TRANSFORM_NONE);
}
/**
* @see BioDao#loadAll(int)
*/
@Override
public Collection loadAll(final int transform)
throws BioDaoException
{
try
{
TypedQuery<Bio> query = this.emanager.createNamedQuery("Bio.findAll", Bio.class);
List<Bio> results = query.getResultList();
this.transformEntities(transform, results);
return results;
}
catch (Exception ex)
{
throw new BioDaoException(ex);
}
}
/**
* Create Bio with no VO transformation
* @see BioDao#create(Bio)
*/
@Override
public Bio create(Bio bio)
throws BioDaoException
{
return (Bio)this.create(TRANSFORM_NONE, bio);
}
/**
* Create Bio with VO transformation
* @see BioDao#create(int, Bio)
*/
@Override
public Object create(final int transform, final Bio bio)
throws BioDaoException
{
if (bio == null)
{
throw new IllegalArgumentException(
"Bio.create - 'bio' can not be null");
}
try
{
this.emanager.persist(bio);
this.emanager.flush();
return this.transformEntity(transform, bio);
}
catch (Exception ex)
{
throw new BioDaoException(ex);
}
}
/**
* Create a Collection of Bio with no VO transformation
* @see BioDao#create(Collection)
*/
@Override
@SuppressWarnings({"unchecked"})
public Collection<Bio> create(final Collection<Bio> entities)
throws BioDaoException
{
return create(TRANSFORM_NONE, entities);
}
/**
* Create a Collection of Bio with VO transformation
* @see BioDao#create(int, Collection)
*/
@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public Collection create(final int transform, final Collection<Bio> entities)
throws BioDaoException
{
if (entities == null)
{
throw new IllegalArgumentException(
"Bio.create - 'entities' can not be null");
}
Collection results = new ArrayList();
try
{
for (final Bio entity : entities)
{
results.add(create(transform, entity));
}
}
catch (Exception ex)
{
throw new BioDaoException(ex);
}
return results;
}
/**
* Create Entity Bio using instance attributes with no VO transformation
* @see BioDao#create(String, String, byte[], String)
*/
@Override
public Bio create(
String name,
String info,
byte[] picture,
char[] advert)
throws BioDaoException
{
return (Bio)this.create(TRANSFORM_NONE, name, info, picture, advert);
}
/**
* Create Entity Bio using instance attributes with VO transformation
* @see BioDao#create(int, String, String, byte[], String)
* composite=false identifiers=1
*/
@Override
public Object create(
final int transform,
String name,
String info,
byte[] picture,
char[] advert)
throws BioDaoException
{
Bio entity = new Bio();
entity.setName(name);
entity.setInfo(info);
entity.setPicture(picture);
entity.setAdvert(advert);
return this.create(transform, entity);
}
/**
* Create Entity Bio using required properties with no VO transformation
* @see BioDao#create(String, BioReference, String, String, byte[])
*/
@Override
public Bio create(
char[] advert,
Set<BioReference> bioReferences,
String info,
String name,
byte[] picture)
throws BioDaoException
{
return (Bio)this.create(TRANSFORM_NONE, advert, bioReferences, info, name, picture);
}
/**
* Create Entity Bio using required properties with VO transformation
* @see BioDao#create(int, String, BioReference, String, String, byte[])
*/
@Override
public Object create(
final int transform,
char[] advert,
Set<BioReference> bioReferences,
String info,
String name,
byte[] picture)
throws BioDaoException
{
Bio entity = new Bio();
// advert $propertyType.fullyQualifiedName identifier=$propertyType.identifier false
entity.setAdvert(advert);
// bioReferences $propertyType.fullyQualifiedName identifier=$propertyType.identifier false
entity.setBioReferences(bioReferences);
// info $propertyType.fullyQualifiedName identifier=$propertyType.identifier false
entity.setInfo(info);
// name $propertyType.fullyQualifiedName identifier=$propertyType.identifier false
entity.setName(name);
// picture $propertyType.fullyQualifiedName identifier=$propertyType.identifier false
entity.setPicture(picture);
return this.create(transform, entity);
}
/**
* @see BioDao#update(Bio)
*/
@Override
public void update(Bio bio)
throws BioDaoException
{
if (bio == null)
{
throw new IllegalArgumentException(
"Bio.update - 'bio' can not be null");
}
try
{
this.emanager.merge(bio);
this.emanager.flush();
}
catch (Exception ex)
{
throw new BioDaoException(ex);
}
}
/**
* @see BioDao#update(Collection)
*/
@Override
public void update(final Collection<Bio> entities)
throws BioDaoException
{
if (entities == null)
{
throw new IllegalArgumentException(
"Bio.update - 'entities' can not be null");
}
try
{
for (final Bio entity : entities)
{
update(entity);
}
}
catch (Exception ex)
{
throw new BioDaoException(ex);
}
}
/**
* @see BioDao#remove(Bio)
*/
@Override
public void remove(Bio bio)
throws BioDaoException
{
if (bio == null)
{
throw new IllegalArgumentException(
"Bio.remove - 'bio' can not be null");
}
try
{
this.emanager.remove(bio);
this.emanager.flush();
}
catch (Exception ex)
{
throw new BioDaoException(ex);
}
}
/**
* @see BioDao#remove(Long)
*/
@Override
public void remove(Long bioId)
throws BioDaoException
{
if (bioId == null)
{
throw new IllegalArgumentException(
"Bio.remove - 'bioId' can not be null");
}
try
{
final Bio entity = this.load(bioId);
if (entity != null)
{
this.remove(entity);
}
}
catch (Exception ex)
{
throw new BioDaoException(ex);
}
}
/**
* @see BioDao#remove(Collection)
*/
@Override
public void remove(Collection<Bio> entities)
throws BioDaoException
{
if (entities == null)
{
throw new IllegalArgumentException(
"Bio.remove - 'entities' can not be null");
}
try
{
for (final Bio entity : entities)
{
remove(entity);
}
}
catch (Exception ex)
{
throw new BioDaoException(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>BioDao</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 BioDao}
* @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 Bio 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, Bio)}
* 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>BioDao</code>
* @param entities the collection of entities to transform
* @see #transformEntity(int, Bio)
*/
protected void transformEntities(final int transform, final Collection<Bio> 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;
}
}