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.util.List;
022import javax.persistence.EntityManager;
023import javax.persistence.Query;
024import org.apache.oozie.ErrorCode;
025import org.apache.oozie.SLAEventBean;
026
027/**
028 * Load the list of SLAEventBean for a seqId and return the list.
029 */
030@Deprecated
031public class SLAEventsGetForSeqIdJPAExecutor implements JPAExecutor<List<SLAEventBean>> {
032
033    private long seqId = 0;
034    private int limitLen = 100; // Default
035    private long[] lastSeqId;
036
037    public SLAEventsGetForSeqIdJPAExecutor(long seqId, int limitLen, long[] lastSeqId) {
038        this.seqId = seqId;
039        this.limitLen = limitLen;
040        this.lastSeqId = lastSeqId;
041        this.lastSeqId[0] = seqId;
042    }
043
044    @Override
045    public String getName() {
046        return "SLAEventsGetForSeqIdJPAExecutor";
047    }
048
049    @Override
050    @SuppressWarnings("unchecked")
051    public List<SLAEventBean> execute(EntityManager em) throws JPAExecutorException {
052        List<SLAEventBean> seBeans;
053        try {
054            Query q = em.createNamedQuery("GET_SLA_EVENT_NEWER_SEQ_LIMITED");
055            q.setParameter("id", seqId);
056            q.setMaxResults(limitLen);
057            seBeans = q.getResultList();
058            for (SLAEventBean j : seBeans) {
059                lastSeqId[0] = Math.max(lastSeqId[0], j.getEvent_id());
060            }
061        }
062        catch (Exception e) {
063            throw new JPAExecutorException(ErrorCode.E0603, e.getMessage(), e);
064        }
065        return seBeans;
066    }
067}