ProfileDaoBase.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:07.
//
package org.andromda.demo.ejb3.registration;
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>Profile</code>.
* </p>
*
* @see ProfileDao
*/
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@Local({ProfileDao.class})
public abstract class ProfileDaoBase
implements ProfileDao
{
/** 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 ProfileDao#load
*/
@Override
public Object load(final int transform, final Long profileId)
throws ProfileDaoException
{
if (profileId == null)
{
throw new IllegalArgumentException(
"Profile.load - 'profileId' can not be null");
}
try
{
final Profile entity = this.emanager.find(Profile.class, profileId);
return transformEntity(transform, entity);
}
catch (Exception ex)
{
throw new ProfileDaoException(ex);
}
}
/**
* @see ProfileDao#load( Long)
*/
@Override
public Profile load( final Long profileId)
throws ProfileDaoException
{
return (Profile)this.load(TRANSFORM_NONE, profileId);
}
/**
* @see ProfileDao#loadAll()
*/
@Override
@SuppressWarnings({"unchecked"})
public Collection<Profile> loadAll()
throws ProfileDaoException
{
return this.loadAll(TRANSFORM_NONE);
}
/**
* @see ProfileDao#loadAll(int)
*/
@Override
public Collection loadAll(final int transform)
throws ProfileDaoException
{
try
{
TypedQuery<Profile> query = this.emanager.createNamedQuery("Profile.findAll", Profile.class);
List<Profile> results = query.getResultList();
this.transformEntities(transform, results);
return results;
}
catch (Exception ex)
{
throw new ProfileDaoException(ex);
}
}
/**
* Create Profile with no VO transformation
* @see ProfileDao#create(Profile)
*/
@Override
public Profile create(Profile profile)
throws ProfileDaoException
{
return (Profile)this.create(TRANSFORM_NONE, profile);
}
/**
* Create Profile with VO transformation
* @see ProfileDao#create(int, Profile)
*/
@Override
public Object create(final int transform, final Profile profile)
throws ProfileDaoException
{
if (profile == null)
{
throw new IllegalArgumentException(
"Profile.create - 'profile' can not be null");
}
try
{
this.emanager.persist(profile);
this.emanager.flush();
return this.transformEntity(transform, profile);
}
catch (Exception ex)
{
throw new ProfileDaoException(ex);
}
}
/**
* Create a Collection of Profile with no VO transformation
* @see ProfileDao#create(Collection)
*/
@Override
@SuppressWarnings({"unchecked"})
public Collection<Profile> create(final Collection<Profile> entities)
throws ProfileDaoException
{
return create(TRANSFORM_NONE, entities);
}
/**
* Create a Collection of Profile with VO transformation
* @see ProfileDao#create(int, Collection)
*/
@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public Collection create(final int transform, final Collection<Profile> entities)
throws ProfileDaoException
{
if (entities == null)
{
throw new IllegalArgumentException(
"Profile.create - 'entities' can not be null");
}
Collection results = new ArrayList();
try
{
for (final Profile entity : entities)
{
results.add(create(transform, entity));
}
}
catch (Exception ex)
{
throw new ProfileDaoException(ex);
}
return results;
}
/**
* Create Entity Profile using instance attributes with no VO transformation
* @see ProfileDao#create(String, String, String)
*/
@Override
public Profile create(
String code,
String name,
String description)
throws ProfileDaoException
{
return (Profile)this.create(TRANSFORM_NONE, code, name, description);
}
/**
* Create Entity Profile using instance attributes with VO transformation
* @see ProfileDao#create(int, String, String, String)
* composite=false identifiers=1
*/
@Override
public Object create(
final int transform,
String code,
String name,
String description)
throws ProfileDaoException
{
Profile entity = new Profile();
entity.setCode(code);
entity.setName(name);
entity.setDescription(description);
return this.create(transform, entity);
}
/**
* Create Entity Profile using required properties with no VO transformation
* @see ProfileDao#create(String, Registration)
*/
@Override
public Profile create(
String code,
Registration registration)
throws ProfileDaoException
{
return (Profile)this.create(TRANSFORM_NONE, code, registration);
}
/**
* Create Entity Profile using required properties with VO transformation
* @see ProfileDao#create(int, String, Registration)
*/
@Override
public Object create(
final int transform,
String code,
Registration registration)
throws ProfileDaoException
{
Profile entity = new Profile();
// code $propertyType.fullyQualifiedName identifier=$propertyType.identifier false
entity.setCode(code);
// registration $propertyType.fullyQualifiedName identifier=$propertyType.identifier false
entity.setRegistration(registration);
return this.create(transform, entity);
}
/**
* @see ProfileDao#update(Profile)
*/
@Override
public void update(Profile profile)
throws ProfileDaoException
{
if (profile == null)
{
throw new IllegalArgumentException(
"Profile.update - 'profile' can not be null");
}
try
{
this.emanager.merge(profile);
this.emanager.flush();
}
catch (Exception ex)
{
throw new ProfileDaoException(ex);
}
}
/**
* @see ProfileDao#update(Collection)
*/
@Override
public void update(final Collection<Profile> entities)
throws ProfileDaoException
{
if (entities == null)
{
throw new IllegalArgumentException(
"Profile.update - 'entities' can not be null");
}
try
{
for (final Profile entity : entities)
{
update(entity);
}
}
catch (Exception ex)
{
throw new ProfileDaoException(ex);
}
}
/**
* @see ProfileDao#remove(Profile)
*/
@Override
public void remove(Profile profile)
throws ProfileDaoException
{
if (profile == null)
{
throw new IllegalArgumentException(
"Profile.remove - 'profile' can not be null");
}
try
{
this.emanager.remove(profile);
this.emanager.flush();
}
catch (Exception ex)
{
throw new ProfileDaoException(ex);
}
}
/**
* @see ProfileDao#remove(Long)
*/
@Override
public void remove(Long profileId)
throws ProfileDaoException
{
if (profileId == null)
{
throw new IllegalArgumentException(
"Profile.remove - 'profileId' can not be null");
}
try
{
final Profile entity = this.load(profileId);
if (entity != null)
{
this.remove(entity);
}
}
catch (Exception ex)
{
throw new ProfileDaoException(ex);
}
}
/**
* @see ProfileDao#remove(Collection)
*/
@Override
public void remove(Collection<Profile> entities)
throws ProfileDaoException
{
if (entities == null)
{
throw new IllegalArgumentException(
"Profile.remove - 'entities' can not be null");
}
try
{
for (final Profile entity : entities)
{
remove(entity);
}
}
catch (Exception ex)
{
throw new ProfileDaoException(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>ProfileDao</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 ProfileDao}
* @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 Profile 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, Profile)}
* 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>ProfileDao</code>
* @param entities the collection of entities to transform
* @see #transformEntity(int, Profile)
*/
protected void transformEntities(final int transform, final Collection<Profile> 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;
}
}