Package org.hibernate.stat

Examples of org.hibernate.stat.EntityStatistics


        this.persistenceUnitRegistry = persistenceUnitRegistry;
    }

    @Override
    protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
        EntityStatistics statistics = entityStatistics(operation);
        if (statistics != null) {
            handle(statistics, context, operation.require(ModelDescriptionConstants.NAME).asString());
        }
        context.completeStep();
    }
View Full Code Here


    s.close();

    s = openSession();
    s.beginTransaction();

    EntityStatistics addressStats = getSessions().getStatistics().getEntityStatistics( "Address" );

    person = ( Map ) s.createQuery( "from Person p join fetch p.address" ).uniqueResult();
    assertNotNull( "could not locate person", person );
    assertNotNull( "could not locate persons address", person.get( "address" ) );
    s.clear();

    Object[] tuple = ( Object[] ) s.createQuery( "select p.name, p from Person p join fetch p.address" ).uniqueResult();
    assertEquals( tuple.length, 2 );
    person = ( Map ) tuple[1];
    assertNotNull( "could not locate person", person );
    assertNotNull( "could not locate persons address", person.get( "address" ) );

    s.delete( "Person", person );

    s.getTransaction().commit();
    s.close();

    assertEquals( addressStats.getFetchCount(), 0 );
  }
View Full Code Here

    s.close();
   
    s = openSession();
    t = s.beginTransaction();
   
    EntityStatistics addressStats = getSessions().getStatistics().getEntityStatistics( Address.class.getName() );
    EntityStatistics mailingAddressStats = getSessions().getStatistics().getEntityStatistics("MailingAddress");

    p = (Person) s.createQuery("from Person p join fetch p.address left join fetch p.mailingAddress").uniqueResult();
    assertNotNull(p.address); assertNull(p.mailingAddress);
    s.clear();

    assertEquals( addressStats.getFetchCount(), 0 );
    assertEquals( mailingAddressStats.getFetchCount(), 0 );
   
    p = (Person) s.createQuery("from Person p join fetch p.address").uniqueResult();
    assertNotNull(p.address); assertNull(p.mailingAddress);
    s.clear();
   
    assertEquals( addressStats.getFetchCount(), 0 );
    assertEquals( mailingAddressStats.getFetchCount(), 1 );

    p = (Person) s.createQuery("from Person").uniqueResult();
    assertNotNull(p.address); assertNull(p.mailingAddress);
    s.clear();
   
    assertEquals( addressStats.getFetchCount(), 1 );
    assertEquals( mailingAddressStats.getFetchCount(), 2 );

    p = (Person) s.createQuery("from Entity").uniqueResult();
    assertNotNull(p.address); assertNull(p.mailingAddress);
    s.clear();
   
    assertEquals( addressStats.getFetchCount(), 2 );
    assertEquals( mailingAddressStats.getFetchCount(), 3 );

    //note that in here join fetch is used for the nullable
    //one-to-one, due to a very special case of default
    p = (Person) s.get(Person.class, "Gavin");
    assertNotNull(p.address); assertNull(p.mailingAddress);
    s.clear();
   
    assertEquals( addressStats.getFetchCount(), 2 );
    assertEquals( mailingAddressStats.getFetchCount(), 3 );

    p = (Person) s.get(Entity.class, "Gavin");
    assertNotNull(p.address); assertNull(p.mailingAddress);
    s.clear();
   
    assertEquals( addressStats.getFetchCount(), 2 );
    assertEquals( mailingAddressStats.getFetchCount(), 3 );
   
    t.commit();
    s.close();
   
    s = openSession();
View Full Code Here

    s.close();
   
    s = openSession();
    t = s.beginTransaction();
   
    EntityStatistics addressStats = getSessions().getStatistics().getEntityStatistics( Address.class.getName() );
    EntityStatistics mailingAddressStats = getSessions().getStatistics().getEntityStatistics("MailingAddress");

    p = (Person) s.createQuery("from Person p join fetch p.address left join fetch p.mailingAddress").uniqueResult();
    assertNotNull(p.address); assertNull(p.mailingAddress);
    s.clear();

    p = (Person) s.createQuery("select p from Person p join fetch p.address left join fetch p.mailingAddress").uniqueResult();
    assertNotNull(p.address); assertNull(p.mailingAddress);
    s.clear();

    Object[] stuff = (Object[]) s.createQuery("select p.name, p from Person p join fetch p.address left join fetch p.mailingAddress").uniqueResult();
    assertEquals(stuff.length, 2);
    p = (Person) stuff[1];
    assertNotNull(p.address); assertNull(p.mailingAddress);
    s.clear();

    assertEquals( addressStats.getFetchCount(), 0 );
    assertEquals( mailingAddressStats.getFetchCount(), 0 );
   
    p = (Person) s.createQuery("from Person p join fetch p.address").uniqueResult();
    assertNotNull(p.address); assertNull(p.mailingAddress);
    s.clear();
   
    assertEquals( addressStats.getFetchCount(), 0 );
    assertEquals( mailingAddressStats.getFetchCount(), 1 );

    p = (Person) s.createQuery("from Person").uniqueResult();
    assertNotNull(p.address); assertNull(p.mailingAddress);
    s.clear();
   
    assertEquals( addressStats.getFetchCount(), 0 );
    assertEquals( mailingAddressStats.getFetchCount(), 2 );

    p = (Person) s.createQuery("from Entity").uniqueResult();
    assertNotNull(p.address); assertNull(p.mailingAddress);
    s.clear();
   
    assertEquals( addressStats.getFetchCount(), 0 );
    assertEquals( mailingAddressStats.getFetchCount(), 3 );

    //note that in here join fetch is used for the nullable
    //one-to-one, due to a very special case of default
    p = (Person) s.get(Person.class, "Gavin");
    assertNotNull(p.address); assertNull(p.mailingAddress);
    s.clear();
   
    assertEquals( addressStats.getFetchCount(), 0 );
    assertEquals( mailingAddressStats.getFetchCount(), 3 );

    p = (Person) s.get(Entity.class, "Gavin");
    assertNotNull(p.address); assertNull(p.mailingAddress);
    s.clear();
   
    assertEquals( addressStats.getFetchCount(), 0 );
    assertEquals( mailingAddressStats.getFetchCount(), 3 );
   
    t.commit();
    s.close();
   
    s = openSession();
View Full Code Here

    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

    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

            .getQueryExecutionMaxTimeQueryString()+"'");

    HibernateTemplate.save(hibernateStatistics);

    for (String entityName : statistics.getEntityNames()) {
      EntityStatistics entityStatistics = statistics.getEntityStatistics(entityName);
      int loadCount = (int) entityStatistics.getLoadCount();
      int insertCount = (int) entityStatistics.getInsertCount();
      int updateCount = (int) entityStatistics.getUpdateCount();
      int deleteCount = (int) entityStatistics.getDeleteCount();
      int fetchCount = (int) entityStatistics.getFetchCount();
      int optimisticFailureCount = (int) entityStatistics.getOptimisticFailureCount();
      if (loadCount + insertCount + updateCount + deleteCount + fetchCount + optimisticFailureCount != 0) {
        HibernateEntityStatistics hibernateEntityStatistics = new HibernateEntityStatistics(entityName, loadCount, updateCount, insertCount,
            deleteCount, fetchCount, optimisticFailureCount, hibernateStatistics);
        hibernateStatistics.getHibernateEntityStatisticsSet().add(hibernateEntityStatistics);
        HibernateTemplate.save(hibernateEntityStatistics);
View Full Code Here

    String[] entityNames = statistics.getEntityNames();
    Map<String, EntityCacheStatsWrapper> entityCacheStats = new HashMap<String, EntityCacheStatsWrapper>();

    for (String entityName : entityNames) {
      EntityStatistics entityStatistics = statistics.getEntityStatistics(entityName);
      EntityCacheStatsWrapper entityCacheStatsWrapper = new EntityCacheStatsWrapper();
      entityCacheStatsWrapper.setEntityStatsWrapper(new EntityStatsWrapper(entityName, entityStatistics));
      entityCacheStats.put(entityName, entityCacheStatsWrapper);
    }
View Full Code Here

    String[] entityNames = statistics.getEntityNames();
    Map<String, EntityCacheStatsWrapper> entityCacheStats = new HashMap<String, EntityCacheStatsWrapper>();

    for (String entityName : entityNames) {
      EntityStatistics entityStatistics = statistics.getEntityStatistics(entityName);
      EntityCacheStatsWrapper entityCacheStatsWrapper = new EntityCacheStatsWrapper();
      entityCacheStatsWrapper.setEntityStatsWrapper(new EntityStatsWrapper(entityName, entityStatistics));
      entityCacheStats.put(entityName, entityCacheStatsWrapper);
    }
View Full Code Here

        this.persistenceUnitRegistry = persistenceUnitRegistry;
    }

    @Override
    protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
        EntityStatistics statistics = entityStatistics(operation);
        if (statistics != null) {
            handle(statistics, context, operation.require(ModelDescriptionConstants.NAME).asString());
        }
        context.stepCompleted();
    }
View Full Code Here

TOP

Related Classes of org.hibernate.stat.EntityStatistics

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.