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