01: /*
02: * Copyright 2004-2006 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.compass.spring.device.jpa;
18:
19: import javax.persistence.EntityManager;
20: import javax.persistence.EntityManagerFactory;
21:
22: import org.compass.gps.device.jpa.JpaGpsDeviceException;
23: import org.compass.gps.device.jpa.NativeJpaExtractor;
24: import org.springframework.orm.jpa.EntityManagerFactoryInfo;
25:
26: /**
27: * Extracts the native entity manager factory from a managed Spring one. If Spring
28: * has not wrapped the factory, will return it as is.
29: *
30: * @author kimchy
31: */
32: public class SpringNativeJpaExtractor implements NativeJpaExtractor {
33:
34: /**
35: * Extracts the native entity manager factory from a managed Spring one. If Spring
36: * has not wrapped the factory, will return it as is.
37: *
38: * @param entityManagerFactory The (possibly) managed Spring entity manager factory
39: * @return The native entity manager factory
40: * @throws JpaGpsDeviceException
41: */
42: public EntityManagerFactory extractNative(
43: EntityManagerFactory entityManagerFactory)
44: throws JpaGpsDeviceException {
45: if (entityManagerFactory instanceof EntityManagerFactoryInfo) {
46: return ((EntityManagerFactoryInfo) entityManagerFactory)
47: .getNativeEntityManagerFactory();
48: }
49: return entityManagerFactory;
50: }
51:
52: public EntityManager extractNative(EntityManager entityManager)
53: throws JpaGpsDeviceException {
54: return entityManager;
55: }
56: }
|