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 running actions for a coordinator job. 011 */ 012 public class CoordActionsActiveCountJPAExecutor implements JPAExecutor<Integer> { 013 014 private String coordJobId = null; 015 016 public CoordActionsActiveCountJPAExecutor(String coordJobId) { 017 ParamChecker.notNull(coordJobId, "coordJobId"); 018 this.coordJobId = coordJobId; 019 } 020 021 @Override 022 public String getName() { 023 return "CoordActionsActiveCountJPAExecutor"; 024 } 025 026 @Override 027 public Integer execute(EntityManager em) throws JPAExecutorException { 028 try { 029 Query q = em.createNamedQuery("GET_COORD_ACTIVE_ACTIONS_COUNT_BY_JOBID"); 030 031 q.setParameter("jobId", coordJobId); 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 }