Package org.hibernate.stat

Examples of org.hibernate.stat.Statistics


        }
        return result;
    }

    private Set<String> getEntityNames() {
        final Statistics stats = getStatistics();
        if (stats == null) {
            return Collections.emptySet();
        } else {
            Set<String> result = new HashSet<String>();
            String[] entityNames = stats.getEntityNames();
            if (entityNames != null) {
                for (String entity : entityNames) {
                    result.add(entity);
                }
            }
View Full Code Here


    }

    private boolean hasCacheRegion(PathElement element) {
        boolean result = false;
        final PersistenceUnitService puService = persistenceUnitRegistry.getPersistenceUnitService(puName);
        final Statistics stats = getStatistics();
        if (stats != null && puService != null) {
            final String scopedPUName = puService.getScopedPersistenceUnitName();
            final String unqualifiedRegionName = element.getValue();
            final String qualifiedRegionName = scopedPUName + "." + unqualifiedRegionName;
            result = stats.getSecondLevelCacheStatistics(qualifiedRegionName) != null;
        }
        return result;
    }
View Full Code Here

        }
        return result;
    }

    private Set<String> getCacheRegionNames() {
        final Statistics stats = getStatistics();
        if (stats == null) {
            return Collections.emptySet();
        } else {
            Set<String> result = new HashSet<String>();
            String[] cacheRegionNames = stats.getSecondLevelCacheRegionNames();
            if (cacheRegionNames != null) {
                for (String region : cacheRegionNames) {

                    // example regionName = "jpa_SecondLevelCacheTestCase.jar#mypc.org.jboss.as.test.integration.jpa.hibernate.Employee"
                    // remove the scoped PU name plus one for '.' the separator character added to it.
View Full Code Here

    }

    private boolean hasQuery(PathElement element) {
        boolean result = false;
        final PersistenceUnitService puService = persistenceUnitRegistry.getPersistenceUnitService(puName);
        final Statistics stats = getStatistics();
        if (stats != null && puService != null) {
            final String scopedPUName = puService.getScopedPersistenceUnitName();
            final String unqualifiedQueryName = element.getValue();
            final String queryName = scopedPUName + "." + unqualifiedQueryName;
            result = stats.getQueryStatistics(queryName) != null;
        }
        return result;
    }
View Full Code Here

        return result;
    }


    private Set<String> getQueryNames() {
        final Statistics stats = getStatistics();
        if (stats == null) {
            return Collections.emptySet();
        } else {
            Set<String> result = new HashSet<String>();
            String[] queries = stats.getQueries();
            if (queries != null) {
                for (String query : queries) {
                    result.add(QueryName.queryName(query).getDisplayName());
                }
            }
View Full Code Here

        }
    }

    private boolean hasCollection(PathElement element) {
        boolean result = false;
        final Statistics stats = getStatistics();
        if (stats != null) {
            final String collectionName = element.getValue();
            result = stats.getCollectionStatistics(collectionName) != null;
        }
        return result;
    }
View Full Code Here

        }
        return result;
    }

    private Set<String> getCollectionNames() {
        final Statistics stats = getStatistics();
        if (stats == null) {
            return Collections.emptySet();
        } else {
            Set<String> result = new HashSet<String>();
            String[] collectionNames = stats.getCollectionRoleNames();
            if (collectionNames != null) {
                for (String entity : collectionNames) {
                    result.add(entity);
                }
            }
View Full Code Here

    Item item = new Item( "Mouse", "Micro$oft mouse" );
    Distributor res = new Distributor();
    res.setName( "Bruce" );
    item.setDistributors( new HashSet<Distributor>() );
    item.getDistributors().add( res );
    Statistics stats = ( (HibernateEntityManagerFactory) factory ).getSessionFactory().getStatistics();
    stats.clear();
    stats.setStatisticsEnabled( true );

    EntityManager em = getOrCreateEntityManager();
    em.getTransaction().begin();

    em.persist( res );
    em.persist( item );
    assertTrue( em.contains( item ) );

    em.getTransaction().commit();
    em.close();

    assertEquals( 1, stats.getSecondLevelCachePutCount() );
    assertEquals( 0, stats.getSecondLevelCacheHitCount() );

    em = getOrCreateEntityManager();
    em.getTransaction().begin();
    Item second = em.find( Item.class, item.getName() );
    assertEquals( 1, second.getDistributors().size() );
    assertEquals( 1, stats.getSecondLevelCacheHitCount() );
    em.getTransaction().commit();
    em.close();

    em = getOrCreateEntityManager();
    em.getTransaction().begin();
    second = em.find( Item.class, item.getName() );
    assertEquals( 1, second.getDistributors().size() );
    assertEquals( 3, stats.getSecondLevelCacheHitCount() );
    em.remove( second );
    em.remove( second.getDistributors().iterator().next() );
    em.getTransaction().commit();
    em.close();

    stats.clear();
    stats.setStatisticsEnabled( false );
  }
View Full Code Here

  public void testTransactionalOperationsWhenExtended() throws Exception {
    Book book = new Book();
    book.name = "Le petit prince";
    EntityManager em = getOrCreateEntityManager();
    Statistics stats = ( (HibernateEntityManagerFactory) factory ).getSessionFactory().getStatistics();
    stats.clear();
    stats.setStatisticsEnabled( true );

    em.persist( book );
    assertEquals( 0, stats.getEntityInsertCount() );
    em.getTransaction().begin();
    em.flush();
    em.getTransaction().commit();
    assertEquals( 1, stats.getEntityInsertCount() );

    em.clear();
    book.name = "Le prince";
    book = em.merge( book );

    em.refresh( book );
    assertEquals( 0, stats.getEntityUpdateCount() );
    em.getTransaction().begin();
    em.flush();
    em.getTransaction().commit();
    assertEquals( 0, stats.getEntityUpdateCount() );

    book.name = "Le prince";
    em.getTransaction().begin();
    em.find( Book.class, book.id );
    em.getTransaction().commit();
    assertEquals( 1, stats.getEntityUpdateCount() );

    em.remove( book );
    assertEquals( 0, stats.getEntityDeleteCount() );
    em.getTransaction().begin();
    em.flush();
    em.getTransaction().commit();
    assertEquals( 1, stats.getEntityDeleteCount() );

    em.close();
    stats.setStatisticsEnabled( false );
  }
View Full Code Here

  public void testMergeWhenExtended() throws Exception {
    Book book = new Book();
    book.name = "Le petit prince";
    EntityManager em = getOrCreateEntityManager();
    Statistics stats = ( (HibernateEntityManagerFactory) factory ).getSessionFactory().getStatistics();

    em.getTransaction().begin();
    em.persist( book );
    assertEquals( 0, stats.getEntityInsertCount() );
    em.getTransaction().commit();

    em.clear(); //persist and clear
    stats.clear();
    stats.setStatisticsEnabled( true );

    Book bookReloaded = em.find( Book.class, book.id );

    book.name = "Le prince";
    assertEquals( "Merge should use the available entiies in the PC", em.merge( book ), bookReloaded );
    assertEquals( book.name, bookReloaded.name );

    assertEquals( 0, stats.getEntityDeleteCount() );
    assertEquals( 0, stats.getEntityInsertCount() );
    assertEquals( "Updates should have been queued", 0, stats.getEntityUpdateCount() );

    em.getTransaction().begin();
    Book bookReReloaded = em.find( Book.class, bookReloaded.id );
    assertEquals( "reload should return the object in PC", bookReReloaded, bookReloaded );
    assertEquals( bookReReloaded.name, bookReloaded.name );
    em.getTransaction().commit();

    assertEquals( 0, stats.getEntityDeleteCount() );
    assertEquals( 0, stats.getEntityInsertCount() );
    assertEquals( "Work on Tx should flush", 1, stats.getEntityUpdateCount() );

    em.getTransaction().begin();
    em.remove( bookReReloaded );
    em.getTransaction().commit();

    em.close();
    stats.setStatisticsEnabled( false );
  }
View Full Code Here

TOP

Related Classes of org.hibernate.stat.Statistics

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.