org.hibernate.stat.Statistics.clear()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(169)

本文整理了Java中org.hibernate.stat.Statistics.clear()方法的一些代码示例,展示了Statistics.clear()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Statistics.clear()方法的具体详情如下:
包路径:org.hibernate.stat.Statistics
类名称:Statistics
方法名:clear

Statistics.clear介绍

[英]reset all statistics
[中]重置所有统计数据

代码示例

代码示例来源:origin: hibernate/hibernate-orm

@Override
  public Object invoke(Object... args) {
    getStatistics( getEntityManagerFactory( args ) ).clear();
    return null;
  }
};

代码示例来源:origin: wildfly/wildfly

@Override
  public Object invoke(Object... args) {
    getStatistics(getEntityManagerFactory(args)).clear();
    return null;
  }
};

代码示例来源:origin: wildfly/wildfly

@Override
  public Object invoke(Object... args) {
    getStatistics(getEntityManagerFactory(args)).clear();
    return null;
  }
};

代码示例来源:origin: wildfly/wildfly

@Override
  public Object invoke(Object... args) {
    getStatistics(getEntityManagerFactory(args)).clear();
    return null;
  }
};

代码示例来源:origin: wildfly/wildfly

@Override
  public Object invoke(Object... args) {
    getStatistics(getEntityManagerFactory(args)).clear();
    return null;
  }
};

代码示例来源:origin: hibernate/hibernate-orm

session.close();
sf.getStatistics().clear();
session = sf.openSession();
session.beginTransaction();

代码示例来源:origin: hibernate/hibernate-orm

Statistics stats = sessionFactory().getStatistics();
stats.setStatisticsEnabled( true );
stats.clear();
q = s.getNamedQuery( "night.duration" );
q.setParameter( "duration", 14l );

代码示例来源:origin: hibernate/hibernate-orm

@Test
@TestForIssue( jiraKey = "HHH-7278" )
public void testInsertedNaturalIdCachedAfterTransactionSuccess() {
  
  Session session = openSession();
  session.getSessionFactory().getStatistics().clear();
  session.beginTransaction();
  Another it = new Another( "it");
  session.save( it );
  session.flush();
  session.getTransaction().commit();
  session.close();
  
  session = openSession();
  session.beginTransaction();
  it = (Another) session.bySimpleNaturalId(Another.class).load("it");
  assertNotNull(it);
  session.delete(it);
  session.getTransaction().commit();
  assertEquals(1, session.getSessionFactory().getStatistics().getNaturalIdCacheHitCount());
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
@TestForIssue( jiraKey = "HHH-7309" )
public void testInsertUpdateEntity_NaturalIdCachedAfterTransactionSuccess() {
  
  Session session = openSession();
  session.getSessionFactory().getStatistics().clear();
  session.beginTransaction();
  Another it = new Another( "it");
  session.save( it );    // schedules an InsertAction
  it.setSurname("1234"); // schedules an UpdateAction, without bug-fix
  // this will re-cache natural-id with identical key and at same time invalidate it
  session.flush();
  session.getTransaction().commit();
  session.close();
  
  session = openSession();
  session.beginTransaction();
  it = (Another) session.bySimpleNaturalId(Another.class).load("it");
  assertNotNull(it);
  session.delete(it);
  session.getTransaction().commit();
  assertEquals("In a strict access strategy we would excpect a hit here", 1, session.getSessionFactory().getStatistics().getNaturalIdCacheHitCount());
}

代码示例来源:origin: hibernate/hibernate-orm

session.close();
session.getSessionFactory().getStatistics().clear();

代码示例来源:origin: hibernate/hibernate-orm

@Test
@TestForIssue( jiraKey = "HHH-7278" )
public void testInsertedNaturalIdNotCachedAfterTransactionFailure() {
  
  Session session = openSession();
  session.getSessionFactory().getStatistics().clear();
  session.beginTransaction();
  Another it = new Another( "it");
  session.save( it );
  session.flush();
  session.getTransaction().rollback();
  session.close();
  
  session = openSession();
  session.beginTransaction();
  it = (Another) session.bySimpleNaturalId(Another.class).load("it");
  assertNull(it);
  assertEquals(0, session.getSessionFactory().getStatistics().getNaturalIdCacheHitCount());
}

代码示例来源:origin: hibernate/hibernate-orm

session.close();
session.getSessionFactory().getStatistics().clear();

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testNaturalIdRecachingWhenNeeded() {
  Session session = openSession();
  session.getSessionFactory().getStatistics().clear();
  session.beginTransaction();
  Another it = new Another( "it");

代码示例来源:origin: hibernate/hibernate-orm

@TestForIssue(jiraKey = "HHH-4838")
@Test
public void testNaturalKeyLookupWithConstraint() {
  Session s = openSession();
  Transaction newTx = s.getTransaction();
  newTx.begin();
  A a1 = new A();
  a1.setName( "name1" );
  s.persist( a1 );
  newTx.commit();
  newTx = s.beginTransaction();
  getCriteria( s ).add( Restrictions.isNull( "singleD" ) ).uniqueResult(); // put query-result into cache
  A a2 = new A();
  a2.setName( "xxxxxx" );
  s.persist( a2 );
  newTx.commit();      // Invalidates space A in UpdateTimeStamps region
  newTx = s.beginTransaction();
  Assert.assertTrue( s.getSessionFactory().getStatistics().isStatisticsEnabled() );
  s.getSessionFactory().getStatistics().clear();
  // should not produce a hit in StandardQuery cache region because there is a constraint
  getCriteria( s ).add( Restrictions.isNull( "singleD" ) ).uniqueResult();
  Assert.assertEquals( 0, s.getSessionFactory().getStatistics().getQueryCacheHitCount() );
  s.createQuery( "delete from A" ).executeUpdate();
  newTx.commit();
  // Shutting down the application
  s.close();
}

代码示例来源:origin: hibernate/hibernate-orm

s.getSessionFactory().getStatistics().clear();

代码示例来源:origin: hibernate/hibernate-orm

s.getSessionFactory().getStatistics().clear();

代码示例来源:origin: hibernate/hibernate-orm

s.getSessionFactory().getStatistics().clear();

代码示例来源:origin: hibernate/hibernate-orm

stats.clear();
assertEquals( "Cache hits should be empty", 0, stats.getNaturalIdCacheHitCount() );
assertEquals( "Cache puts should be empty", 0, stats.getNaturalIdCachePutCount() );

代码示例来源:origin: hibernate/hibernate-orm

statistics.clear();
sqlStatementInterceptor.clear();

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testNaturalIdLoaderNotCached() {
  saveSomeCitizens();
  Session s = openSession();
  Transaction tx = s.beginTransaction();
  State france = this.getState( s, "Ile de France" );
  final NaturalIdLoadAccess naturalIdLoader = s.byNaturalId( Citizen.class );
  naturalIdLoader.using( "ssn", "1234" ).using( "state", france );
  //NaturalId cache gets populated during entity loading, need to clear it out
  this.cleanupCache();
  Statistics stats = sessionFactory().getStatistics();
  stats.setStatisticsEnabled( true );
  stats.clear();
  assertEquals( "NaturalId Cache Hits", 0, stats.getNaturalIdCacheHitCount() );
  assertEquals( "NaturalId Cache Misses", 0, stats.getNaturalIdCacheMissCount() );
  assertEquals( "NaturalId Cache Puts", 0, stats.getNaturalIdCachePutCount() );
  assertEquals( "NaturalId Cache Queries", 0, stats.getNaturalIdQueryExecutionCount() );
  // first query
  Citizen citizen = (Citizen)naturalIdLoader.load();
  assertNotNull( citizen );
  assertEquals( "NaturalId Cache Hits", 0, stats.getNaturalIdCacheHitCount() );
  assertEquals( "NaturalId Cache Misses", 1, stats.getNaturalIdCacheMissCount() );
  assertEquals( "NaturalId Cache Puts", 1, stats.getNaturalIdCachePutCount() );
  assertEquals( "NaturalId Cache Queries", 1, stats.getNaturalIdQueryExecutionCount() );
  // cleanup
  tx.rollback();
  s.close();
}

相关文章

Statistics类方法