001    /**
002     * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
003     * Licensed under the Apache License, Version 2.0 (the "License");
004     * you may not use this file except in compliance with the License.
005     * You may obtain a copy of the License at
006     *
007     *   http://www.apache.org/licenses/LICENSE-2.0
008     *
009     *  Unless required by applicable law or agreed to in writing, software
010     *  distributed under the License is distributed on an "AS IS" BASIS,
011     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012     *  See the License for the specific language governing permissions and
013     *  limitations under the License. See accompanying LICENSE file.
014     */
015    package org.apache.oozie.executor.jpa;
016    
017    import java.sql.Timestamp;
018    import java.util.Date;
019    import java.util.List;
020    
021    import javax.persistence.EntityManager;
022    import javax.persistence.Query;
023    
024    import org.apache.oozie.BundleActionBean;
025    import org.apache.oozie.ErrorCode;
026    
027    /**
028     * Load the list of BundleAction ordered by lastModifiedTime
029     */
030    public class BundleActionsGetByLastModifiedTimeJPAExecutor implements JPAExecutor<List<BundleActionBean>> {
031        private Date d = null;
032    
033        public BundleActionsGetByLastModifiedTimeJPAExecutor(Date d) {
034            this.d = d;
035        }
036    
037        @Override
038        public String getName() {
039            return "BundleActionsGetByLastModifiedTimeJPAExecutor";
040        }
041    
042        @Override
043        @SuppressWarnings("unchecked")
044        public List<BundleActionBean> execute(EntityManager em) throws JPAExecutorException {
045            List<BundleActionBean> baBeans;
046            try {
047                Query q = em.createNamedQuery("GET_BUNDLE_ACTIONS_BY_LAST_MODIFIED_TIME");
048                q.setParameter("lastModifiedTime", new Timestamp(d.getTime()));
049                baBeans = q.getResultList();
050            }
051            catch (Exception e) {
052                throw new JPAExecutorException(ErrorCode.E0603, e);
053            }
054    
055            return baBeans;
056        }
057    }