Package org.hibernate.stat

Examples of org.hibernate.stat.Statistics


    tx.commit();
    s.close();
  }

  public void testQueryStatGathering() {
    Statistics stats = getSessions().getStatistics();
    stats.clear();

    Session s = openSession();
    Transaction tx = s.beginTransaction();
    fillDb(s);
    tx.commit();
    s.close();

    s = openSession();
    tx = s.beginTransaction();
    final String continents = "from Continent";
    int results = s.createQuery( continents ).list().size();
    QueryStatistics continentStats = stats.getQueryStatistics( continents );
    assertNotNull( "stats were null",  continentStats );
    assertEquals( "unexpected execution count", 1, continentStats.getExecutionCount() );
    assertEquals( "unexpected row count", results, continentStats.getExecutionRowCount() );
    long maxTime = continentStats.getExecutionMaxTime();
    assertEquals( maxTime, stats.getQueryExecutionMaxTime() );
//    assertEquals( continents, stats.getQueryExecutionMaxTimeQueryString() );

    Iterator itr = s.createQuery( continents ).iterate();
    // iterate() should increment the execution count
    assertEquals( "unexpected execution count", 2, continentStats.getExecutionCount() );
    // but should not effect the cumulative row count
    assertEquals( "unexpected row count", results, continentStats.getExecutionRowCount() );
    Hibernate.close( itr );

    ScrollableResults scrollableResults = s.createQuery( continents ).scroll();
    // same deal with scroll()...
    assertEquals( "unexpected execution count", 3, continentStats.getExecutionCount() );
    assertEquals( "unexpected row count", results, continentStats.getExecutionRowCount() );
    // scroll through data because SybaseASE15Dialect throws NullPointerException
    // if data is not read before closing the ResultSet
    while ( scrollableResults.next() ) {
      // do nothing
    }
    scrollableResults.close();
    tx.commit();
    s.close();

    // explicitly check that statistics for "split queries" get collected
    // under the original query
    stats.clear();
    s = openSession();
    tx = s.beginTransaction();
    final String localities = "from Locality";
    results = s.createQuery( localities ).list().size();
    QueryStatistics localityStats = stats.getQueryStatistics( localities );
    assertNotNull( "stats were null",  localityStats );
    // ...one for each split query
    assertEquals( "unexpected execution count", 2, localityStats.getExecutionCount() );
    assertEquals( "unexpected row count", results, localityStats.getExecutionRowCount() );
    maxTime = localityStats.getExecutionMaxTime();
    assertEquals( maxTime, stats.getQueryExecutionMaxTime() );
//    assertEquals( localities, stats.getQueryExecutionMaxTimeQueryString() );
    tx.commit();
    s.close();
    assertFalse( s.isOpen() );

    // native sql queries
    stats.clear();
    s = openSession();
    tx = s.beginTransaction();
    final String sql = "select id, name from Country";
    results = s.createSQLQuery( sql ).addEntity( Country.class ).list().size();
    QueryStatistics sqlStats = stats.getQueryStatistics( sql );
    assertNotNull( "sql stats were null", sqlStats );
    assertEquals( "unexpected execution count", 1, sqlStats.getExecutionCount() );
    assertEquals( "unexpected row count", results, sqlStats.getExecutionRowCount() );
    maxTime = sqlStats.getExecutionMaxTime();
    assertEquals( maxTime, stats.getQueryExecutionMaxTime() );
//    assertEquals( sql, stats.getQueryExecutionMaxTimeQueryString() );
    tx.commit();
    s.close();

    s = openSession();
View Full Code Here


  public void testJoinedSubclass() {
    if ( ! supportsCircularCascadeDelete() ) {
      return;
    }

    Statistics statistics = getSessions().getStatistics();
    statistics.clear();
   
    Session s = openSession();
    Transaction t = s.beginTransaction();
   
    Salesperson mark = new Salesperson();
    mark.setName("Mark");
    mark.setTitle("internal sales");
    mark.setSex('M');
    mark.setAddress("buckhead");
    mark.setZip("30305");
    mark.setCountry("USA");
   
    Person joe = new Person();
    joe.setName("Joe");
    joe.setAddress("San Francisco");
    joe.setZip("XXXXX");
    joe.setCountry("USA");
    joe.setSex('M');
    joe.setSalesperson(mark);
    mark.getCustomers().add(joe);
       
    s.save(mark);
   
    t.commit();
   
    assertEquals( statistics.getEntityInsertCount(), 2 );
    assertEquals( statistics.getPrepareStatementCount(), 5 );
   
    statistics.clear();
   
    t = s.beginTransaction();
    s.delete(mark);
    t.commit();

    assertEquals( statistics.getEntityDeleteCount(), 2 );
    if ( getDialect().supportsCascadeDelete() ) {
      assertEquals( statistics.getPrepareStatementCount(), 1 );
    }
   
    t = s.beginTransaction();
    List names = s.createQuery("select name from Person").list();
    assertTrue( names.isEmpty() );
View Full Code Here

      beginTx();
      try {
         Session s = openSession();
         Item found = (Item) s.load(Item.class, item.getId());
         Statistics stats = s.getSessionFactory().getStatistics();
         log.info(stats.toString());
         assertEquals(item.getDescription(), found.getDescription());
         assertEquals(0, stats.getSecondLevelCacheMissCount());
         assertEquals(1, stats.getSecondLevelCacheHitCount());
         s.delete(found);
         s.close();
      } catch (Exception e) {
         setRollbackOnlyTx(e);
      } finally {
View Full Code Here

      }

      beginTx();
      try {
         Session s = openSession();
         Statistics stats = s.getSessionFactory().getStatistics();
         SecondLevelCacheStatistics cStats = stats.getSecondLevelCacheStatistics(Item.class.getName() + ".items");
         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());
         Map cacheEntries = cStats.getEntries();
         assertEquals(1, cacheEntries.size());
View Full Code Here

      }

      beginTx();
      try {
         s = openSession();
         Statistics stats = s.getSessionFactory().getStatistics();
         s.createQuery("from Item").setCacheable(true).list();
         assertEquals(1, stats.getQueryCacheHitCount());
         s.createQuery("delete from Item").executeUpdate();
         s.close();
      } catch (Exception e) {
         setRollbackOnlyTx(e);
      } finally {
View Full Code Here

      Thread.sleep(100);

      beginTx();
      try {
         s = openSession();
         Statistics stats = s.getSessionFactory().getStatistics();
         s.createQuery("from Item").setCacheable(true).list();
         s.createQuery("from Item").setCacheable(true).list();
         assertEquals(1, stats.getQueryCacheHitCount());
         s.close();
      } catch (Exception e) {
         setRollbackOnlyTx(e);
      } finally {
         commitOrRollbackTx();
View Full Code Here

      }
   }

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

      return "read-only";
   }

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

      }

      try {
         s = openSession();
         s.beginTransaction();
         Statistics stats = s.getSessionFactory().getStatistics();
         SecondLevelCacheStatistics cStats = stats.getSecondLevelCacheStatistics(Item.class.getName() + ".items");
         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());
         Map cacheEntries = cStats.getEntries();
         assertEquals(1, cacheEntries.size());
View Full Code Here

      }
   }

   public void testEmptySecondLevelCacheEntry() throws Exception {
      getSessions().getCache().evictEntityRegion(Item.class.getName());
      Statistics stats = getSessions().getStatistics();
      stats.clear();
      SecondLevelCacheStatistics statistics = stats.getSecondLevelCacheStatistics(Item.class.getName() + ".items");
      Map cacheEntries = statistics.getEntries();
      assertEquals(0, cacheEntries.size());
   }
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.