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, last modified time, actionXml and missingDependencies of CoordinatorAction and persists it.
031 * It executes SQL update query and return type is Void.
032 */
033public class CoordActionUpdateForInputCheckJPAExecutor implements JPAExecutor<Void> {
034
035    private CoordinatorActionBean coordAction = null;
036
037    public CoordActionUpdateForInputCheckJPAExecutor(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_FOR_INPUTCHECK");
052            q.setParameter("id", coordAction.getId());
053            q.setParameter("status", coordAction.getStatus().toString());
054            q.setParameter("lastModifiedTime", new Date());
055            q.setParameter("actionXml", coordAction.getActionXml());
056            q.setParameter("missingDependencies", coordAction.getMissingDependencies());
057            q.executeUpdate();
058            // Since the return type is Void, we have to return null
059            return null;
060        }
061        catch (Exception e) {
062            throw new JPAExecutorException(ErrorCode.E0603, e.getMessage(), e);
063        }
064    }
065
066    /*
067     * (non-Javadoc)
068     *
069     * @see org.apache.oozie.executor.jpa.JPAExecutor#getName()
070     */
071    @Override
072    public String getName() {
073        return "CoordActionUpdateForInputCheckJPAExecutor";
074    }
075}