Package org.hibernate.stat

Examples of org.hibernate.stat.QueryStatistics


    i.setDescription("A really top-quality, full-featured widget.");
    s.save(i);
    t.commit();
    s.close();

        QueryStatistics qs = s.getSessionFactory().getStatistics().getQueryStatistics( queryString );
    EntityStatistics es = s.getSessionFactory().getStatistics().getEntityStatistics( Item.class.getName() );

    Thread.sleep(200);

    s = openSession();
    t = s.beginTransaction();
    List result = s.createQuery( queryString ).setCacheable(true).list();
    assertEquals( result.size(), 1 );
    t.commit();
    s.close();

    assertEquals( qs.getCacheHitCount(), 0 );

    s = openSession();
    t = s.beginTransaction();
    result = s.createQuery( queryString ).setCacheable(true).list();
    assertEquals( result.size(), 1 );
    t.commit();
    s.close();

    assertEquals( qs.getCacheHitCount(), 1 );

    s = openSession();
    t = s.beginTransaction();
    result = s.createQuery( queryString ).setCacheable(true).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list();
    assertEquals( result.size(), 1 );
    Map m = (Map) result.get(0);
    assertEquals(1, m.size());
    t.commit();
    s.close();

    assertEquals( "hit count should not go up since we are adding a resulttransformer", qs.getCacheHitCount(), 1 );
   
    s = openSession();
    t = s.beginTransaction();
    result = s.createQuery( queryString ).setCacheable(true).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list();
    assertEquals( result.size(), 1 );
    m = (Map) result.get(0);
    assertEquals(1, m.size());
    t.commit();
    s.close();
   
    assertEquals( "hit count should go up since we are using the same resulttransformer", qs.getCacheHitCount(), 2 );
   
    s = openSession();
    t = s.beginTransaction();
    result = s.createQuery( queryString ).setCacheable(true).list();
    assertEquals( result.size(), 1 );
    assertTrue( Hibernate.isInitialized( result.get(0) ) );
    i = (Item) s.get( Item.class, new Long(i.getId()) );
        i.setName("widget");
    i.setDescription("A middle-quality widget.");
    t.commit();
    s.close();

    assertEquals( qs.getCacheHitCount(), 3 );
    assertEquals( qs.getCacheMissCount(), 3 );

    Thread.sleep(200);

    s = openSession();
    t = s.beginTransaction();
    result = s.createQuery( queryString ).setCacheable(true).list();
    assertEquals( result.size(), 1 );
    i = (Item) s.get( Item.class, new Long(i.getId()) );
    assertEquals( (String) result.get(0), "A middle-quality widget." );
   
    s.delete(i);
    t.commit();
    s.close();

    assertEquals( qs.getCacheHitCount(), 3 );
    assertEquals( qs.getCacheMissCount(), 4 );
    assertEquals( qs.getCachePutCount(), 4 );
    assertEquals( qs.getExecutionCount(), 4 );
    assertEquals( es.getFetchCount(), 0 ); //check that it was being cached

  }
View Full Code Here


    assertTrue( "Incorrect result size", sr.next() );
    assertTrue( "Incorrect return type", sr.get(0) instanceof Animal );
    sr.close();

    // caching...
    QueryStatistics stats = getSessions().getStatistics().getQueryStatistics( "select new Animal(an.description, an.bodyWeight) from Animal an" );
    results = session.createQuery( "select new Animal(an.description, an.bodyWeight) from Animal an" )
        .setCacheable( true )
        .list();
    assertEquals( "incorrect result size", 2, results.size() );
    assertClassAssignability( Animal.class, results.get( 0 ).getClass() );
    long initCacheHits = stats.getCacheHitCount();
    results = session.createQuery( "select new Animal(an.description, an.bodyWeight) from Animal an" )
        .setCacheable( true )
        .list();
    assertEquals( "dynamic intantiation query not served from cache", initCacheHits + 1, stats.getCacheHitCount() );
    assertEquals( "incorrect result size", 2, results.size() );
    assertClassAssignability( Animal.class, results.get( 0 ).getClass() );

    session.close();
View Full Code Here

TOP

Related Classes of org.hibernate.stat.QueryStatistics

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.