Java 类org.hibernate.ejb.HibernateEntityManagerFactory 实例源码

项目:hibernate4-memcached    文件:QueryCacheTest.java   
@Test
public void createQueryCacheAndEvictAllThenRetry() throws Exception {
    List<Author> beforeResults = getAuthorsWithQuery("Author query", "어느나라");

    log.warn("#####################################################################");

    HibernateEntityManagerFactory entityManagerFactory = (HibernateEntityManagerFactory) EntityTestUtils.getEntityManagerFactory();
    org.hibernate.Cache cache = entityManagerFactory.getSessionFactory().getCache();
    cache.evictEntityRegions();
    cache.evictQueryRegions();
    cache.evictDefaultQueryRegion();
    cache.evictCollectionRegions();

    log.warn("just eviected all.");
    List<Author> againResults = getAuthorsWithQuery("Author query again after evict all", "어느나라");

    assertThat(againResults).isEqualTo(beforeResults);
    log.warn("#####################################################################");
}
项目:jipijapa    文件:HibernateQueryCacheStatistics.java   
private org.hibernate.stat.QueryStatistics getStatistics(EntityManagerFactory entityManagerFactory, String displayQueryName) {
    HibernateEntityManagerFactory entityManagerFactoryImpl = (HibernateEntityManagerFactory) entityManagerFactory;
    SessionFactory sessionFactory = entityManagerFactoryImpl.getSessionFactory();
    // convert displayed (transformed by QueryNames) query name to original query name to look up query statistics
    if (sessionFactory != null) {
        String[] originalQueryNames = sessionFactory.getStatistics().getQueries();
        if (originalQueryNames != null) {
            for (String originalQueryName : originalQueryNames) {
                if (QueryName.queryName(originalQueryName).getDisplayName().equals(displayQueryName)) {
                    return sessionFactory.getStatistics().getQueryStatistics(originalQueryName);
                }
            }
        }
    }
    return null;
}
项目:lams    文件:HibernateJpaSessionFactoryBean.java   
@Override
public SessionFactory getObject() {
    EntityManagerFactory emf = getEntityManagerFactory();
    Assert.isInstanceOf(HibernateEntityManagerFactory.class, emf);
    return ((HibernateEntityManagerFactory) emf).getSessionFactory();
}
项目:spring-entity-listener    文件:HibernateEntityListenersAdapter.java   
@PostConstruct
public void findMethods() {
    for (Object listener : listeners) {
        findMethodsForListener(listener);
    }

    HibernateEntityManagerFactory hemf = (HibernateEntityManagerFactory) emf;
    SessionFactory sf = hemf.getSessionFactory();
    registry = ((SessionFactoryImpl) sf).getServiceRegistry().getService(EventListenerRegistry.class);
}
项目:spring-entity-listener    文件:HibernateEntityListenersConfigurer.java   
@PostConstruct
public void registerListeners() {
    HibernateEntityManagerFactory hemf = (HibernateEntityManagerFactory) emf;
    SessionFactory sf = hemf.getSessionFactory();
    EventListenerRegistry registry = ((SessionFactoryImpl) sf).getServiceRegistry().getService(
            EventListenerRegistry.class);

    registry.getEventListenerGroup(EventType.PRE_INSERT).appendListener(listener);
    registry.getEventListenerGroup(EventType.POST_COMMIT_INSERT).appendListener(listener);
    registry.getEventListenerGroup(EventType.PRE_UPDATE).appendListener(listener);
    registry.getEventListenerGroup(EventType.POST_COMMIT_UPDATE).appendListener(listener);
    registry.getEventListenerGroup(EventType.PRE_DELETE).appendListener(listener);
    registry.getEventListenerGroup(EventType.POST_COMMIT_DELETE).appendListener(listener);
    registry.getEventListenerGroup(EventType.POST_LOAD).appendListener(listener);
}
项目:debop4j    文件:JpaTestBase.java   
/** Get JBoss TM out of Hibernate */
public static TransactionManager extractJBossTransactionManager(EntityManagerFactory factory) {
    if (log.isDebugEnabled())
        log.debug("TransactionManager를 꺼냅니다.");
    SessionFactoryImplementor sessionFactory =
            (SessionFactoryImplementor) ((HibernateEntityManagerFactory) factory).getSessionFactory();
    return sessionFactory.getServiceRegistry().getService(JtaPlatform.class).retrieveTransactionManager();
}
项目:jipijapa    文件:HibernateCollectionStatistics.java   
private org.hibernate.stat.Statistics getBaseStatistics(EntityManagerFactory entityManagerFactory) {
    HibernateEntityManagerFactory entityManagerFactoryImpl = (HibernateEntityManagerFactory) entityManagerFactory;
    SessionFactory sessionFactory = entityManagerFactoryImpl.getSessionFactory();
    if (sessionFactory != null) {
        return sessionFactory.getStatistics();
    }
    return null;
}
项目:jipijapa    文件:HibernateCollectionStatistics.java   
private CollectionStatistics getStatistics(final EntityManagerFactory entityManagerFactory, String collectionName) {
    HibernateEntityManagerFactory entityManagerFactoryImpl = (HibernateEntityManagerFactory) entityManagerFactory;
    SessionFactory sessionFactory = entityManagerFactoryImpl.getSessionFactory();
    if (sessionFactory != null) {
        return sessionFactory.getStatistics().getCollectionStatistics(collectionName);
    }
    return null;
}
项目:jipijapa    文件:HibernateEntityStatistics.java   
private org.hibernate.stat.Statistics getBaseStatistics(EntityManagerFactory entityManagerFactory) {
    HibernateEntityManagerFactory entityManagerFactoryImpl = (HibernateEntityManagerFactory) entityManagerFactory;
    SessionFactory sessionFactory = entityManagerFactoryImpl.getSessionFactory();
    if (sessionFactory != null) {
        return sessionFactory.getStatistics();
    }
    return null;
}
项目:jipijapa    文件:HibernateEntityStatistics.java   
private org.hibernate.stat.EntityStatistics getStatistics(EntityManagerFactory entityManagerFactory, String entityName) {
    HibernateEntityManagerFactory entityManagerFactoryImpl = (HibernateEntityManagerFactory) entityManagerFactory;
    SessionFactory sessionFactory = entityManagerFactoryImpl.getSessionFactory();
    if (sessionFactory != null) {
        return sessionFactory.getStatistics().getEntityStatistics(entityName);
    }
    return null;
}
项目:jipijapa    文件:HibernateStatistics.java   
static final org.hibernate.stat.Statistics getStatistics(final EntityManagerFactory entityManagerFactory) {
    HibernateEntityManagerFactory entityManagerFactoryImpl = (HibernateEntityManagerFactory) entityManagerFactory;
    SessionFactory sessionFactory = entityManagerFactoryImpl.getSessionFactory();
    if (sessionFactory != null) {
        return sessionFactory.getStatistics();
    }
    return null;
}
项目:jipijapa    文件:HibernateQueryCacheStatistics.java   
private org.hibernate.stat.Statistics getBaseStatistics(EntityManagerFactory entityManagerFactory) {
    HibernateEntityManagerFactory entityManagerFactoryImpl = (HibernateEntityManagerFactory) entityManagerFactory;
    SessionFactory sessionFactory = entityManagerFactoryImpl.getSessionFactory();
    if (sessionFactory != null) {
        return sessionFactory.getStatistics();
    }
    return null;
}
项目:jipijapa    文件:HibernateEntityCacheStatistics.java   
private org.hibernate.stat.Statistics getBaseStatistics(EntityManagerFactory entityManagerFactory) {
    HibernateEntityManagerFactory entityManagerFactoryImpl = (HibernateEntityManagerFactory) entityManagerFactory;
    SessionFactory sessionFactory = entityManagerFactoryImpl.getSessionFactory();
    if (sessionFactory != null) {
        return sessionFactory.getStatistics();
    }
    return null;
}
项目:jipijapa    文件:HibernateEntityCacheStatistics.java   
org.hibernate.stat.SecondLevelCacheStatistics getStatistics(EntityManagerFactoryAccess entityManagerFactoryaccess, PathAddress pathAddress) {
    String scopedPersistenceUnitName = pathAddress.getValue(HibernateStatistics.PROVIDER_LABEL);
    HibernateEntityManagerFactory entityManagerFactoryImpl = (HibernateEntityManagerFactory) entityManagerFactoryaccess.entityManagerFactory(scopedPersistenceUnitName);
    SessionFactory sessionFactory = entityManagerFactoryImpl.getSessionFactory();
    if (sessionFactory != null) {
        // The entity class name is prefixed by the application scoped persistence unit name
        return sessionFactory.getStatistics().getSecondLevelCacheStatistics(scopedPersistenceUnitName + "." +
                pathAddress.getValue(HibernateStatistics.ENTITYCACHE));
    }
    return null;
}
项目:spring4-understanding    文件:HibernateEntityManagerFactoryIntegrationTests.java   
public void testCanCastNativeEntityManagerFactoryToHibernateEntityManagerFactoryImpl() {
    EntityManagerFactoryInfo emfi = (EntityManagerFactoryInfo) entityManagerFactory;
    assertTrue(emfi.getNativeEntityManagerFactory() instanceof HibernateEntityManagerFactory);
}
项目:spring-entity-listener    文件:SpringEntityListenersConfigurer.java   
@PostConstruct
public void registerListeners() {
    // get registry so we can add listeners.
    HibernateEntityManagerFactory hemf = (HibernateEntityManagerFactory) entityManagerFactory;
    SessionFactory sf = hemf.getSessionFactory();
    EventListenerRegistry registry = ((SessionFactoryImpl) sf).getServiceRegistry().getService(
            EventListenerRegistry.class);

    final Set<Object> listeners = new HashSet<Object>();

    EntityManager entityManager = null;
    try {
        entityManager = hemf.createEntityManager();
        // for every entity known to the system...
        for (EntityType<?> entity : entityManager.getMetamodel().getEntities()) {

            // ... register event listeners for it.
            if (entity.getJavaType().isAnnotationPresent(SpringEntityListeners.class)) {
                SpringEntityListeners annotation = (SpringEntityListeners) entity.getJavaType().getAnnotation(
                        SpringEntityListeners.class);
                for (Class<?> beanClass : annotation.value()) {
                    Map<String, ?> map = context.getBeansOfType(beanClass);
                    listeners.addAll(map.values());
                }
            }
        }
    } finally {
        if (entityManager != null) {
            entityManager.close();
        }
    }

    // register adapter and listeners.
    HibernateEntityListenersAdapter adapter = new HibernateEntityListenersAdapter(new ArrayList<Object>(listeners),
            entityManagerFactory);
    registry.getEventListenerGroup(EventType.PRE_INSERT).appendListener(adapter);
    registry.getEventListenerGroup(EventType.POST_COMMIT_INSERT).appendListener(adapter);
    registry.getEventListenerGroup(EventType.PRE_UPDATE).appendListener(adapter);
    registry.getEventListenerGroup(EventType.POST_COMMIT_UPDATE).appendListener(adapter);
    registry.getEventListenerGroup(EventType.PRE_DELETE).appendListener(adapter);
    registry.getEventListenerGroup(EventType.POST_COMMIT_DELETE).appendListener(adapter);
    registry.getEventListenerGroup(EventType.POST_LOAD).appendListener(adapter);
}
项目:class-guard    文件:HibernateJpaSessionFactoryBean.java   
public SessionFactory getObject() {
    EntityManagerFactory emf = getEntityManagerFactory();
    Assert.isInstanceOf(HibernateEntityManagerFactory.class, emf);
    return ((HibernateEntityManagerFactory) emf).getSessionFactory();
}
项目:class-guard    文件:HibernateJpaVendorAdapter.java   
@Override
public Class<? extends EntityManagerFactory> getEntityManagerFactoryInterface() {
    return HibernateEntityManagerFactory.class;
}
项目:class-guard    文件:HibernateEntityManagerFactoryIntegrationTests.java   
public void testCanCastNativeEntityManagerFactoryToHibernateEntityManagerFactoryImpl() {
    EntityManagerFactoryInfo emfi = (EntityManagerFactoryInfo) entityManagerFactory;
    assertTrue(emfi.getNativeEntityManagerFactory() instanceof HibernateEntityManagerFactory);
}
项目:debop4j    文件:TestHelper.java   
public static void dropSchemaAndDatabase(EntityManagerFactory emf) {
    dropSchemaAndDatabase(((HibernateEntityManagerFactory) emf).getSessionFactory());
}
项目:books    文件:SessionUtil.java   
/**
 * Returns an instance of the current session.
 * 
 * @return Instance of the current session
 */
public static Session getCurrentSession() {
    SessionFactory sessionFactory = ((HibernateEntityManagerFactory) EMF.get()).getSessionFactory();
    return sessionFactory.getCurrentSession();
}