001 /** 002 * Copyright (c) 2010 Yahoo! Inc. All rights reserved. 003 * Licensed under the Apache License, Version 2.0 (the "License"); 004 * you may not use this file except in compliance with the License. 005 * You may obtain a copy of the License at 006 * 007 * http://www.apache.org/licenses/LICENSE-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, software 010 * distributed under the License is distributed on an "AS IS" BASIS, 011 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 * See the License for the specific language governing permissions and 013 * limitations under the License. See accompanying LICENSE file. 014 */ 015 package org.apache.oozie.executor.jpa; 016 017 import java.util.ArrayList; 018 import java.util.List; 019 020 import javax.persistence.EntityManager; 021 import javax.persistence.Query; 022 023 import org.apache.oozie.CoordinatorJobBean; 024 import org.apache.oozie.ErrorCode; 025 026 /** 027 * Get a list of paused bundle Jobs; 028 */ 029 public class CoordJobsGetPausedJPAExecutor implements JPAExecutor<List<CoordinatorJobBean>> { 030 private final int limit; 031 032 public CoordJobsGetPausedJPAExecutor(int limit) { 033 this.limit = limit; 034 } 035 036 @Override 037 public String getName() { 038 return "CoordJobsGetPausedJPAExecutor"; 039 } 040 041 @Override 042 @SuppressWarnings("unchecked") 043 public List<CoordinatorJobBean> execute(EntityManager em) throws JPAExecutorException { 044 List<CoordinatorJobBean> cjBeans; 045 List<CoordinatorJobBean> jobList = new ArrayList<CoordinatorJobBean>(); 046 try { 047 Query q = em.createNamedQuery("GET_COORD_JOBS_PAUSED"); 048 if (limit > 0) { 049 q.setMaxResults(limit); 050 } 051 cjBeans = q.getResultList(); 052 for (CoordinatorJobBean j : cjBeans) { 053 jobList.add(j); 054 } 055 } 056 catch (Exception e) { 057 throw new JPAExecutorException(ErrorCode.E0603, e); 058 } 059 return jobList; 060 } 061 }