Package org.hibernate.stat

Examples of org.hibernate.stat.QueryStatistics


        if (stats != null) {
            String[] originalQueryNames = stats.getStatistics().getQueries();
            if (originalQueryNames != null) {
                for (String originalQueryName : originalQueryNames) {
                    if (QueryName.queryName(originalQueryName).getDisplayName().equals(displayQueryName)) {
                        QueryStatistics statistics = stats.getStatistics().getQueryStatistics(originalQueryName);
                        handle(statistics, context, operation.require(ModelDescriptionConstants.NAME).asString(), originalQueryName);
                        break;
                    }
                }
            }
View Full Code Here


    try{
          // the nextTimestamp from infinispan is "return System.currentTimeMillis() / 100;"
          Thread.sleep(1000);
         
      String queryString = "from Employee e where e.id > "+id;
      QueryStatistics queryStats = stats.getQueryStatistics(queryString);
      Query query = em.createQuery(queryString);
      query.setHint("org.hibernate.cacheable", true);

      // query - this call should fill the cache
      query.getResultList();
      assertEquals("Expected 1 miss in cache"+generateQueryCacheStats(queryStats), 1,  queryStats.getCacheMissCount());
      assertEquals("Expected 1 put in cache"+generateQueryCacheStats(queryStats), 1,  queryStats.getCachePutCount());
      assertEquals("Expected no hits in cache"+generateQueryCacheStats(queryStats), 0,  queryStats.getCacheHitCount());
     
      // query - second call should hit cache
      query.getResultList();
      assertEquals("Expected 1 hit in cache"+generateQueryCacheStats(queryStats), 1,  queryStats.getCacheHitCount());
     

    }catch (AssertionError e) {
      return e.getMessage();
    } catch (InterruptedException e) {
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

    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

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

   
    s.beginTransaction();
    //and this one SHOULD served by the cache
    s.createQuery( queryString ).setCacheable( true ).list();
    s.getTransaction().commit();
    QueryStatistics qs = s.getSessionFactory().getStatistics().getQueryStatistics( queryString );
    assertEquals( 1, qs.getCacheHitCount() );
    assertEquals( 1, qs.getCachePutCount() );
    s.close();
    s = openSession();
    s.beginTransaction();
    for(Object obj:list){
      s.delete( obj );
View Full Code Here

    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 );
    assertEquals( s.getSessionFactory().getStatistics().getEntityFetchCount(), 0 );
   
    s = openSession();
    t = s.beginTransaction();
    result = s.createQuery( queryString ).setCacheable(true).list();
    assertEquals( result.size(), 1 );
    assertTrue( Hibernate.isInitialized( result.get(0) ) );
    i = (Item) result.get(0);
    i.setName("Widget");
    t.commit();
    s.close();
   
    assertEquals( qs.getCacheHitCount(), 2 );
    assertEquals( qs.getCacheMissCount(), 2 );
    assertEquals( s.getSessionFactory().getStatistics().getEntityFetchCount(), 0 );

    Thread.sleep(200);

    s = openSession();
    t = s.beginTransaction();
    result = s.createQuery( queryString ).setCacheable(true).list();
    if ( dialectIsCaseSensitive("i.name='widget' should not match on case sensitive database.") ) {
      assertEquals( result.size(), 0 );
    }
    i = (Item) s.get( Item.class, new Long(i.getId()) );
    assertEquals( i.getName(), "Widget" );
   
    s.delete(i);
    t.commit();
    s.close();

    assertEquals( qs.getCacheHitCount(), 2 );
    assertEquals( qs.getCacheMissCount(), 3 );
    assertEquals( qs.getCachePutCount(), 3 );
    assertEquals( qs.getExecutionCount(), 3 );
    assertEquals( es.getFetchCount(), 0 ); //check that it was being cached
   
  }
View Full Code Here

    t.commit();
    s.close();

    final String queryString = "from Item i where i.name like '%widget'";

    QueryStatistics qs = s.getSessionFactory().getStatistics().getQueryStatistics( queryString );

    Thread.sleep(200);

    s = openSession();
    t = s.beginTransaction();
    List result = s.createQuery( queryString ).setCacheable(true).list();
    assertEquals( result.size(), 2 );
    t.commit();
    s.close();
   
    assertEquals( qs.getCacheHitCount(), 0 );
    assertEquals( s.getSessionFactory().getStatistics().getEntityFetchCount(), 0 );
   
    getSessions().evict(Item.class);
       
    s = openSession();
    t = s.beginTransaction();
    result = s.createQuery( queryString ).setCacheable(true).list();
    assertEquals( result.size(), 2 );
    assertTrue( Hibernate.isInitialized( result.get(0) ) );
    assertTrue( Hibernate.isInitialized( result.get(1) ) );
    t.commit();
    s.close();
   
    assertEquals( qs.getCacheHitCount(), 1 );
    assertEquals( s.getSessionFactory().getStatistics().getEntityFetchCount(), 1 );

    s = openSession();
    t = s.beginTransaction();
    s.createQuery("delete Item").executeUpdate();
View Full Code Here

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

    assertEquals( qs.getCacheHitCount(), 0 );
    assertEquals( qs.getCacheMissCount(), 1 );
    assertEquals( qs.getCachePutCount(), 1 );

    Thread.sleep(200);

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

    assertEquals( qs.getCacheHitCount(), 0 );
    assertEquals( qs.getCacheMissCount(), 2 );
    assertEquals( qs.getCachePutCount(), 2 );

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

    assertEquals( qs.getCacheHitCount(), 1 );
    assertEquals( qs.getCacheMissCount(), 2 );
    assertEquals( qs.getCachePutCount(), 2 );

    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() );
    assertEquals( i.getDescription(), m.get( "desc" ) );
    t.commit();
    s.close();

    assertEquals( "hit count should go up since data is not transformed until after it is cached", qs.getCacheHitCount(), 2 );
    assertEquals( qs.getCacheMissCount(), 2 );
    assertEquals( qs.getCachePutCount(), 2 );

    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());
    assertEquals( i.getDescription(), m.get( "desc" ) );
    t.commit();
    s.close();

    assertEquals( "hit count should go up since data is not transformed until after it is cachedr", qs.getCacheHitCount(), 3 );
    assertEquals( qs.getCacheMissCount(), 2 );
    assertEquals( qs.getCachePutCount(), 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(), 4 );
    assertEquals( qs.getCacheMissCount(), 2 );
    assertEquals( qs.getCachePutCount(), 2 );

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

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

    s.delete(i);
    t.commit();
    s.close();

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

  }
View Full Code Here

    try{
          // the nextTimestamp from infinispan is "return System.currentTimeMillis() / 100;"
          Thread.sleep(1000);
         
      String queryString = "from Employee e where e.id > "+id;
      QueryStatistics queryStats = stats.getQueryStatistics(queryString);
      Query query = em.createQuery(queryString);
      query.setHint("org.hibernate.cacheable", true);

      // query - this call shouldn't hit the cache -> query cache is empty
      query.getResultList();
      assertEquals("Expected 1 miss in cache"+generateQueryCacheStats(queryStats), 1,  queryStats.getCacheMissCount());
      assertEquals("Expected 1 put in cache"+generateQueryCacheStats(queryStats), 1,  queryStats.getCachePutCount());
      assertEquals("Expected no hits in cache"+generateQueryCacheStats(queryStats), 0,  queryStats.getCacheHitCount());
     

    }catch (AssertionError e) {
      return e.getMessage();
    } catch (InterruptedException e) {
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.