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 pending actions for a status for a coordinator job. 011 */ 012 public class CoordActionsPendingFalseStatusCountGetJPAExecutor implements JPAExecutor<Integer> { 013 014 private String coordJobId = null; 015 private String status = null; 016 017 public CoordActionsPendingFalseStatusCountGetJPAExecutor(String coordJobId, String status) { 018 ParamChecker.notNull(coordJobId, "coordJobId"); 019 ParamChecker.notNull(status, "status"); 020 this.coordJobId = coordJobId; 021 this.status = status; 022 } 023 024 @Override 025 public String getName() { 026 return "CoordActionsPendingFalseStatusCountGetJPAExecutor"; 027 } 028 029 @Override 030 public Integer execute(EntityManager em) throws JPAExecutorException { 031 try { 032 Query q = em.createNamedQuery("GET_COORD_ACTIONS_PENDING_FALSE_STATUS_COUNT"); 033 q.setParameter("jobId", coordJobId); 034 q.setParameter("status", status); 035 Long count = (Long) q.getSingleResult(); 036 return Integer.valueOf(count.intValue()); 037 } 038 catch (Exception e) { 039 throw new JPAExecutorException(ErrorCode.E0603, e); 040 } 041 } 042 043 }