Java Code Examples for org.hibernate.stat.Statistics#getCollectionFetchCount()

The following examples show how to use org.hibernate.stat.Statistics#getCollectionFetchCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestStatistics.java    From HibernateTips with MIT License 6 votes vote down vote up
@Test
public void statisticsAPI() {
	log.info("... statisticsAPI ...");

	EntityManager em = emf.createEntityManager();
	em.getTransaction().begin();

	List<Author> authors = em.createQuery("SELECT a FROM Author a", Author.class).getResultList();

	for (Author a : authors) {
		log.info(a.getFirstName() + " " + a.getLastName() + " wrote " + a.getBooks().size());
	}
	
	SessionFactory sessionFactory = emf.unwrap(SessionFactory.class);
	Statistics stats = sessionFactory.getStatistics();
	long queryCount = stats.getQueryExecutionCount();
	long collectionFetchCount = stats.getCollectionFetchCount();
	log.info("QueryCount: "+queryCount);
	log.info("CollectionFetchCount: "+collectionFetchCount);
	
	em.getTransaction().commit();
	em.close();
}
 
Example 2
Source File: HibernateCounter.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public long getCount() {
    Statistics statistics = getSessionFactory().getStatistics();
    switch (metric) {
        case "sessionsOpened":
            return statistics.getSessionOpenCount();
        case "sessionsClosed":
            return statistics.getSessionCloseCount();
        case "transactionCount":
            return statistics.getTransactionCount();
        case "successfulTransactions":
            return statistics.getSuccessfulTransactionCount();
        case "optimisticLockFailures":
            return statistics.getOptimisticFailureCount();
        case "flushes":
            return statistics.getFlushCount();
        case "connectionsObtained":
            return statistics.getConnectCount();
        case "statementsPrepared":
            return statistics.getPrepareStatementCount();
        case "statementsClosed":
            return statistics.getCloseStatementCount();
        case "secondLevelCachePuts":
            return statistics.getSecondLevelCachePutCount();
        case "secondLevelCacheHits":
            return statistics.getSecondLevelCacheHitCount();
        case "secondLevelCacheMisses":
            return statistics.getSecondLevelCacheMissCount();
        case "entitiesLoaded":
            return statistics.getEntityLoadCount();
        case "entitiesUpdated":
            return statistics.getEntityUpdateCount();
        case "entitiesInserted":
            return statistics.getEntityInsertCount();
        case "entitiesDeleted":
            return statistics.getEntityDeleteCount();
        case "entitiesFetched":
            return statistics.getEntityFetchCount();
        case "collectionsLoaded":
            return statistics.getCollectionLoadCount();
        case "collectionsUpdated":
            return statistics.getCollectionUpdateCount();
        case "collectionsRemoved":
            return statistics.getCollectionRemoveCount();
        case "collectionsRecreated":
            return statistics.getCollectionRecreateCount();
        case "collectionsFetched":
            return statistics.getCollectionFetchCount();
        case "naturalIdQueriesExecutedToDatabase":
            return statistics.getNaturalIdQueryExecutionCount();
        case "naturalIdCachePuts":
            return statistics.getNaturalIdCachePutCount();
        case "naturalIdCacheHits":
            return statistics.getNaturalIdCacheHitCount();
        case "naturalIdCacheMisses":
            return statistics.getNaturalIdCacheMissCount();
        case "queriesExecutedToDatabase":
            return statistics.getQueryExecutionCount();
        case "queryCachePuts":
            return statistics.getQueryCachePutCount();
        case "queryCacheHits":
            return statistics.getQueryCacheHitCount();
        case "queryCacheMisses":
            return statistics.getQueryCacheMissCount();
        case "updateTimestampsCachePuts":
            return statistics.getUpdateTimestampsCachePutCount();
        case "updateTimestampsCacheHits":
            return statistics.getUpdateTimestampsCacheHitCount();
        case "updateTimestampsCacheMisses":
            return statistics.getUpdateTimestampsCacheMissCount();
        default:
            throw new IllegalArgumentException("Unknown data source metric");
    }
}