001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019package org.apache.oozie.executor.jpa; 020 021import java.sql.SQLException; 022import java.util.ArrayList; 023import java.util.List; 024 025import javax.persistence.EntityManager; 026import javax.persistence.Query; 027 028import org.apache.oozie.ErrorCode; 029import org.apache.oozie.WorkflowActionBean; 030import org.apache.oozie.util.ParamChecker; 031import org.apache.openjpa.persistence.OpenJPAPersistence; 032 033/** 034 * JPA Command to get subset of workflow actions for a particular workflow. 035 */ 036public class WorkflowActionSubsetGetJPAExecutor implements JPAExecutor<List<WorkflowActionBean>> { 037 038 private final String wfId; 039 private final int start; 040 private final int length; 041 042 /** 043 * This Constructor creates the WorkflowActionSubsetGetJPAExecutor object Which gets the List of wrokflow action 044 * bean. 045 * 046 * @param wfId 047 * @param start 048 * @param length 049 */ 050 public WorkflowActionSubsetGetJPAExecutor(String wfId, int start, int length) { 051 ParamChecker.notNull(wfId, "wfJobId"); 052 this.wfId = wfId; 053 this.start = start; 054 this.length = length; 055 } 056 057 /* (non-Javadoc) 058 * @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.EntityManager) 059 */ 060 @Override 061 @SuppressWarnings("unchecked") 062 public List<WorkflowActionBean> execute(EntityManager em) throws JPAExecutorException { 063 List<WorkflowActionBean> actions; 064 List<WorkflowActionBean> actionList = new ArrayList<WorkflowActionBean>(); 065 try { 066 Query q = em.createNamedQuery("GET_ACTIONS_FOR_WORKFLOW"); 067 OpenJPAPersistence.cast(q); 068 q.setParameter("wfId", wfId); 069 q.setFirstResult(start - 1); 070 q.setMaxResults(length); 071 actions = q.getResultList(); 072 } 073 catch (Exception e) { 074 throw new JPAExecutorException(ErrorCode.E0605, "null", e); 075 } 076 return actions; 077 } 078 079 /* (non-Javadoc) 080 * @see org.apache.oozie.executor.jpa.JPAExecutor#getName() 081 */ 082 @Override 083 public String getName() { 084 return "WorkflowActionSubsetGetJPAExecutor"; 085 } 086}