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