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 javax.persistence.EntityManager; 018 019 /** 020 * Executor pattern interface that gives access to an {@link EntityManager}. 021 * <p/> 022 * Implementations are executed by the {@link org.apache.oozie.service.JPAService}. 023 */ 024 public interface JPAExecutor<T> { 025 026 /** 027 * Return the name of the JPA executor. Used for logging and instrumentation. 028 * 029 * @return the name of the JPA executor. 030 */ 031 public String getName(); 032 033 /** 034 * Method that encapsulates JPA access operations. 035 * <p/> 036 * Implementations should not close the received {@link EntityManager}. 037 * <p/> 038 * Implementations should commit any transaction before ending, else the transaction will be rolled back. 039 * 040 * @param em an active {@link EntityManager} 041 * @return a return value if any. 042 * @throws JPAExecutorException thrown if a jpa executor failed 043 */ 044 public T execute(EntityManager em) throws JPAExecutorException; 045 046 }