SponsorDaoBase.java

  1. // license-header java merge-point
  2. //
  3. // Attention: Generated code! Do not modify by hand!
  4. // Generated by DaoBase.vsl in andromda-ejb3-cartridge on 08/08/2014 12:21:06.
  5. //
  6. package org.andromda.demo.ejb3.athlete;

  7. import java.util.ArrayList;
  8. import java.util.Collection;
  9. import java.util.List;
  10. import java.util.Set;
  11. import javax.annotation.Resource;
  12. import javax.ejb.Local;
  13. import javax.ejb.SessionContext;
  14. import javax.ejb.TransactionAttribute;
  15. import javax.ejb.TransactionAttributeType;
  16. import javax.persistence.EntityManager;
  17. import javax.persistence.PersistenceContext;
  18. import javax.persistence.TypedQuery;
  19. import org.hibernate.Session;

  20. /**
  21.  * <p>
  22.  * Base EJB3 DAO Class: is able to create, update, remove, load, and find
  23.  * objects of type <code>Sponsor</code>.
  24.  * </p>
  25.  *
  26.  * @see SponsorDao
  27.  */
  28. @TransactionAttribute(TransactionAttributeType.REQUIRED)
  29. @Local({SponsorDao.class})
  30. public abstract class SponsorDaoBase
  31.     implements SponsorDao
  32. {
  33.     /** Session Context Injection */
  34.     @Resource
  35.     protected SessionContext context;

  36.     /**
  37.      * Inject persistence context demo-ejb3
  38.      */
  39.     @PersistenceContext(unitName = "demo-ejb3")
  40.     protected EntityManager emanager;

  41.     /**
  42.      * Inject Hibernate Session
  43.      */
  44.     @PersistenceContext(unitName = "demo-ejb3")
  45.     protected Session hibernateSession;

  46.     /**
  47.      * @see SponsorDao#load
  48.      */
  49.     @Override
  50.     public Object load(final int transform, final Long sponsorId)
  51.         throws SponsorDaoException
  52.     {
  53.         if (sponsorId == null)
  54.         {
  55.             throw new IllegalArgumentException(
  56.                 "Sponsor.load - 'sponsorId' can not be null");
  57.         }
  58.         try
  59.         {
  60.             final Sponsor entity = this.emanager.find(Sponsor.class, sponsorId);
  61.             return transformEntity(transform, entity);
  62.         }
  63.         catch (Exception ex)
  64.         {
  65.             throw new SponsorDaoException(ex);
  66.         }
  67.     }

  68.     /**
  69.      * @see SponsorDao#load( Long)
  70.      */
  71.     @Override
  72.     public Sponsor load( final Long sponsorId)
  73.         throws SponsorDaoException
  74.     {
  75.         return (Sponsor)this.load(TRANSFORM_NONE, sponsorId);
  76.     }

  77.     /**
  78.      * @see SponsorDao#loadAll()
  79.      */
  80.     @Override
  81.     @SuppressWarnings({"unchecked"})
  82.     public Collection<Sponsor> loadAll()
  83.         throws SponsorDaoException
  84.     {
  85.         return this.loadAll(TRANSFORM_NONE);
  86.     }

  87.     /**
  88.      * @see SponsorDao#loadAll(int)
  89.      */
  90.     @Override
  91.     public Collection loadAll(final int transform)
  92.         throws SponsorDaoException
  93.     {
  94.         try
  95.         {
  96.             TypedQuery<Sponsor> query = this.emanager.createNamedQuery("Sponsor.findAll", Sponsor.class);
  97.             List<Sponsor> results = query.getResultList();
  98.             this.transformEntities(transform, results);
  99.             return results;
  100.         }
  101.         catch (Exception ex)
  102.         {
  103.             throw new SponsorDaoException(ex);
  104.         }
  105.     }

  106.     /**
  107.      * Create Sponsor with no VO transformation
  108.      * @see SponsorDao#create(Sponsor)
  109.      */
  110.     @Override
  111.     public Sponsor create(Sponsor sponsor)
  112.         throws SponsorDaoException
  113.     {
  114.         return (Sponsor)this.create(TRANSFORM_NONE, sponsor);
  115.     }

  116.     /**
  117.      * Create Sponsor with VO transformation
  118.      * @see SponsorDao#create(int, Sponsor)
  119.      */
  120.     @Override
  121.     public Object create(final int transform, final Sponsor sponsor)
  122.         throws SponsorDaoException
  123.     {
  124.         if (sponsor == null)
  125.         {
  126.             throw new IllegalArgumentException(
  127.                 "Sponsor.create - 'sponsor' can not be null");
  128.         }

  129.         try
  130.         {
  131.             this.emanager.persist(sponsor);
  132.             this.emanager.flush();
  133.             return this.transformEntity(transform, sponsor);
  134.         }
  135.         catch (Exception ex)
  136.         {
  137.             throw new SponsorDaoException(ex);
  138.         }
  139.     }

  140.     /**
  141.      * Create a Collection of Sponsor with no VO transformation
  142.      * @see SponsorDao#create(Collection)
  143.      */
  144.     @Override
  145.     @SuppressWarnings({"unchecked"})
  146.     public Collection<Sponsor> create(final Collection<Sponsor> entities)
  147.         throws SponsorDaoException
  148.     {
  149.         return create(TRANSFORM_NONE, entities);
  150.     }

  151.     /**
  152.      * Create a Collection of Sponsor with VO transformation
  153.      * @see SponsorDao#create(int, Collection)
  154.      */
  155.     @Override
  156.     @SuppressWarnings({"unchecked", "rawtypes"})
  157.     public Collection create(final int transform, final Collection<Sponsor> entities)
  158.         throws SponsorDaoException
  159.     {
  160.         if (entities == null)
  161.         {
  162.             throw new IllegalArgumentException(
  163.                 "Sponsor.create - 'entities' can not be null");
  164.         }
  165.         Collection results = new ArrayList();
  166.         try
  167.         {
  168.             for (final Sponsor entity : entities)
  169.             {
  170.                 results.add(create(transform, entity));
  171.             }
  172.         }
  173.         catch (Exception ex)
  174.         {
  175.             throw new SponsorDaoException(ex);
  176.         }
  177.         return results;
  178.     }

  179.     /**
  180.      * Create Entity Sponsor using instance attributes with no VO transformation
  181.      * @see SponsorDao#create(int, String)
  182.      */
  183.     @Override
  184.     public Sponsor create(
  185.         int code,
  186.         String name)
  187.         throws SponsorDaoException
  188.     {
  189.         return (Sponsor)this.create(TRANSFORM_NONE, code, name);
  190.     }

  191.     /**
  192.      * Create Entity Sponsor using instance attributes with VO transformation
  193.      * @see SponsorDao#create(int, int, String)
  194.      * composite=false identifiers=1
  195.      */
  196.     @Override
  197.     public Object create(
  198.         final int transform,
  199.         int code,
  200.         String name)
  201.         throws SponsorDaoException
  202.     {
  203.         Sponsor entity = new Sponsor();
  204.         entity.setCode(code);
  205.         entity.setName(name);
  206.         return this.create(transform, entity);
  207.     }

  208.     /**
  209.      * Create Entity Sponsor using required properties with no VO transformation
  210.      * @see SponsorDao#create(int, GrantInfo, String, TrackAthlete)
  211.      */
  212.     @Override
  213.     public Sponsor create(
  214.         int code,
  215.         Set<GrantInfo> grantInfos,
  216.         String name,
  217.         TrackAthlete trackAthlete)
  218.         throws SponsorDaoException
  219.     {
  220.         return (Sponsor)this.create(TRANSFORM_NONE, code, grantInfos, name, trackAthlete);
  221.     }

  222.     /**
  223.      * Create Entity Sponsor using required properties with VO transformation
  224.      * @see SponsorDao#create(int, int, GrantInfo, String, TrackAthlete)
  225.      */
  226.     @Override
  227.     public Object create(
  228.         final int transform,
  229.         int code,
  230.         Set<GrantInfo> grantInfos,
  231.         String name,
  232.         TrackAthlete trackAthlete)
  233.         throws SponsorDaoException
  234.     {
  235.         Sponsor entity = new Sponsor();
  236.         // code $propertyType.fullyQualifiedName identifier=$propertyType.identifier false
  237.         entity.setCode(code);
  238.         // grantInfos $propertyType.fullyQualifiedName identifier=$propertyType.identifier false
  239.         entity.setGrantInfos(grantInfos);
  240.         // name $propertyType.fullyQualifiedName identifier=$propertyType.identifier false
  241.         entity.setName(name);
  242.         // trackAthlete $propertyType.fullyQualifiedName identifier=$propertyType.identifier false
  243.         entity.setTrackAthlete(trackAthlete);
  244.         return this.create(transform, entity);
  245.     }

  246.     /**
  247.      * @see SponsorDao#update(Sponsor)
  248.      */
  249.     @Override
  250.     public void update(Sponsor sponsor)
  251.         throws SponsorDaoException
  252.     {
  253.         if (sponsor == null)
  254.         {
  255.             throw new IllegalArgumentException(
  256.                 "Sponsor.update - 'sponsor' can not be null");
  257.         }
  258.         try
  259.         {
  260.             this.emanager.merge(sponsor);
  261.             this.emanager.flush();
  262.         }
  263.         catch (Exception ex)
  264.         {
  265.             throw new SponsorDaoException(ex);
  266.         }
  267.     }

  268.     /**
  269.      * @see SponsorDao#update(Collection)
  270.      */
  271.     @Override
  272.     public void update(final Collection<Sponsor> entities)
  273.         throws SponsorDaoException
  274.     {
  275.         if (entities == null)
  276.         {
  277.             throw new IllegalArgumentException(
  278.                 "Sponsor.update - 'entities' can not be null");
  279.         }
  280.         try
  281.         {
  282.             for (final Sponsor entity : entities)
  283.             {
  284.                 update(entity);
  285.             }
  286.         }
  287.         catch (Exception ex)
  288.         {
  289.             throw new SponsorDaoException(ex);
  290.         }
  291.     }

  292.     /**
  293.      * @see SponsorDao#remove(Sponsor)
  294.      */
  295.     @Override
  296.     public void remove(Sponsor sponsor)
  297.         throws SponsorDaoException
  298.     {
  299.         if (sponsor == null)
  300.         {
  301.             throw new IllegalArgumentException(
  302.                 "Sponsor.remove - 'sponsor' can not be null");
  303.         }
  304.         try
  305.         {
  306.             this.emanager.remove(sponsor);
  307.             this.emanager.flush();
  308.         }
  309.         catch (Exception ex)
  310.         {
  311.             throw new SponsorDaoException(ex);
  312.         }
  313.     }

  314.     /**
  315.      * @see SponsorDao#remove(Long)
  316.      */
  317.     @Override
  318.     public void remove(Long sponsorId)
  319.         throws SponsorDaoException
  320.     {
  321.         if (sponsorId == null)
  322.         {
  323.             throw new IllegalArgumentException(
  324.                 "Sponsor.remove - 'sponsorId' can not be null");
  325.         }
  326.         try
  327.         {
  328.             final Sponsor entity = this.load(sponsorId);
  329.             if (entity != null)
  330.             {
  331.                 this.remove(entity);
  332.             }
  333.         }
  334.         catch (Exception ex)
  335.         {
  336.             throw new SponsorDaoException(ex);
  337.         }
  338.     }

  339.     /**
  340.      * @see SponsorDao#remove(Collection)
  341.      */
  342.     @Override
  343.     public void remove(Collection<Sponsor> entities)
  344.         throws SponsorDaoException
  345.     {
  346.         if (entities == null)
  347.         {
  348.             throw new IllegalArgumentException(
  349.                 "Sponsor.remove - 'entities' can not be null");
  350.         }
  351.         try
  352.         {
  353.             for (final Sponsor entity : entities)
  354.             {
  355.                 remove(entity);
  356.             }
  357.         }
  358.         catch (Exception ex)
  359.         {
  360.             throw new SponsorDaoException(ex);
  361.         }
  362.     }

  363.     /**
  364.      * Allows transformation of entities into value objects
  365.      * (or something else for that matter), when the <code>transform</code>
  366.      * flag is set to one of the constants defined in <code>SponsorDao</code>, please note
  367.      * that the {@link #TRANSFORM_NONE} constant denotes no transformation, so the entity itself
  368.      * will be returned.
  369.      *
  370.      * If the integer argument value is unknown {@link #TRANSFORM_NONE} is assumed.
  371.      *
  372.      * @param transform one of the constants declared in {@link SponsorDao}
  373.      * @param entity an entity that was found
  374.      * @return the transformed entity (i.e. new value object, etc)
  375.      * @see #transformEntities(int,Collection)
  376.      */
  377.     protected Object transformEntity(final int transform, final Sponsor entity)
  378.     {
  379.         Object target = null;
  380.         if (entity != null)
  381.         {
  382.             switch (transform)
  383.             {
  384.                 case TRANSFORM_NONE : // fall-through
  385.                 default:
  386.                     target = entity;
  387.             }
  388.         }
  389.         return target;
  390.     }

  391.     /**
  392.      * Transforms a collection of entities using the
  393.      * {@link #transformEntity(int, Sponsor)}
  394.      * method. This method does not instantiate a new collection.
  395.      * <p/>
  396.      * Transforms into the same collection as the argument, but this time containing the transformed entities
  397.      * This method is to be used internally only.
  398.      *
  399.      * @param transform one of the constants declared in <code>SponsorDao</code>
  400.      * @param entities the collection of entities to transform
  401.      * @see #transformEntity(int, Sponsor)
  402.      */
  403.     protected void transformEntities(final int transform, final Collection<Sponsor> entities)
  404.     {
  405.         switch (transform)
  406.         {
  407.             case TRANSFORM_NONE : // fall-through
  408.                 default:
  409.                 // do nothing;
  410.         }
  411.     }


  412.     // For unit testing outside of container - persistence context not injected
  413.     /**
  414.      * @return the context
  415.      */
  416.     public SessionContext getContext()
  417.     {
  418.         return this.context;
  419.     }

  420.     /**
  421.      * @param contextIn the context to set
  422.      */
  423.     public void setContext(SessionContext contextIn)
  424.     {
  425.         this.context = contextIn;
  426.     }

  427.     /**
  428.      * @return the emanager
  429.      */
  430.     public EntityManager getEmanager()
  431.     {
  432.         return this.emanager;
  433.     }

  434.     /**
  435.      * @param emanagerIn the emanager to set
  436.      */
  437.     public void setEmanager(EntityManager emanagerIn)
  438.     {
  439.         this.emanager = emanagerIn;
  440.     }

  441.     /**
  442.      * @return the hibernateSession
  443.      */
  444.     public Session getHibernateSession()
  445.     {
  446.         return this.hibernateSession;
  447.     }

  448.     /**
  449.      * @param hibernateSessionIn the hibernateSession to set
  450.      */
  451.     public void setHibernateSession(Session hibernateSessionIn)
  452.     {
  453.         this.hibernateSession = hibernateSessionIn;
  454.     }
  455. }