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