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 java.sql.Timestamp; 022import java.util.Date; 023import java.util.List; 024 025import javax.persistence.EntityManager; 026import javax.persistence.Query; 027 028import org.apache.oozie.ErrorCode; 029import org.apache.oozie.util.DateUtils; 030import org.apache.oozie.util.ParamChecker; 031 032public class CoordJobGetActionModifiedDateForRangeJPAExecutor implements JPAExecutor<Date> { 033 034 private String jobId = null; 035 private String startAction, endAction; 036 037 public CoordJobGetActionModifiedDateForRangeJPAExecutor(String jobId, String startAction, String endAction) { 038 ParamChecker.notNull(jobId, "jobId"); 039 this.jobId = jobId; 040 this.startAction = startAction; 041 this.endAction = endAction; 042 } 043 044 @Override 045 public String getName() { 046 return "CoordJobGetActionIdsForDateRangeJPAExecutor"; 047 } 048 049 @Override 050 @SuppressWarnings("unchecked") 051 public Date execute(EntityManager em) throws JPAExecutorException { 052 try { 053 Query q = em.createNamedQuery("GET_COORD_ACTIONS_MAX_MODIFIED_DATE_FOR_RANGE"); 054 q.setParameter("jobId", jobId); 055 q.setParameter("startAction", startAction); 056 q.setParameter("endAction", endAction); 057 List<Timestamp> coordActionIds = q.getResultList(); 058 return coordActionIds.isEmpty() ? new Date() : DateUtils.toDate(coordActionIds.get(0)); 059 } 060 catch (Exception e) { 061 throw new JPAExecutorException(ErrorCode.E0603, e.getMessage(), e); 062 } 063 } 064 065}