01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.orm.jpa;
18:
19: import javax.persistence.EntityManager;
20:
21: import org.springframework.transaction.SavepointManager;
22: import org.springframework.transaction.support.ResourceHolderSupport;
23: import org.springframework.util.Assert;
24:
25: /**
26: * Holder wrapping a JPA EntityManager.
27: * JpaTransactionManager binds instances of this class to the thread,
28: * for a given EntityManagerFactory.
29: *
30: * <p>Note: This is an SPI class, not intended to be used by applications.
31: *
32: * @author Juergen Hoeller
33: * @since 2.0
34: * @see JpaTransactionManager
35: * @see EntityManagerFactoryUtils
36: */
37: public class EntityManagerHolder extends ResourceHolderSupport {
38:
39: private final EntityManager entityManager;
40:
41: private SavepointManager savepointManager;
42:
43: public EntityManagerHolder(EntityManager entityManager) {
44: Assert.notNull(entityManager, "EntityManager must not be null");
45: this .entityManager = entityManager;
46: }
47:
48: public EntityManager getEntityManager() {
49: return this .entityManager;
50: }
51:
52: public void setSavepointManager(SavepointManager savepointManager) {
53: this .savepointManager = savepointManager;
54: }
55:
56: public SavepointManager getSavepointManager() {
57: return this .savepointManager;
58: }
59:
60: public void clear() {
61: super.clear();
62: this.savepointManager = null;
63: }
64:
65: }
|