/** * Returns the Compass Gps instance associated with the given OpenJPA {@link javax.persistence.EntityManagerFactory}. * Used in order to perform {@link org.compass.gps.device.jpa.embedded.JpaCompassGps#index()} operation. Note, the index * operation should not be perfomed within a running transaction. */ public static JpaCompassGps getCompassGps(EntityManagerFactory emf) { EntityManagerFactory nativeEmf = NativeJpaHelper.extractNativeJpa(emf); OpenJPAEntityManagerFactory openJpaEmf = OpenJPAPersistence.cast(nativeEmf); return (JpaCompassGps) openJpaEmf.getUserObject(CompassProductDerivation.COMPASS_GPS_USER_OBJECT_KEY); }
/** * Gets the persistence context. The persistence context is lazily constructed because all commands * may not need it. */ public OpenJPAEntityManager getPersistenceContext() { if (_em == null) { _em = _emf.createEntityManager(); } return _em; }
public JESTContext(String unit, OpenJPAEntityManagerFactory emf, HttpServletRequest request, HttpServletResponse response) { _unit = unit; _emf = emf; _request = request; _response = response; OpenJPAConfiguration conf = _emf.getConfiguration(); _log = conf.getLog("JEST"); _repos = conf.getMetaDataRepositoryInstance(); }
/** * Determines whether the specified state manager is managed by an open * broker within the persistence unit of the provided EMF instance. * @param emf OpenJPAEntityManagerFactory * @param sm StateManager * @return true if this state manager is managed by a broker within * this persistence unit. */ public static boolean isManagedBy(OpenJPAEntityManagerFactory emf, Object entity) { // Assert a valid emf was provided, it is open, and the entity is PC if (emf == null || !emf.isOpen() || !ImplHelper.isManageable(entity)) { return false; } // Assert the context is a broker PersistenceCapable pc = (PersistenceCapable)entity; if (!(pc.pcGetGenericContext() instanceof Broker)) { return false; } // Assert the broker is available and open Broker broker = (Broker)pc.pcGetGenericContext(); if (broker == null || broker.isClosed()) { return false; } // Assert the emf associated with the PC is the same as the provided emf OpenJPAEntityManagerFactory eemf = JPAFacadeHelper.toEntityManagerFactory(broker.getBrokerFactory()); if (eemf == emf && eemf.isOpen()) { return true; } return false; }
/** * Determines whether the specified state manager is managed by an open * broker within the persistence unit of the provided EMF instance. * @param emf OpenJPAEntityManagerFactory * @param sm StateManager * @return true if this state manager is managed by a broker within * this persistence unit. */ public static boolean isManagedBy(OpenJPAEntityManagerFactory emf, Object entity) { // Assert a valid emf was provided, it is open, and the entity is PC if (emf == null || !emf.isOpen() || !ImplHelper.isManageable(entity)) { return false; } // Assert the context is a broker PersistenceCapable pc = (PersistenceCapable)entity; if (!(pc.pcGetGenericContext() instanceof Broker)) { return false; } // Assert the broker is available and open Broker broker = (Broker)pc.pcGetGenericContext(); if (broker == null || broker.isClosed()) { return false; } // Assert the emf associated with the PC is the same as the provided emf OpenJPAEntityManagerFactory eemf = JPAFacadeHelper.toEntityManagerFactory(broker.getBrokerFactory()); if (eemf == emf && eemf.isOpen()) { return true; } return false; }
/** * Returns the Compass instance assoicated with the given OpenJPA {@link javax.persistence.EntityManagerFactory}. * This allows to get a Compass instnace in order to perform search operations for example outside of a JPA * transaction (for performance reasons, mostly there is no need to start a DB transaction). */ public static Compass getCompass(EntityManagerFactory emf) { EntityManagerFactory nativeEmf = NativeJpaHelper.extractNativeJpa(emf); OpenJPAEntityManagerFactory openJpaEmf = OpenJPAPersistence.cast(nativeEmf); return (Compass) openJpaEmf.getUserObject(CompassProductDerivation.COMPASS_USER_OBJECT_KEY); }
/** * Determines whether the specified state manager is managed by an open * broker within the persistence unit of the provided EMF instance. * @param emf OpenJPAEntityManagerFactory * @param sm StateManager * @return true if this state manager is managed by a broker within * this persistence unit. */ public static boolean isManagedBy(OpenJPAEntityManagerFactory emf, Object entity) { // Assert a valid emf was provided, it is open, and the entity is PC if (emf == null || !emf.isOpen() || !ImplHelper.isManageable(entity)) { return false; } // Assert the context is a broker PersistenceCapable pc = (PersistenceCapable)entity; if (!(pc.pcGetGenericContext() instanceof Broker)) { return false; } // Assert the broker is available and open Broker broker = (Broker)pc.pcGetGenericContext(); if (broker == null || broker.isClosed()) { return false; } // Assert the emf associated with the PC is the same as the provided emf OpenJPAEntityManagerFactory eemf = JPAFacadeHelper.toEntityManagerFactory(broker.getBrokerFactory()); if (eemf == emf && eemf.isOpen()) { return true; } return false; }
OpenJPAEntityManager em = emf.createEntityManager(); boolean isJTA = em.isManaged(); em.close(); emf.createEntityManager().close();
/** * Returns the index settings that are configured within the {@link javax.persistence.EntityManagerFactory} * configuration. Can be used to configure exteranally a {@link org.compass.gps.device.jpa.embedded.JpaCompassGps} * instance. */ public Properties getIndexSettings(EntityManagerFactory emf) { EntityManagerFactory nativeEmf = NativeJpaHelper.extractNativeJpa(emf); OpenJPAEntityManagerFactory openJpaEmf = OpenJPAPersistence.cast(nativeEmf); return (Properties) openJpaEmf.getUserObject(CompassProductDerivation.COMPASS_INDEX_SETTINGS_USER_OBJECT_KEY); }
/** * Determines whether the specified state manager is managed by an open * broker within the persistence unit of the provided EMF instance. * @param emf OpenJPAEntityManagerFactory * @param sm StateManager * @return true if this state manager is managed by a broker within * this persistence unit. */ public static boolean isManagedBy(OpenJPAEntityManagerFactory emf, Object entity) { // Assert a valid emf was provided, it is open, and the entity is PC if (emf == null || !emf.isOpen() || !ImplHelper.isManageable(entity)) { return false; } // Assert the context is a broker PersistenceCapable pc = (PersistenceCapable)entity; if (!(pc.pcGetGenericContext() instanceof Broker)) { return false; } // Assert the broker is available and open Broker broker = (Broker)pc.pcGetGenericContext(); if (broker == null || broker.isClosed()) { return false; } // Assert the emf associated with the PC is the same as the provided emf OpenJPAEntityManagerFactory eemf = JPAFacadeHelper.toEntityManagerFactory(broker.getBrokerFactory()); if (eemf == emf && eemf.isOpen()) { return true; } return false; }
/** * Returns the Compass Gps instance associated with the given OpenJPA {@link javax.persistence.EntityManager}. * Used in order to perform {@link org.compass.gps.device.jpa.embedded.JpaCompassGps#index()} operation. Note, the index * operation should not be perfomed within a running transaction. */ public static JpaCompassGps getCompassGps(EntityManager em) { EntityManager nativeEm = NativeJpaHelper.extractNativeJpa(em); OpenJPAEntityManagerFactory openJpaEmf = OpenJPAPersistence.cast(nativeEm).getEntityManagerFactory(); return (JpaCompassGps) openJpaEmf.getUserObject(CompassProductDerivation.COMPASS_GPS_USER_OBJECT_KEY); }
/** * Returns the Compass instance assoicated with the given OpenJPA {@link javax.persistence.EntityManager}. * This allows to get a Compass instnace in order to perform search operations for example outside of a JPA * transaction (for performance reasons, mostly there is no need to start a DB transaction). */ public static Compass getCompass(EntityManager em) { EntityManager nativeEm = NativeJpaHelper.extractNativeJpa(em); OpenJPAEntityManagerFactory openJpaEmf = OpenJPAPersistence.cast(nativeEm).getEntityManagerFactory(); return (Compass) openJpaEmf.getUserObject(CompassProductDerivation.COMPASS_USER_OBJECT_KEY); }
/** * Return the underlying broker factory for the given persistence manager * factory facade. */ public static BrokerFactory toBrokerFactory(EntityManagerFactory emf) { if (emf == null) return null; if (!(emf instanceof EntityManagerFactoryImpl)) { Class c = emf.getClass(); try { // either cast here may fail emf = (EntityManagerFactoryImpl) ((OpenJPAEntityManagerFactory) emf).getUserObject(EMF_KEY); } catch (ClassCastException cce) { throw new ArgumentException(_loc.get( "cant-convert-brokerfactory", c), null, null, false); } } return ((EntityManagerFactoryImpl) emf).getBrokerFactory(); }
/** * Return the underlying broker factory for the given persistence manager * factory facade. */ public static BrokerFactory toBrokerFactory(EntityManagerFactory emf) { if (emf == null) return null; if (!(emf instanceof EntityManagerFactoryImpl)) { Class c = emf.getClass(); try { // either cast here may fail emf = (EntityManagerFactoryImpl) ((OpenJPAEntityManagerFactory) emf).getUserObject(EMF_KEY); } catch (ClassCastException cce) { throw new ArgumentException(_loc.get( "cant-convert-brokerfactory", c), null, null, false); } } return ((EntityManagerFactoryImpl) emf).getBrokerFactory(); }
/** * Return the underlying broker factory for the given persistence manager * factory facade. */ public static BrokerFactory toBrokerFactory(EntityManagerFactory emf) { if (emf == null) return null; if (!(emf instanceof EntityManagerFactoryImpl)) { Class c = emf.getClass(); try { // either cast here may fail emf = (EntityManagerFactoryImpl) ((OpenJPAEntityManagerFactory) emf).getUserObject(EMF_KEY); } catch (ClassCastException cce) { throw new ArgumentException(_loc.get( "cant-convert-brokerfactory", c), null, null, false); } } return ((EntityManagerFactoryImpl) emf).getBrokerFactory(); }
/** * Returns the index settings that are configured within the {@link javax.persistence.EntityManager} * configuration. Can be used to configure exteranally a {@link org.compass.gps.device.jpa.embedded.JpaCompassGps} * instnace. */ public Properties getIndexSettings(EntityManager em) { EntityManager nativeEm = NativeJpaHelper.extractNativeJpa(em); OpenJPAEntityManagerFactory openJpaEmf = OpenJPAPersistence.cast(nativeEm).getEntityManagerFactory(); return (Properties) openJpaEmf.getUserObject(CompassProductDerivation.COMPASS_INDEX_SETTINGS_USER_OBJECT_KEY); } }
/** * Return the underlying broker factory for the given persistence manager * factory facade. */ public static BrokerFactory toBrokerFactory(EntityManagerFactory emf) { if (emf == null) return null; if (!(emf instanceof EntityManagerFactoryImpl)) { Class c = emf.getClass(); try { // either cast here may fail emf = (EntityManagerFactoryImpl) ((OpenJPAEntityManagerFactory) emf).getUserObject(EMF_KEY); } catch (ClassCastException cce) { throw new ArgumentException(_loc.get( "cant-convert-brokerfactory", c), null, null, false); } } return ((EntityManagerFactoryImpl) emf).getBrokerFactory(); }
/** * Return the underlying broker factory for the given persistence manager * factory facade. */ public static BrokerFactory toBrokerFactory(EntityManagerFactory emf) { if (emf == null) return null; if (!(emf instanceof EntityManagerFactoryImpl)) { Class c = emf.getClass(); try { // either cast here may fail emf = (EntityManagerFactoryImpl) ((OpenJPAEntityManagerFactory) emf).getUserObject(EMF_KEY); } catch (ClassCastException cce) { throw new ArgumentException(_loc.get( "cant-convert-brokerfactory", c), null, null, false); } } return ((EntityManagerFactoryImpl) emf).getBrokerFactory(); }