001/*
002 * Copyright 2006-2013 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.batch.item.database.orm;
018
019import javax.persistence.EntityManager;
020import javax.persistence.Query;
021
022import org.springframework.beans.factory.InitializingBean;
023
024/**
025 * <p>
026 * Abstract JPA Query Provider to serve as a base class for all JPA
027 * {@link Query} providers.
028 * </p>
029 *
030 * @author Anatoly Polinsky
031 * @author Dave Syer
032 *
033 * @since 2.1
034 */
035public abstract class AbstractJpaQueryProvider implements JpaQueryProvider, InitializingBean {
036
037        private EntityManager entityManager;
038
039        /**
040         * <p>
041         * Public setter to override the entityManager that was created by this
042         * {@link HibernateQueryProvider}. This is currently needed to allow
043         * {@link HibernateQueryProvider} to participate in a user's managed transaction.
044         * </p>
045         *
046         * @param entityManager EntityManager to use
047         */
048        @Override
049        public void setEntityManager(EntityManager entityManager) {
050                this.entityManager = entityManager;
051        }
052
053        /**
054         * <p>
055         * Getter for {@link EntityManager}
056         * </p>
057         *
058         * @return entityManager the injected {@link EntityManager}
059         */
060        protected EntityManager getEntityManager() {
061                return entityManager;
062        }
063}