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.gps.device.jpa.embedded.hibernate;
18:
19: import java.util.Properties;
20: import javax.persistence.EntityManager;
21: import javax.persistence.EntityManagerFactory;
22:
23: import org.compass.core.Compass;
24: import org.compass.core.CompassTemplate;
25: import org.compass.gps.device.hibernate.embedded.HibernateHelper;
26: import org.compass.gps.device.jpa.JpaGpsDevice;
27: import org.compass.gps.device.jpa.embedded.DefaultJpaCompassGps;
28: import org.compass.gps.device.jpa.embedded.JpaCompassGps;
29: import org.hibernate.ejb.HibernateEntityManager;
30: import org.hibernate.ejb.HibernateEntityManagerFactory;
31:
32: /**
33: * @author kimchy
34: */
35: public abstract class HibernateJpaHelper {
36:
37: private HibernateJpaHelper() {
38:
39: }
40:
41: public static Compass getCompass(EntityManagerFactory emf) {
42: return HibernateHelper
43: .getCompass(((HibernateEntityManagerFactory) emf)
44: .getSessionFactory());
45: }
46:
47: public static CompassTemplate getCompassTemplate(
48: EntityManagerFactory emf) {
49: return HibernateHelper
50: .getCompassTempalte(((HibernateEntityManagerFactory) emf)
51: .getSessionFactory());
52: }
53:
54: public static Compass getCompass(EntityManager em) {
55: return HibernateHelper.getCompass(((HibernateEntityManager) em)
56: .getSession());
57: }
58:
59: public static CompassTemplate getCompassTemplate(EntityManager em) {
60: return HibernateHelper
61: .getCompassTempalte(((HibernateEntityManager) em)
62: .getSession());
63: }
64:
65: public static Properties getIndexSettings(EntityManagerFactory emf) {
66: return HibernateHelper
67: .getIndexSettings(((HibernateEntityManagerFactory) emf)
68: .getSessionFactory());
69: }
70:
71: public static Properties getIndexSettings(EntityManager em) {
72: return HibernateHelper
73: .getIndexSettings(((HibernateEntityManager) em)
74: .getSession());
75: }
76:
77: public static JpaCompassGps getCompassGps(EntityManagerFactory emf) {
78: JpaGpsDevice device = new JpaGpsDevice("jpadevice", emf);
79: return getCompassGps(device);
80: }
81:
82: public static JpaCompassGps getCompassGps(JpaGpsDevice device) {
83: DefaultJpaCompassGps gps = new DefaultJpaCompassGps(
84: getCompass(device.getEntityManagerFactory()));
85: device.setMirrorDataChanges(false);
86: gps.setIndexProperties(getIndexSettings(device
87: .getEntityManagerFactory()));
88: gps.addGpsDevice(device);
89: gps.start();
90: return gps;
91: }
92: }
|