当前位置: 首页>>代码示例>>Java>>正文


Java HibernateEntityManagerFactory类代码示例

本文整理汇总了Java中org.hibernate.jpa.HibernateEntityManagerFactory的典型用法代码示例。如果您正苦于以下问题:Java HibernateEntityManagerFactory类的具体用法?Java HibernateEntityManagerFactory怎么用?Java HibernateEntityManagerFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HibernateEntityManagerFactory类属于org.hibernate.jpa包,在下文中一共展示了HibernateEntityManagerFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createProxy

import org.hibernate.jpa.HibernateEntityManagerFactory; //导入依赖的package包/类
/**
 * 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();
}
 
开发者ID:Metrink,项目名称:croquet,代码行数:29,代码来源:EntityManagerProxyFactory.java

示例2: getStatistics

import org.hibernate.jpa.HibernateEntityManagerFactory; //导入依赖的package包/类
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;
}
 
开发者ID:jipijapa,项目名称:jipijapa,代码行数:17,代码来源:HibernateQueryCacheStatistics.java

示例3: invoke

import org.hibernate.jpa.HibernateEntityManagerFactory; //导入依赖的package包/类
@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;
}
 
开发者ID:jipijapa,项目名称:jipijapa,代码行数:23,代码来源:HibernateQueryCacheStatistics.java

示例4: HibernateLazyIdExtractor

import org.hibernate.jpa.HibernateEntityManagerFactory; //导入依赖的package包/类
public HibernateLazyIdExtractor(EntityManagerFactory emf)
{
	this.persistenceUnitUtil = emf.getPersistenceUnitUtil();
	
	final HibernateEntityManagerFactory emFactory = (HibernateEntityManagerFactory) emf;
	this.factory = emFactory.getSessionFactory();
}
 
开发者ID:ethlo,项目名称:dachs,代码行数:8,代码来源:HibernateLazyIdExtractor.java

示例5: getSchemaName

import org.hibernate.jpa.HibernateEntityManagerFactory; //导入依赖的package包/类
@Override
public String getSchemaName() {
    SessionFactory sf = emf.unwrap(HibernateEntityManagerFactory.class).getSessionFactory();
    SessionFactoryImplementor sfi = (SessionFactoryImplementor) sf;
    String schema = sfi.getSettings().getDefaultSchemaName();
    return schema == null ? "" : schema;
}
 
开发者ID:eclecticlogic,项目名称:pedal-dialect,代码行数:8,代码来源:HibernateProviderAccessSpiImpl.java

示例6: getTableName

import org.hibernate.jpa.HibernateEntityManagerFactory; //导入依赖的package包/类
/**
 * @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;
    }
}
 
开发者ID:eclecticlogic,项目名称:pedal-dialect,代码行数:16,代码来源:HibernateProviderAccessSpiImpl.java

示例7: EntityManagerInterceptor

import org.hibernate.jpa.HibernateEntityManagerFactory; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:Metrink,项目名称:croquet,代码行数:12,代码来源:EntityManagerProxyFactory.java

示例8: begin

import org.hibernate.jpa.HibernateEntityManagerFactory; //导入依赖的package包/类
@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));
}
 
开发者ID:Metrink,项目名称:croquet,代码行数:10,代码来源:CroquetPersistService.java

示例9: getEntityManager

import org.hibernate.jpa.HibernateEntityManagerFactory; //导入依赖的package包/类
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();
}
 
开发者ID:wb14123,项目名称:bard,代码行数:31,代码来源:DBManager.java

示例10: getUpdateSource

import org.hibernate.jpa.HibernateEntityManagerFactory; //导入依赖的package包/类
@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;
}
 
开发者ID:Hotware,项目名称:Hibernate-Search-GenericJPA,代码行数:30,代码来源:HibernateSynchronizedUpdateSourceProvider.java

示例11: getBaseStatistics

import org.hibernate.jpa.HibernateEntityManagerFactory; //导入依赖的package包/类
private org.hibernate.stat.Statistics getBaseStatistics(EntityManagerFactory entityManagerFactory) {
    HibernateEntityManagerFactory entityManagerFactoryImpl = (HibernateEntityManagerFactory) entityManagerFactory;
    SessionFactory sessionFactory = entityManagerFactoryImpl.getSessionFactory();
    if (sessionFactory != null) {
        return sessionFactory.getStatistics();
    }
    return null;
}
 
开发者ID:jipijapa,项目名称:jipijapa,代码行数:9,代码来源:HibernateCollectionStatistics.java

示例12: getStatistics

import org.hibernate.jpa.HibernateEntityManagerFactory; //导入依赖的package包/类
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;
}
 
开发者ID:jipijapa,项目名称:jipijapa,代码行数:9,代码来源:HibernateCollectionStatistics.java

示例13: getStatistics

import org.hibernate.jpa.HibernateEntityManagerFactory; //导入依赖的package包/类
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;
}
 
开发者ID:jipijapa,项目名称:jipijapa,代码行数:9,代码来源:HibernateEntityStatistics.java

示例14: getStatistics

import org.hibernate.jpa.HibernateEntityManagerFactory; //导入依赖的package包/类
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;
}
 
开发者ID:jipijapa,项目名称:jipijapa,代码行数:9,代码来源:HibernateStatistics.java

示例15: getStatistics

import org.hibernate.jpa.HibernateEntityManagerFactory; //导入依赖的package包/类
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;
}
 
开发者ID:jipijapa,项目名称:jipijapa,代码行数:13,代码来源:HibernateEntityCacheStatistics.java


注:本文中的org.hibernate.jpa.HibernateEntityManagerFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。