List of usage examples for org.hibernate.stat Statistics clear
void clear();
From source file:models.papmon.HibernateStat.java
License:Open Source License
public HibernateStat(Date refDate) { created = refDate;/*from ww w . ja v a 2 s. c o m*/ Session session = (Session) JPA.em().getDelegate(); Statistics stats = session.getSessionFactory().getStatistics(); queryExecutionCount = stats.getQueryExecutionCount(); queryExecutionMaxTime = stats.getQueryExecutionMaxTime(); sessionOpenCount = stats.getSessionOpenCount(); sessionCloseCount = stats.getSessionCloseCount(); entityLoadCount = stats.getEntityLoadCount(); entityInsertCount = stats.getEntityInsertCount(); entityUpdateCount = stats.getEntityUpdateCount(); entityDeleteCount = stats.getEntityDeleteCount(); entityFetchCount = stats.getEntityFetchCount(); queryCacheHitCount = stats.getQueryCacheHitCount(); queryCacheMissCount = stats.getQueryCacheMissCount(); queryCachePutCount = stats.getQueryCachePutCount(); secondLevelCacheHitCount = stats.getSecondLevelCacheHitCount(); secondLevelCacheMissCount = stats.getSecondLevelCacheMissCount(); secondLevelCachePutCount = stats.getSecondLevelCachePutCount(); stats.clear(); }
From source file:net.firejack.platform.processor.statistics.StatisticsProcessor.java
License:Apache License
@Scheduled(cron = "0 0/5 * * * *") public void schedulerStatisticsHandler() { if (templates != null) { for (HibernateTemplate template : templates) { SessionFactory sessionFactory = template.getSessionFactory(); Statistics statistics = sessionFactory.getStatistics(); if (statistics.isStatisticsEnabled()) { LogTransaction logTransaction = new LogTransaction(); logTransaction.setPackageLookup(OpenFlameSecurityConstants.getPackageLookup()); logTransaction.setTransactions(statistics.getSuccessfulTransactionCount()); logTransaction.setEntitiesLoaded(statistics.getEntityLoadCount()); logTransaction.setEntitiesInserted(statistics.getEntityInsertCount()); logTransaction.setEntitiesUpdated(statistics.getEntityUpdateCount()); logTransaction.setEntitiesDeleted(statistics.getEntityDeleteCount()); logTransaction.setEntitiesFetched(statistics.getEntityFetchCount()); logTransaction.setCollectionsLoaded(statistics.getCollectionLoadCount()); logTransaction.setCollectionsRecreated(statistics.getCollectionRecreateCount()); logTransaction.setCollectionsUpdated(statistics.getCollectionUpdateCount()); logTransaction.setCollectionsRemoved(statistics.getCollectionRemoveCount()); logTransaction.setCollectionsFetched(statistics.getCollectionFetchCount()); logTransaction.setMaxQueryTime(statistics.getQueryExecutionMaxTime()); Date hourlyDate = new Date(); logTransaction.setHourPeriod(DateUtils.truncate(hourlyDate, Calendar.HOUR).getTime()); logTransaction.setDayPeriod(DateUtils.truncate(hourlyDate, Calendar.DAY_OF_MONTH).getTime()); logTransaction.setWeekPeriod(DateUtils.truncateDateToWeek(hourlyDate).getTime()); logTransaction.setMonthPeriod(DateUtils.truncate(hourlyDate, Calendar.MONTH).getTime()); OPFEngine.StatisticsService.saveLogTransaction(logTransaction); statistics.clear(); } else { logger.warn("Hibernate Statistics is disabled."); }/* w w w. j a v a2 s .c om*/ } } }
From source file:ome.server.itests.scalability.SqlHibernateDatasourceComparisonTest.java
License:Open Source License
@Test(enabled = false) public void testCompareDirect() throws Exception { prime();/*from w w w . j a v a 2 s. c o m*/ Statistics rawstats = rawsf.getStatistics(); Statistics omestats = omesf.getStatistics(); System.out.println("Clearing stats"); rawstats.clear(); omestats.clear(); Category.getInstance("org.hibernate.SQL").setLevel(Level.DEBUG); // callHibernateAlone(); callHibernateChannels(); // callHibernateLinks(); System.out.println("**** RawStats"); rawstats.logSummary(); // callOmeroAlone(); callOmeroChannels(); // callOmeroLinks(); System.out.println("**** OmeStats"); omestats.logSummary(); System.out.println(new Report()); }
From source file:org.beangle.ems.dev.hibernate.web.action.CacheAction.java
License:Open Source License
public String index() { Statistics statistics = sessionFactory.getStatistics(); Date lastUpdate = new Date(); Date activation = null;//from w ww. j av a 2s. co m Date deactivation = null; List<Long> generalStatistics = CollectUtils.newArrayList(18); final String action = get("do"); final StringBuilder info = new StringBuilder(512); if ("activate".equals(action) && !statistics.isStatisticsEnabled()) { statistics.setStatisticsEnabled(true); activation = new Date(); getSession().put("hibernate.stat.activation", activation); getSession().remove("hibernate.stat.deactivation"); info.append("Statistics enabled\n"); } else if ("deactivate".equals(action) && statistics.isStatisticsEnabled()) { statistics.setStatisticsEnabled(false); deactivation = new Date(); getSession().put("hibernate.stat.deactivation", deactivation); activation = (Date) getSession().get("hibernate.stat.activation"); info.append("Statistics disabled\n"); } else if ("clear".equals(action)) { activation = null; deactivation = null; statistics.clear(); getSession().remove("hibernate.stat.activation"); getSession().remove("hibernate.stat.deactivation"); generalStatistics.clear(); info.append("Statistics cleared\n"); } else { activation = (Date) getSession().get("hibernate.stat.activation"); deactivation = (Date) getSession().get("hibernate.stat.deactivation"); } if (info.length() > 0) addMessage(info.toString()); boolean active = statistics.isStatisticsEnabled(); if (active) { generalStatistics.add(statistics.getConnectCount()); generalStatistics.add(statistics.getFlushCount()); generalStatistics.add(statistics.getPrepareStatementCount()); generalStatistics.add(statistics.getCloseStatementCount()); generalStatistics.add(statistics.getSessionCloseCount()); generalStatistics.add(statistics.getSessionOpenCount()); generalStatistics.add(statistics.getTransactionCount()); generalStatistics.add(statistics.getSuccessfulTransactionCount()); generalStatistics.add(statistics.getOptimisticFailureCount()); } put("active", active); put("lastUpdate", lastUpdate); if (null != activation) { if (null != deactivation) { put("duration", deactivation.getTime() - activation.getTime()); } else { put("duration", lastUpdate.getTime() - activation.getTime()); } } put("activation", activation); put("deactivation", deactivation); put("generalStatistics", generalStatistics); return forward(); }
From source file:org.cast.cwm.admin.DatabaseStatisticsPage.java
License:Open Source License
public DatabaseStatisticsPage(PageParameters params) { super(params); Statistics stats = Databinder.getHibernateSessionFactory().getStatistics(); if (stats.isStatisticsEnabled()) { add(new Label("count", String.valueOf(stats.getQueryExecutionCount()))); add(new Label("cloads", String.valueOf(stats.getCollectionLoadCount()))); add(new Label("worst", stats.getQueryExecutionMaxTimeQueryString())); // Worked in SNUDLE, why am I getting no output here? add(new Label("worsttime", String.valueOf(stats.getQueryExecutionMaxTime()))); add(new Label("qchit", String.valueOf(stats.getQueryCacheHitCount()))); add(new Label("qcmiss", String.valueOf(stats.getQueryCacheMissCount()))); } else {// www . j ava 2 s. co m stats.setStatisticsEnabled(true); add(new Label("count", "--")); add(new Label("cloads", "--")); add(new Label("worst", "--")); add(new Label("worsttime", "--")); add(new Label("qchit", "--")); add(new Label("qcmiss", "--")); } stats.clear(); add(new Link<Void>("off") { private static final long serialVersionUID = 1L; @Override public void onClick() { Databinder.getHibernateSessionFactory().getStatistics().setStatisticsEnabled(false); setResponsePage(getApplication().getHomePage()); } }); }
From source file:org.infinispan.test.hibernate.cache.commons.functional.ReadOnlyTest.java
License:LGPL
@Test public void testEmptySecondLevelCacheEntry() { sessionFactory().getCache().evictCollectionRegion(Item.class.getName() + ".items"); Statistics stats = sessionFactory().getStatistics(); stats.clear(); InfinispanBaseRegion region = TEST_SESSION_ACCESS.getRegion(sessionFactory(), Item.class.getName() + ".items"); assertEquals(0, region.getElementCountInMemory()); }
From source file:org.infinispan.test.hibernate.cache.commons.functional.ReadOnlyTest.java
License:LGPL
@Test public void testInsertDeleteEntity() throws Exception { final Statistics stats = sessionFactory().getStatistics(); stats.clear(); final Item item = new Item("chris", "Chris's Item"); withTxSession(s -> s.persist(item)); log.info("Entry persisted, let's load and delete it."); withTxSession(s -> {//from ww w . j a v a 2s. co m Item found = s.load(Item.class, item.getId()); log.info(stats.toString()); assertEquals(item.getDescription(), found.getDescription()); assertEquals(0, stats.getSecondLevelCacheMissCount()); assertEquals(1, stats.getSecondLevelCacheHitCount()); s.delete(found); }); }
From source file:org.infinispan.test.hibernate.cache.commons.functional.ReadOnlyTest.java
License:LGPL
@Test public void testInsertClearCacheDeleteEntity() throws Exception { final Statistics stats = sessionFactory().getStatistics(); stats.clear(); final Item item = new Item("chris", "Chris's Item"); withTxSession(s -> s.persist(item)); assertEquals(0, stats.getSecondLevelCacheMissCount()); assertEquals(0, stats.getSecondLevelCacheHitCount()); assertEquals(1, stats.getSecondLevelCachePutCount()); log.info("Entry persisted, let's load and delete it."); cleanupCache();//from w w w .j av a 2 s. c o m TIME_SERVICE.advance(1); withTxSession(s -> { Item found = s.load(Item.class, item.getId()); log.info(stats.toString()); assertEquals(item.getDescription(), found.getDescription()); assertEquals(1, stats.getSecondLevelCacheMissCount()); assertEquals(0, stats.getSecondLevelCacheHitCount()); assertEquals(2, stats.getSecondLevelCachePutCount()); s.delete(found); }); }
From source file:org.infinispan.test.hibernate.cache.commons.functional.ReadWriteTest.java
License:LGPL
@Test public void testCollectionCache() throws Exception { final Statistics stats = sessionFactory().getStatistics(); stats.clear(); final Item item = new Item("chris", "Chris's Item"); final Item another = new Item("another", "Owned Item"); item.addItem(another);/*from www. j av a 2 s . c o m*/ withTxSession(s -> { s.persist(item); s.persist(another); }); // The collection has been removed, but we can't add it again immediately using putFromLoad TIME_SERVICE.advance(1); withTxSession(s -> { Item loaded = s.load(Item.class, item.getId()); assertEquals(1, loaded.getItems().size()); }); String itemsRegionName = Item.class.getName() + ".items"; SecondLevelCacheStatistics cStats = stats.getSecondLevelCacheStatistics(itemsRegionName); assertEquals(1, cStats.getElementCountInMemory()); withTxSession(s -> { Item loadedWithCachedCollection = (Item) s.load(Item.class, item.getId()); stats.logSummary(); assertEquals(item.getName(), loadedWithCachedCollection.getName()); assertEquals(item.getItems().size(), loadedWithCachedCollection.getItems().size()); assertEquals(1, cStats.getHitCount()); assertEquals(1, TEST_SESSION_ACCESS.getRegion(sessionFactory(), itemsRegionName).getElementCountInMemory()); Item itemElement = loadedWithCachedCollection.getItems().iterator().next(); itemElement.setOwner(null); loadedWithCachedCollection.getItems().clear(); s.delete(itemElement); s.delete(loadedWithCachedCollection); }); }
From source file:org.infinispan.test.hibernate.cache.commons.functional.ReadWriteTest.java
License:LGPL
@Test @TestForIssue(jiraKey = "HHH-9231") public void testAddNewOneToManyElementInitFlushLeaveCacheConsistent() throws Exception { Statistics stats = sessionFactory().getStatistics(); stats.clear(); SecondLevelCacheStatistics cStats = stats.getSecondLevelCacheStatistics(Item.class.getName() + ".items"); ByRef<Long> itemId = new ByRef<>(null); saveItem(itemId);//from w ww . jav a 2s .c o m // create an element for item.itsms Item itemElement = new Item(); itemElement.setName("element"); itemElement.setDescription("element item"); withTxSession(s -> { Item item = s.get(Item.class, itemId.get()); assertFalse(Hibernate.isInitialized(item.getItems())); // Add an element to item.items (a Set); it will initialize the Set. item.addItem(itemElement); assertTrue(Hibernate.isInitialized(item.getItems())); s.persist(itemElement); s.flush(); markRollbackOnly(s); }); withTxSession(s -> { Item item = s.get(Item.class, itemId.get()); Hibernate.initialize(item.getItems()); assertTrue(item.getItems().isEmpty()); s.delete(item); }); }