| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| package org.apache.openjpa.persistence.spring; |
| |
| import org.apache.openjpa.persistence.models.library.Book; |
| import org.apache.openjpa.persistence.models.library.Borrower; |
| |
| /** |
| * The Spring library example is intended to mirror the behavior of an |
| * application that uses the Spring Framework's JPA transaction manager and |
| * annotations. In this case, the Spring Framework's transactional handling, |
| * through its advice and proxies, causes the entity manager to be closed after |
| * each call to the implementation of the service (a.k.a. DAO) interface. These |
| * observations are based on Spring version 2.5.5. |
| * <p> |
| * It is likely that other containers behave in a similar manner. |
| * <p> |
| * In particular, it mirrors the behavior when there is a Spring annotated |
| * service interface that looks like the following: |
| * |
| * <pre> |
| * (at)Transactional(propagation=Propagation.SUPPORTS) |
| * public interface LibService |
| * { |
| * public Borrower findBorrowerByName(String name); |
| * public Book findBookByTitle(String title); |
| * |
| * (at)Transactional(propagation=Propagation.REQUIRED) |
| * public void borrowBook(Borrower borrower, Book book); |
| * |
| * (at)Transactional(propagation=Propagation.REQUIRED) |
| * public void returnBook(Book book); |
| * } |
| * </pre> |
| * <p> |
| * And there is a Spring configuration file with the following entries: |
| * |
| * <pre> |
| * <bean id="emf" |
| * class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean" |
| * > |
| * <property name="persistenceUnitName" value="" /> |
| * </bean> |
| * |
| * <!-- enable Spring's support for JPA injection --> |
| * <bean class=" |
| *org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor |
| *"/> |
| * |
| * <bean id="transactionalService" |
| * class="sample.jpa.service.LibServiceImpl" > |
| * </bean> |
| * |
| * <bean id="transactionManager" |
| * class="org.springframework.orm.jpa.JpaTransactionManager" > |
| * <property name="entityManagerFactory" ref="emf" /> |
| * </bean> |
| * |
| * <tx:annotation-driven/> |
| * </pre> |
| * <p> |
| * And the declaration of the entity manager in the service implementation is |
| * annotated with the <b>(at)PersistenceContext</b> annotation. |
| * |
| * @author David Ezzio |
| */ |
| |
| public interface LibService { |
| Borrower findBorrowerByName(String name); |
| |
| Book findBookByTitle(String title); |
| |
| void borrowBook(Borrower borrower, Book book); |
| |
| void returnBook(Book book); |
| |
| void setTransactionalEntityManagerFactory( |
| TransactionalEntityManagerFactory txEMF); |
| } |