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

项目:croquet    文件:EntityManagerProxyFactory.java   
/**
 * Creates a proxy object that will write-replace with a wrapper around the {@link EntityManager}.
 * @param factory a factory to generate EntityManagers.
 * @return the proxied instance.
 */
static EntityManager createProxy(final HibernateEntityManagerFactory factory) {
    final EntityManagerInterceptor handler = new EntityManagerInterceptor(factory);

    final Enhancer e = new Enhancer();

    // make sure we're Serializable and have a write replace method
    e.setInterfaces(new Class[] { EntityManager.class, Serializable.class, IWriteReplace.class });
    e.setSuperclass(Object.class);
    e.setCallback(handler);
    e.setNamingPolicy(new DefaultNamingPolicy() {
        @Override
        public String getClassName(final String prefix,
                                   final String source,
                                   final Object key,
                                   final Predicate names) {
            return super.getClassName("CROQUET_ENTITY_MANAGER_PROXY_" + prefix, source, key, names);
        }
    });

    LOG.trace("Created proxy for an EntityManager");

    return (EntityManager)e.create();
}
项目: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;
}
项目:jipijapa    文件:HibernateQueryCacheStatistics.java   
@Override
public Object invoke(Object... args) {
    String displayQueryName = getQueryName(args);
    EntityManagerFactory entityManagerFactory = getEntityManagerFactory(args);
    if (displayQueryName != null && entityManagerFactory != null) {
        HibernateEntityManagerFactory entityManagerFactoryImpl = (HibernateEntityManagerFactory) entityManagerFactory;
        SessionFactory sessionFactory = entityManagerFactoryImpl.getSessionFactory();
        // convert displayed (transformed by QueryNames) query name to original query name
        if (sessionFactory != null) {
            String[] originalQueryNames = sessionFactory.getStatistics().getQueries();
            if (originalQueryNames != null) {
                for (String originalQueryName : originalQueryNames) {
                    if (QueryName.queryName(originalQueryName).getDisplayName().equals(displayQueryName)) {
                        return originalQueryName;
                    }
                }
            }
        }

    }
    return null;
}
项目:dachs    文件:HibernateLazyIdExtractor.java   
public HibernateLazyIdExtractor(EntityManagerFactory emf)
{
    this.persistenceUnitUtil = emf.getPersistenceUnitUtil();

    final HibernateEntityManagerFactory emFactory = (HibernateEntityManagerFactory) emf;
    this.factory = emFactory.getSessionFactory();
}
项目:pedal-dialect    文件:HibernateProviderAccessSpiImpl.java   
@Override
public String getSchemaName() {
    SessionFactory sf = emf.unwrap(HibernateEntityManagerFactory.class).getSessionFactory();
    SessionFactoryImplementor sfi = (SessionFactoryImplementor) sf;
    String schema = sfi.getSettings().getDefaultSchemaName();
    return schema == null ? "" : schema;
}
项目:pedal-dialect    文件:HibernateProviderAccessSpiImpl.java   
/**
 * @param entityClass Entity class for which the table name is required.
 * @return Table name if the entity class is a single table.
 */
@Override
public String getTableName(Class<? extends Serializable> entityClass) {
    SessionFactory sf = emf.unwrap(HibernateEntityManagerFactory.class).getSessionFactory();
    ClassMetadata metadata = sf.getClassMetadata(entityClass);
    if (metadata instanceof SingleTableEntityPersister) {
        SingleTableEntityPersister step = (SingleTableEntityPersister) metadata;
        return step.getTableName();
    } else {
        return null;
    }
}
项目:croquet    文件:EntityManagerProxyFactory.java   
/**
 * Constructor.
 *
 * @param instance the original instance of the class.
 */
public EntityManagerInterceptor(final HibernateEntityManagerFactory factory) {
    if(factory == null) {
        throw new IllegalArgumentException("HibernateEntityManagerFactory is null");
    }
    this.factory = factory;
}
项目:croquet    文件:CroquetPersistService.java   
@Override
public void begin() {
    if(null != entityManager.get()) {
        throw new IllegalStateException("Work already begun on this thread. " +
            "Looks like you have called UnitOfWork.begin() twice without a balancing call to end() in between.");
    }

    entityManager.set(EntityManagerProxyFactory.createProxy((HibernateEntityManagerFactory)entityManagerFactory));
}
项目:pedal-dialect    文件:HibernateProviderAccessSpiImpl.java   
@Override
public String getSchemaName() {
    SessionFactory sf = emf.unwrap(HibernateEntityManagerFactory.class).getSessionFactory();
    SessionFactoryImplementor sfi = (SessionFactoryImplementor) sf;
    String schema = sfi.getSettings().getDefaultSchemaName();
    return schema == null ? "" : schema;
}
项目:pedal-dialect    文件:HibernateProviderAccessSpiImpl.java   
/**
 * @param entityClass Entity class for which the table name is required.
 * @return Table name if the entity class is a single table.
 */
@Override
public String getTableName(Class<? extends Serializable> entityClass) {
    SessionFactory sf = emf.unwrap(HibernateEntityManagerFactory.class).getSessionFactory();
    ClassMetadata metadata = sf.getClassMetadata(entityClass);
    if (metadata instanceof SingleTableEntityPersister) {
        SingleTableEntityPersister step = (SingleTableEntityPersister) metadata;
        return step.getTableName();
    } else {
        return null;
    }
}
项目:bard    文件:DBManager.java   
public static EntityManager getEntityManager()
    throws MalformedObjectNameException, NotCompliantMBeanException,
    InstanceAlreadyExistsException, MBeanRegistrationException {
    if (emf == null) {
        emf = Persistence.createEntityManagerFactory(
            Util.getConfig().getString("bard.jpa.unit", "prod")
        );
        final SessionFactory sessionFactory =
            ((HibernateEntityManagerFactory) emf).getSessionFactory();

        ObjectName statsName = new ObjectName("org.hibernate:type=statistics");
        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();

        final Statistics statistics = sessionFactory.getStatistics();
        statistics.setStatisticsEnabled(true);
        Object statisticsMBean = Proxy.newProxyInstance(DBManager.class.getClassLoader(),
            new Class<?>[] {StatisticsMXBean.class}, new InvocationHandler() {

                @Override
                public Object invoke(Object proxy, Method method, Object[] args)
                    throws Throwable {
                    return method.invoke(statistics, args);
                }
            });

        mbeanServer.registerMBean(statisticsMBean, statsName);

    }
    return emf.createEntityManager();
}
项目:Hibernate-Search-GenericJPA    文件:HibernateSynchronizedUpdateSourceProvider.java   
@Override
public SynchronizedUpdateSource getUpdateSource(
        ExtendedSearchIntegrator searchIntegrator,
        Map<Class<?>, RehashedTypeMetadata> rehashedTypeMetadataPerIndexRoot,
        Map<Class<?>, List<Class<?>>> containedInIndexOf,
        Properties properties,
        EntityManagerFactory emf,
        TransactionManager transactionManager,
        Set<Class<?>> indexRelevantEntities) {
    HibernateEntityManagerFactory hibernateEntityManagerFactory =
            (HibernateEntityManagerFactory) emf;
    SessionFactoryImpl sessionFactory = (SessionFactoryImpl) hibernateEntityManagerFactory.getSessionFactory();
    ServiceRegistry serviceRegistry = sessionFactory.getServiceRegistry();
    EventListenerRegistry listenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );

    HibernateUpdateSource updateSource = new HibernateUpdateSource();
    updateSource.initialize( searchIntegrator );

    listenerRegistry.addDuplicationStrategy( new DuplicationStrategyImpl( HibernateUpdateSource.class ) );

    listenerRegistry.appendListeners( EventType.POST_INSERT, updateSource );
    listenerRegistry.appendListeners( EventType.POST_UPDATE, updateSource );
    listenerRegistry.appendListeners( EventType.POST_DELETE, updateSource );
    listenerRegistry.appendListeners( EventType.POST_COLLECTION_RECREATE, updateSource );
    listenerRegistry.appendListeners( EventType.POST_COLLECTION_REMOVE, updateSource );
    listenerRegistry.appendListeners( EventType.POST_COLLECTION_UPDATE, updateSource );

    return updateSource;
}
项目: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;
}
项目:spring-data    文件:Idm4jApplication.java   
@Bean  
public SessionFactory sessionFactory(HibernateEntityManagerFactory hemf){  
    return hemf.getSessionFactory();  
}
项目:ignite-jpa    文件:TestOgm.java   
private static TransactionManager extractJBossTransactionManager(EntityManagerFactory factory) {
    SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) ( (HibernateEntityManagerFactory) factory ).getSessionFactory();
    return sessionFactory.getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager();
}
项目:springJpaKata    文件:JmxConfig.java   
@Bean
@DependsOn("entityManagerFactory")
public Statistics statisticsService(EntityManagerFactory entityManagerFactory) {
    SessionFactory sf = ((HibernateEntityManagerFactory) entityManagerFactory).getSessionFactory();
    return sf.getStatistics();
}
项目:random-jpa    文件:MockEntityManagerProvider.java   
private MockEntityManagerProvider() {
    this.entityManager = Mockito.mock(HibernateEntityManager.class);
    this.entityManagerFactory = Mockito.mock(HibernateEntityManagerFactory.class);
    this.metamodel = Mockito.mock(Metamodel.class);
}
项目:elpaaso-core    文件:HibernateStatisticsFactoryBean.java   
@Override
public Statistics getObject() throws Exception {
  SessionFactory sessionFactory = ((HibernateEntityManagerFactory) entityManagerFactory).getSessionFactory();
  return sessionFactory.getStatistics();
}
项目:spring-data-jpa-datatables    文件:Config.java   
@Bean
public SessionFactory sessionFactory(AbstractEntityManagerFactoryBean entityManagerFactory)
    throws SQLException {
  return ((HibernateEntityManagerFactory) entityManagerFactory.getObject()).getSessionFactory();
}
项目:croquet    文件:EntityManagerProxyFactory.java   
public EntityManagerWrapper(final HibernateEntityManagerFactory factory) {
    this.factory = factory;
}