SponsorDaoBase.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.athlete;
- 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>Sponsor</code>.
- * </p>
- *
- * @see SponsorDao
- */
- @TransactionAttribute(TransactionAttributeType.REQUIRED)
- @Local({SponsorDao.class})
- public abstract class SponsorDaoBase
- implements SponsorDao
- {
- /** 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 SponsorDao#load
- */
- @Override
- public Object load(final int transform, final Long sponsorId)
- throws SponsorDaoException
- {
- if (sponsorId == null)
- {
- throw new IllegalArgumentException(
- "Sponsor.load - 'sponsorId' can not be null");
- }
- try
- {
- final Sponsor entity = this.emanager.find(Sponsor.class, sponsorId);
- return transformEntity(transform, entity);
- }
- catch (Exception ex)
- {
- throw new SponsorDaoException(ex);
- }
- }
- /**
- * @see SponsorDao#load( Long)
- */
- @Override
- public Sponsor load( final Long sponsorId)
- throws SponsorDaoException
- {
- return (Sponsor)this.load(TRANSFORM_NONE, sponsorId);
- }
- /**
- * @see SponsorDao#loadAll()
- */
- @Override
- @SuppressWarnings({"unchecked"})
- public Collection<Sponsor> loadAll()
- throws SponsorDaoException
- {
- return this.loadAll(TRANSFORM_NONE);
- }
- /**
- * @see SponsorDao#loadAll(int)
- */
- @Override
- public Collection loadAll(final int transform)
- throws SponsorDaoException
- {
- try
- {
- TypedQuery<Sponsor> query = this.emanager.createNamedQuery("Sponsor.findAll", Sponsor.class);
- List<Sponsor> results = query.getResultList();
- this.transformEntities(transform, results);
- return results;
- }
- catch (Exception ex)
- {
- throw new SponsorDaoException(ex);
- }
- }
- /**
- * Create Sponsor with no VO transformation
- * @see SponsorDao#create(Sponsor)
- */
- @Override
- public Sponsor create(Sponsor sponsor)
- throws SponsorDaoException
- {
- return (Sponsor)this.create(TRANSFORM_NONE, sponsor);
- }
- /**
- * Create Sponsor with VO transformation
- * @see SponsorDao#create(int, Sponsor)
- */
- @Override
- public Object create(final int transform, final Sponsor sponsor)
- throws SponsorDaoException
- {
- if (sponsor == null)
- {
- throw new IllegalArgumentException(
- "Sponsor.create - 'sponsor' can not be null");
- }
- try
- {
- this.emanager.persist(sponsor);
- this.emanager.flush();
- return this.transformEntity(transform, sponsor);
- }
- catch (Exception ex)
- {
- throw new SponsorDaoException(ex);
- }
- }
- /**
- * Create a Collection of Sponsor with no VO transformation
- * @see SponsorDao#create(Collection)
- */
- @Override
- @SuppressWarnings({"unchecked"})
- public Collection<Sponsor> create(final Collection<Sponsor> entities)
- throws SponsorDaoException
- {
- return create(TRANSFORM_NONE, entities);
- }
- /**
- * Create a Collection of Sponsor with VO transformation
- * @see SponsorDao#create(int, Collection)
- */
- @Override
- @SuppressWarnings({"unchecked", "rawtypes"})
- public Collection create(final int transform, final Collection<Sponsor> entities)
- throws SponsorDaoException
- {
- if (entities == null)
- {
- throw new IllegalArgumentException(
- "Sponsor.create - 'entities' can not be null");
- }
- Collection results = new ArrayList();
- try
- {
- for (final Sponsor entity : entities)
- {
- results.add(create(transform, entity));
- }
- }
- catch (Exception ex)
- {
- throw new SponsorDaoException(ex);
- }
- return results;
- }
- /**
- * Create Entity Sponsor using instance attributes with no VO transformation
- * @see SponsorDao#create(int, String)
- */
- @Override
- public Sponsor create(
- int code,
- String name)
- throws SponsorDaoException
- {
- return (Sponsor)this.create(TRANSFORM_NONE, code, name);
- }
- /**
- * Create Entity Sponsor using instance attributes with VO transformation
- * @see SponsorDao#create(int, int, String)
- * composite=false identifiers=1
- */
- @Override
- public Object create(
- final int transform,
- int code,
- String name)
- throws SponsorDaoException
- {
- Sponsor entity = new Sponsor();
- entity.setCode(code);
- entity.setName(name);
- return this.create(transform, entity);
- }
- /**
- * Create Entity Sponsor using required properties with no VO transformation
- * @see SponsorDao#create(int, GrantInfo, String, TrackAthlete)
- */
- @Override
- public Sponsor create(
- int code,
- Set<GrantInfo> grantInfos,
- String name,
- TrackAthlete trackAthlete)
- throws SponsorDaoException
- {
- return (Sponsor)this.create(TRANSFORM_NONE, code, grantInfos, name, trackAthlete);
- }
- /**
- * Create Entity Sponsor using required properties with VO transformation
- * @see SponsorDao#create(int, int, GrantInfo, String, TrackAthlete)
- */
- @Override
- public Object create(
- final int transform,
- int code,
- Set<GrantInfo> grantInfos,
- String name,
- TrackAthlete trackAthlete)
- throws SponsorDaoException
- {
- Sponsor entity = new Sponsor();
- // code $propertyType.fullyQualifiedName identifier=$propertyType.identifier false
- entity.setCode(code);
- // grantInfos $propertyType.fullyQualifiedName identifier=$propertyType.identifier false
- entity.setGrantInfos(grantInfos);
- // name $propertyType.fullyQualifiedName identifier=$propertyType.identifier false
- entity.setName(name);
- // trackAthlete $propertyType.fullyQualifiedName identifier=$propertyType.identifier false
- entity.setTrackAthlete(trackAthlete);
- return this.create(transform, entity);
- }
- /**
- * @see SponsorDao#update(Sponsor)
- */
- @Override
- public void update(Sponsor sponsor)
- throws SponsorDaoException
- {
- if (sponsor == null)
- {
- throw new IllegalArgumentException(
- "Sponsor.update - 'sponsor' can not be null");
- }
- try
- {
- this.emanager.merge(sponsor);
- this.emanager.flush();
- }
- catch (Exception ex)
- {
- throw new SponsorDaoException(ex);
- }
- }
- /**
- * @see SponsorDao#update(Collection)
- */
- @Override
- public void update(final Collection<Sponsor> entities)
- throws SponsorDaoException
- {
- if (entities == null)
- {
- throw new IllegalArgumentException(
- "Sponsor.update - 'entities' can not be null");
- }
- try
- {
- for (final Sponsor entity : entities)
- {
- update(entity);
- }
- }
- catch (Exception ex)
- {
- throw new SponsorDaoException(ex);
- }
- }
- /**
- * @see SponsorDao#remove(Sponsor)
- */
- @Override
- public void remove(Sponsor sponsor)
- throws SponsorDaoException
- {
- if (sponsor == null)
- {
- throw new IllegalArgumentException(
- "Sponsor.remove - 'sponsor' can not be null");
- }
- try
- {
- this.emanager.remove(sponsor);
- this.emanager.flush();
- }
- catch (Exception ex)
- {
- throw new SponsorDaoException(ex);
- }
- }
- /**
- * @see SponsorDao#remove(Long)
- */
- @Override
- public void remove(Long sponsorId)
- throws SponsorDaoException
- {
- if (sponsorId == null)
- {
- throw new IllegalArgumentException(
- "Sponsor.remove - 'sponsorId' can not be null");
- }
- try
- {
- final Sponsor entity = this.load(sponsorId);
- if (entity != null)
- {
- this.remove(entity);
- }
- }
- catch (Exception ex)
- {
- throw new SponsorDaoException(ex);
- }
- }
- /**
- * @see SponsorDao#remove(Collection)
- */
- @Override
- public void remove(Collection<Sponsor> entities)
- throws SponsorDaoException
- {
- if (entities == null)
- {
- throw new IllegalArgumentException(
- "Sponsor.remove - 'entities' can not be null");
- }
- try
- {
- for (final Sponsor entity : entities)
- {
- remove(entity);
- }
- }
- catch (Exception ex)
- {
- throw new SponsorDaoException(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>SponsorDao</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 SponsorDao}
- * @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 Sponsor 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, Sponsor)}
- * 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>SponsorDao</code>
- * @param entities the collection of entities to transform
- * @see #transformEntity(int, Sponsor)
- */
- protected void transformEntities(final int transform, final Collection<Sponsor> 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;
- }
- }