本文整理汇总了Java中org.hibernate.stat.Statistics.setStatisticsEnabled方法的典型用法代码示例。如果您正苦于以下问题:Java Statistics.setStatisticsEnabled方法的具体用法?Java Statistics.setStatisticsEnabled怎么用?Java Statistics.setStatisticsEnabled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.stat.Statistics
的用法示例。
在下文中一共展示了Statistics.setStatisticsEnabled方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: perfTest
import org.hibernate.stat.Statistics; //导入方法依赖的package包/类
@Test(enabled = false)
public <T extends ObjectType> void perfTest() throws Exception {
Statistics stats = getFactory().getStatistics();
stats.setStatisticsEnabled(true);
final File OBJECTS_FILE = new File("./src/test/resources/10k-users.xml");
List<PrismObject<? extends Objectable>> elements = prismContext.parserFor(OBJECTS_FILE).parseObjects();
long previousCycle = 0;
long time = System.currentTimeMillis();
for (int i = 0; i < elements.size(); i++) {
if (i % 500 == 0) {
LOGGER.info("Previous cycle time {}. Next cycle: {}", new Object[]{
(System.currentTimeMillis() - time - previousCycle), i});
previousCycle = System.currentTimeMillis() - time;
}
PrismObject<T> object = (PrismObject<T>) elements.get(i);
repositoryService.addObject(object, null, new OperationResult("add performance test"));
}
LOGGER.info("Time to add objects ({}): {}",
new Object[]{elements.size(), (System.currentTimeMillis() - time)});
stats.logSummary();
}
示例2: testSessionStats
import org.hibernate.stat.Statistics; //导入方法依赖的package包/类
public void testSessionStats() throws Exception {
SessionFactory sf = getSessions();
Statistics stats = sf.getStatistics();
boolean isStats = stats.isStatisticsEnabled();
stats.clear();
stats.setStatisticsEnabled(true);
Session s = sf.openSession();
assertEquals( 1, stats.getSessionOpenCount() );
s.close();
assertEquals( 1, stats.getSessionCloseCount() );
s = sf.openSession();
Transaction tx = s.beginTransaction();
A a = new A();
a.setName("mya");
s.save(a);
a.setName("b");
tx.commit();
s.close();
assertEquals( 1, stats.getFlushCount() );
s = sf.openSession();
tx = s.beginTransaction();
String hql = "from " + A.class.getName();
Query q = s.createQuery(hql);
q.list();
tx.commit();
s.close();
assertEquals(1, stats.getQueryExecutionCount() );
assertEquals(1, stats.getQueryStatistics(hql).getExecutionCount() );
stats.setStatisticsEnabled(isStats);
}
示例3: testSessionStatistics
import org.hibernate.stat.Statistics; //导入方法依赖的package包/类
public void testSessionStatistics() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Statistics stats = getSessions().getStatistics();
stats.clear();
boolean isStats = stats.isStatisticsEnabled();
stats.setStatisticsEnabled(true);
Continent europe = fillDb(s);
tx.commit();
s.clear();
tx = s.beginTransaction();
SessionStatistics sessionStats = s.getStatistics();
assertEquals( 0, sessionStats.getEntityKeys().size() );
assertEquals( 0, sessionStats.getEntityCount() );
assertEquals( 0, sessionStats.getCollectionKeys().size() );
assertEquals( 0, sessionStats.getCollectionCount() );
europe = (Continent) s.get( Continent.class, europe.getId() );
Hibernate.initialize( europe.getCountries() );
Hibernate.initialize( europe.getCountries().iterator().next() );
assertEquals( 2, sessionStats.getEntityKeys().size() );
assertEquals( 2, sessionStats.getEntityCount() );
assertEquals( 1, sessionStats.getCollectionKeys().size() );
assertEquals( 1, sessionStats.getCollectionCount() );
tx.commit();
s.close();
stats.setStatisticsEnabled( isStats);
}
示例4: checkFetchJoin
import org.hibernate.stat.Statistics; //导入方法依赖的package包/类
@Test
public void checkFetchJoin() {
Statistics statistics = sessionFactory.getStatistics();
statistics.setStatisticsEnabled(true);
DataTablesOutput<A> output = getOutput(input);
assertThat(output.getRecordsFiltered()).isEqualTo(3);
assertThat(statistics.getPrepareStatementCount()).isEqualTo(2);
assertThat(statistics.getEntityLoadCount()).isEqualTo(3 /* A */ + 3 /* C */);
}
示例5: getEntityManager
import org.hibernate.stat.Statistics; //导入方法依赖的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();
}
示例6: JobsMemoryMonitorRunner
import org.hibernate.stat.Statistics; //导入方法依赖的package包/类
public JobsMemoryMonitorRunner(Statistics statistics, SchedulerState schedulerState) {
statistics.setStatisticsEnabled(true);
this.stats = statistics;
this.schedulerState = schedulerState;
}
示例7: getHibernateStatistics
import org.hibernate.stat.Statistics; //导入方法依赖的package包/类
public Statistics getHibernateStatistics() {
Statistics stats = this.getSessionFactory().getStatistics();
stats.setStatisticsEnabled(true);
return stats;
}