Package org.hibernate.stat

Examples of org.hibernate.stat.Statistics


        return false;
    }

    public void testEmptySecondLevelCacheEntry() throws Exception {
        getSessions().evictEntity(Item.class.getName());
        Statistics stats = getSessions().getStatistics();
        stats.clear();
        SecondLevelCacheStatistics statistics = stats.getSecondLevelCacheStatistics(getPrefixedRegionName(Item.class.getName()));
        Map cacheEntries = statistics.getEntries();
        assertEquals(0, cacheEntries.size());
    }
View Full Code Here


    JLabel treeCellRendererComponent = (JLabel) super.getTreeCellRendererComponent( tree, value, selected, expanded, leaf, row, hasFocus );
   
    String text = treeCellRendererComponent.getText();
    String tooltip = null;
    if(value instanceof Statistics) {
      Statistics stats = (Statistics) value;
      text = "Statistics " + formatter.format( new Date(stats.getStartTime()) );
      tooltip = stats.toString();
    }
   
    if(value instanceof CategorizedStatistics) {
      CategorizedStatistics stats = (CategorizedStatistics) value;
      text = stats.getCategoryName();
     
    }
    if(value instanceof EntityStatistics) {
      //EntityStatistics stats = (EntityStatistics) value;
     
View Full Code Here

    }

    public static Statistics getStatisticsService(EntityManager entityManager, MBeanServer server) {
        Session hibernateSession = PersistenceUtility.getHibernateSession(entityManager);
        SessionFactory hibernateSessionFactory = hibernateSession.getSessionFactory();
        Statistics hibernateStatistics = hibernateSessionFactory.getStatistics();
        return hibernateStatistics;
    }
View Full Code Here

    public StatisticsUtility() {


        this.sessionFactory = PersistenceUtility.getHibernateSession(LookupUtil.getEntityManager())
                .getSessionFactory();
        Statistics stats = sessionFactory.getStatistics();

        connectionsAtStart = stats.getConnectCount();
        beginTime = System.currentTimeMillis();
    }
View Full Code Here

        connectionsAtStart = stats.getConnectCount();
        beginTime = System.currentTimeMillis();
    }

    public void logStats() {
        Statistics stats = sessionFactory.getStatistics();

        log.info("HibernateStats: " + (stats.getConnectCount() - connectionsAtStart) +
                " connections made in " + (System.currentTimeMillis() - beginTime) + "ms");
    }
View Full Code Here

    public void zeroStats() {
        if (isLoggingEnabled()) {
            EntityManager entityManager = LookupUtil.getEntityManager();
            MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
            Statistics stats = PersistenceUtility.getStatisticsService(entityManager, platformMBeanServer);
            stats.clear();
        }
    }
View Full Code Here

  }
 
  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);
  }
View Full Code Here

  }

  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);

  }
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.