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.sla; 019 020 import javax.persistence.EntityManager; 021 import javax.persistence.Query; 022 023 import org.apache.oozie.ErrorCode; 024 import org.apache.oozie.executor.jpa.JPAExecutor; 025 import org.apache.oozie.executor.jpa.JPAExecutorException; 026 import org.apache.oozie.sla.SLARegistrationBean; 027 028 /** 029 * Load SLARegistrationBean on restart 030 */ 031 public class SLARegistrationGetOnRestartJPAExecutor implements JPAExecutor<SLARegistrationBean> { 032 033 private String id; 034 035 public SLARegistrationGetOnRestartJPAExecutor(String id) { 036 this.id = id; 037 } 038 039 @Override 040 public String getName() { 041 return "SLARegistrationGetOnRestartJPAExecutor"; 042 } 043 044 @Override 045 public SLARegistrationBean execute(EntityManager em) throws JPAExecutorException { 046 try { 047 Query q = em.createNamedQuery("GET_SLA_REG_ON_RESTART"); 048 q.setParameter("id", id); 049 Object[] obj = (Object[]) q.getSingleResult(); 050 return getBeanFromObj(obj); 051 } 052 catch (Exception e) { 053 throw new JPAExecutorException(ErrorCode.E0603, e.getMessage(), e); 054 } 055 } 056 057 private SLARegistrationBean getBeanFromObj(Object[] arr) { 058 SLARegistrationBean bean = new SLARegistrationBean(); 059 if (arr[0] != null) { 060 bean.setNotificationMsg((String) arr[0]); 061 } 062 if (arr[1] != null) { 063 bean.setUpstreamApps((String) arr[1]); 064 } 065 if (arr[2] != null) { 066 bean.setSlaConfig((String) arr[2]); 067 } 068 if (arr[3] != null) { 069 bean.setJobData((String) arr[3]); 070 } 071 return bean; 072 } 073 074 }