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 javax.persistence.EntityManager; 022import javax.persistence.Query; 023 024import org.apache.oozie.ErrorCode; 025import org.apache.oozie.util.ParamChecker; 026 027/** 028 * Deletes the coordinator action if its in WAITING or READY state. 029 */ 030public class CoordActionRemoveJPAExecutor implements JPAExecutor<Void> { 031 032 // private CoordinatorActionBean coordAction = null; 033 private String coordActionId = null; 034 035 /** 036 * Constructor which records coordinator action id. 037 * 038 * @param coordActionId 039 */ 040 public CoordActionRemoveJPAExecutor(String coordActionId) { 041 ParamChecker.notNull(coordActionId, "coordActionId"); 042 this.coordActionId = coordActionId; 043 } 044 045 /* (non-Javadoc) 046 * @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.EntityManager) 047 */ 048 @Override 049 public Void execute(EntityManager em) throws JPAExecutorException { 050 Query g = em.createNamedQuery("DELETE_UNSCHEDULED_ACTION"); 051 g.setParameter("id", coordActionId); 052 int actionsDeleted; 053 try { 054 actionsDeleted = g.executeUpdate(); 055 } catch (Exception e) { 056 throw new JPAExecutorException(ErrorCode.E0603, e.getMessage(), e); 057 } 058 059 if (actionsDeleted == 0) 060 throw new JPAExecutorException(ErrorCode.E1022, coordActionId); 061 062 return null; 063 } 064 065 /* (non-Javadoc) 066 * @see org.apache.oozie.executor.jpa.JPAExecutor#getName() 067 */ 068 @Override 069 public String getName() { 070 return "CoordActionRemoveJPAExecutor"; 071 } 072}