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 */
018package org.apache.oozie.executor.jpa;
019
020import java.util.Date;
021
022import javax.persistence.EntityManager;
023import javax.persistence.Query;
024
025import org.apache.oozie.CoordinatorActionBean;
026import org.apache.oozie.ErrorCode;
027import org.apache.oozie.util.ParamChecker;
028
029/**
030 * Updates the action status, pending status and last modified time of CoordinatorAction and persists it.
031 * It executes SQL update query and return type is Void.
032 */
033public class CoordActionUpdateStatusJPAExecutor implements JPAExecutor<Void> {
034
035    private CoordinatorActionBean coordAction = null;
036
037    public CoordActionUpdateStatusJPAExecutor(CoordinatorActionBean coordAction) {
038        ParamChecker.notNull(coordAction, "coordAction");
039        this.coordAction = coordAction;
040    }
041
042    /*
043     * (non-Javadoc)
044     *
045     * @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.
046     * EntityManager)
047     */
048    @Override
049    public Void execute(EntityManager em) throws JPAExecutorException {
050        try {
051            Query q = em.createNamedQuery("UPDATE_COORD_ACTION_STATUS_PENDING_TIME");
052            q.setParameter("id", coordAction.getId());
053            q.setParameter("status", coordAction.getStatus().toString());
054            q.setParameter("pending", coordAction.getPending());
055            q.setParameter("lastModifiedTime", new Date());
056            q.executeUpdate();
057            // Since the return type is Void, we have to return null
058            return null;
059        }
060        catch (Exception e) {
061            throw new JPAExecutorException(ErrorCode.E0603, e.getMessage(), e);
062        }
063    }
064
065    /*
066     * (non-Javadoc)
067     *
068     * @see org.apache.oozie.executor.jpa.JPAExecutor#getName()
069     */
070    @Override
071    public String getName() {
072        return "CoordActionUpdateStatusJPAExecutor";
073    }
074}