001    package org.apache.oozie.executor.jpa;
002    
003    import javax.persistence.EntityManager;
004    import javax.persistence.Query;
005    
006    import org.apache.oozie.ErrorCode;
007    import org.apache.oozie.util.ParamChecker;
008    
009    /**
010     * Load the number of actions for a bundle job.
011     */
012    public class BundleActionsCountForJobGetJPAExecutor implements JPAExecutor<Integer> {
013    
014        private String bundleJobId = null;
015    
016        public BundleActionsCountForJobGetJPAExecutor(String bundleJobId) {
017            ParamChecker.notNull(bundleJobId, "bundleJobId");
018            this.bundleJobId = bundleJobId;
019        }
020    
021        @Override
022        public String getName() {
023            return "BundleActionsCountForJobGetJPAExecutor";
024        }
025    
026        @Override
027        public Integer execute(EntityManager em) throws JPAExecutorException {
028            try {
029                Query q = em.createNamedQuery("GET_BUNDLE_ACTIONS_COUNT_BY_JOB");
030    
031                q.setParameter("bundleId", bundleJobId);
032                Long count = (Long) q.getSingleResult();
033                return Integer.valueOf(count.intValue());
034            }
035            catch (Exception e) {
036                throw new JPAExecutorException(ErrorCode.E0603, e);
037            }
038        }
039    
040    }