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