@Override public Object invoke(Object... args) { getStatistics( getEntityManagerFactory( args ) ).clear(); return null; } };
@Override public Object invoke(Object... args) { getStatistics(getEntityManagerFactory(args)).clear(); return null; } };
@Override public Object invoke(Object... args) { getStatistics(getEntityManagerFactory(args)).clear(); return null; } };
@Override public Object invoke(Object... args) { getStatistics(getEntityManagerFactory(args)).clear(); return null; } };
@Override public Object invoke(Object... args) { getStatistics(getEntityManagerFactory(args)).clear(); return null; } };
session.close(); sf.getStatistics().clear(); session = sf.openSession(); session.beginTransaction();
Statistics stats = sessionFactory().getStatistics(); stats.setStatisticsEnabled( true ); stats.clear(); q = s.getNamedQuery( "night.duration" ); q.setParameter( "duration", 14l );
@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()); }
@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()); }
session.close(); session.getSessionFactory().getStatistics().clear();
@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()); }
session.close(); session.getSessionFactory().getStatistics().clear();
@Test public void testNaturalIdRecachingWhenNeeded() { Session session = openSession(); session.getSessionFactory().getStatistics().clear(); session.beginTransaction(); Another it = new Another( "it");
@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(); }
s.getSessionFactory().getStatistics().clear();
s.getSessionFactory().getStatistics().clear();
s.getSessionFactory().getStatistics().clear();
stats.clear(); assertEquals( "Cache hits should be empty", 0, stats.getNaturalIdCacheHitCount() ); assertEquals( "Cache puts should be empty", 0, stats.getNaturalIdCachePutCount() );
statistics.clear(); sqlStatementInterceptor.clear();
@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(); }