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 org.apache.oozie.ErrorCode; 022import org.apache.oozie.FaultInjection; 023 024import javax.persistence.EntityManager; 025import javax.persistence.Query; 026import java.util.Collection; 027 028/** 029 * Delete Bundle job, its list of actions and return the number of actions that were deleted. 030 */ 031public class BundleJobsDeleteJPAExecutor implements JPAExecutor<Integer> { 032 033 private Collection<String> deleteList; 034 035 /** 036 * Initialize the JPAExecutor using the delete list of BundleJobBeans 037 * @param deleteList 038 */ 039 public BundleJobsDeleteJPAExecutor(Collection<String> deleteList) { 040 this.deleteList = deleteList; 041 } 042 043 public BundleJobsDeleteJPAExecutor() { 044 } 045 046 /** 047 * Sets the delete list for BundleJobBeans 048 * 049 * @param deleteList 050 */ 051 public void setDeleteList(Collection<String> deleteList) { 052 this.deleteList = deleteList; 053 } 054 055 /* 056 * (non-Javadoc) 057 * 058 * @see org.apache.oozie.executor.jpa.JPAExecutor#getName() 059 */ 060 @Override 061 public String getName() { 062 return "BundleJobsDeleteJPAExecutor"; 063 } 064 065 /* 066 * (non-Javadoc) 067 * 068 * @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence. 069 * EntityManager) 070 */ 071 @Override 072 public Integer execute(EntityManager em) throws JPAExecutorException { 073 int actionsDeleted = 0; 074 try { 075 // Only used by test cases to check for rollback of transaction 076 FaultInjection.activate("org.apache.oozie.command.SkipCommitFaultInjection"); 077 if (deleteList != null && !deleteList.isEmpty()) { 078 Query q = em.createNamedQuery("DELETE_BUNDLE_JOB"); 079 q.setParameter("id", deleteList); 080 q.executeUpdate(); 081 // Delete the actions for this coord job 082 Query g = em.createNamedQuery("DELETE_ACTIONS_FOR_BUNDLE"); 083 g.setParameter("bundleId", deleteList); 084 actionsDeleted = g.executeUpdate(); 085 } 086 } 087 catch (Exception e) { 088 throw new JPAExecutorException(ErrorCode.E0603, e.getMessage(), e); 089 } 090 return actionsDeleted; 091 } 092}