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.jboss.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.jboss.ejb3.entity.InjectedEntityManagerFactory;
25:
26: /**
27: * @author kimchy
28: */
29: public class JBossNativeHibernateJpaExtractor implements
30: NativeJpaExtractor {
31:
32: /**
33: * Extracts the native entity manager factory from a managed JBoss one. If JBoss
34: * has not wrapped the factory, will return it as is.
35: *
36: * @param entityManagerFactory The (possibly) managed JBoss entity manager factory
37: * @return The native entity manager factory
38: * @throws org.compass.gps.device.jpa.JpaGpsDeviceException
39: *
40: */
41: public EntityManagerFactory extractNative(
42: EntityManagerFactory entityManagerFactory)
43: throws JpaGpsDeviceException {
44: if (entityManagerFactory instanceof InjectedEntityManagerFactory) {
45: return ((InjectedEntityManagerFactory) entityManagerFactory)
46: .getDelegate();
47: }
48: return entityManagerFactory;
49: }
50:
51: public EntityManager extractNative(EntityManager entityManager)
52: throws JpaGpsDeviceException {
53: return entityManager;
54: }
55: }
|