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 javax.persistence.EntityManager; 018 import javax.persistence.Query; 019 020 import org.apache.oozie.ErrorCode; 021 import org.apache.oozie.util.ParamChecker; 022 023 /** 024 * Delete the list of BundleAction for a BundleJob and return the number of actions been deleted. 025 */ 026 public class BundleActionsDeleteForPurgeJPAExecutor implements JPAExecutor<Integer> { 027 028 private String bundleId = null; 029 030 public BundleActionsDeleteForPurgeJPAExecutor(String bundleId) { 031 ParamChecker.notNull(bundleId, "bundleId"); 032 this.bundleId = bundleId; 033 } 034 035 /* (non-Javadoc) 036 * @see org.apache.oozie.executor.jpa.JPAExecutor#getName() 037 */ 038 @Override 039 public String getName() { 040 return "BundleActionsDeleteForPurgeJPAExecutor"; 041 } 042 043 /* (non-Javadoc) 044 * @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.EntityManager) 045 */ 046 @Override 047 public Integer execute(EntityManager em) throws JPAExecutorException { 048 int actionsDeleted = 0; 049 try { 050 Query g = em.createNamedQuery("DELETE_COMPLETED_ACTIONS_FOR_BUNDLE"); 051 g.setParameter("bundleId", bundleId); 052 actionsDeleted = g.executeUpdate(); 053 } 054 catch (Exception e) { 055 throw new JPAExecutorException(ErrorCode.E0603, e); 056 } 057 return actionsDeleted; 058 } 059 }