Examples of SecondLevelCacheStatistics


Examples of org.hibernate.stat.SecondLevelCacheStatistics

  public String sameSessionCheck(String CACHE_REGION_NAME) {
   
    EntityManager em = emf.createEntityManager();
    Statistics stats = em.unwrap(Session.class).getSessionFactory().getStatistics();
    stats.clear();
    SecondLevelCacheStatistics emp2LCStats = stats.getSecondLevelCacheStatistics(CACHE_REGION_NAME+"Employee");
     
    try{
      // add new entities and check if they are put in 2LC
      createEmployee(em, "Peter", "Ostrava", 2);
      createEmployee(em, "Tom", "Brno", 3);
      assertEquals("There are 2 puts in the 2LC"+generateEntityCacheStats(emp2LCStats), 2, emp2LCStats.getPutCount());
     
      // loading all Employee entities should put in 2LC all Employee
      List<?> empList = getAllEmployeesQuery(em);
      assertEquals("There are 2 entities.", empList.size(), 2);
      assertEquals("There are 2 entities in the 2LC"+generateEntityCacheStats(emp2LCStats), 2, emp2LCStats.getElementCountInMemory());
     
      // clear session
      em.clear();
     
      // entity should be loaded from 2L cache, we'are expecting hit in 2L cache
      Employee emp = getEmployee(em, 2);
      assertNotNull("Employee returned", emp);
      assertEquals("Expected 1 hit in cache"+generateEntityCacheStats(emp2LCStats), 1,  emp2LCStats.getHitCount());
     
    }catch (AssertionError e) {
      return e.getMessage();
    finally{
      em.close();
View Full Code Here

Examples of org.hibernate.stat.SecondLevelCacheStatistics

  public String secondSessionCheck(String CACHE_REGION_NAME) {
   
    EntityManager em = emf.createEntityManager();
    Statistics stats = em.unwrap(Session.class).getSessionFactory().getStatistics();
    stats.clear();
    SecondLevelCacheStatistics emp2LCStats = stats.getSecondLevelCacheStatistics(CACHE_REGION_NAME+"Employee");
     
    try{
      // add new entity
      createEmployee(em, "David", "Praha", 10);
      assertEquals("There is 1 put in the 2LC"+generateEntityCacheStats(emp2LCStats), 1, emp2LCStats.getPutCount());
     
    }catch (AssertionError e) {
      return e.getMessage();
    finally{
      em.close();
    }
   
   
    EntityManager em2 = emf.createEntityManager();
    try
      // loading entity stored in previous session, we'are expecting hit in cache
      Employee emp = getEmployee(em2, 10);
      assertNotNull("Employee returned", emp);
      assertEquals("Expected 1 hit in 2LC"+generateEntityCacheStats(emp2LCStats), 1,  emp2LCStats.getHitCount());
     
    }catch (AssertionError e) {
      return e.getMessage();
    finally{
      em2.close();
View Full Code Here

Examples of org.hibernate.stat.SecondLevelCacheStatistics

  public String addEntitiesAndEvictAll(String CACHE_REGION_NAME){

    EntityManager em = emf.createEntityManager();
    Statistics stats = em.unwrap(Session.class).getSessionFactory().getStatistics();
    stats.clear();
    SecondLevelCacheStatistics emp2LCStats = stats.getSecondLevelCacheStatistics(CACHE_REGION_NAME+"Employee");
   
    try{
      createEmployee(em, "Jan", "Ostrava", 20);
      createEmployee(em, "Martin", "Brno", 30);
      assertEquals("There are 2 puts in the 2LC"+generateEntityCacheStats(emp2LCStats), 2, emp2LCStats.getPutCount());
     
      assertTrue("Expected entities stored in the cache"+generateEntityCacheStats(emp2LCStats), emp2LCStats.getElementCountInMemory() > 0);
     
      // evict entity 2lc
      emf.getCache().evictAll();
     
    }catch (AssertionError e) {
View Full Code Here

Examples of org.hibernate.stat.SecondLevelCacheStatistics

  public String evictedEntityCacheCheck(String CACHE_REGION_NAME){

    EntityManager em = emf.createEntityManager();
    Statistics stats = em.unwrap(Session.class).getSessionFactory().getStatistics();
    stats.clear();
    SecondLevelCacheStatistics emp2LCStats = stats.getSecondLevelCacheStatistics(CACHE_REGION_NAME+"Employee");
     
    try
      assertEquals("Expected no entities stored in the cache"+emp2LCStats, 0, emp2LCStats.getElementCountInMemory());
     
      // loading entity stored in previous session, we are expecting miss in 2lc
      Employee emp = getEmployee(em, 20);
      assertNotNull("Employee returned", emp);
      assertEquals("Expected 1 miss in 2LC"+generateEntityCacheStats(emp2LCStats), 1,  emp2LCStats.getMissCount());
     
    }catch (AssertionError e) {
      return e.getMessage();
    finally{
      em.close();
View Full Code Here

Examples of org.hibernate.stat.SecondLevelCacheStatistics

        this.persistenceUnitRegistry = persistenceUnitRegistry;
    }

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

Examples of org.hibernate.stat.SecondLevelCacheStatistics

      withTx(tm, new Callable<Void>() {
         @Override
         public Void call() throws Exception {
            Session s = openSession();
            s.getTransaction().begin();
            SecondLevelCacheStatistics cStats = stats.getSecondLevelCacheStatistics( Item.class.getName() + ".items" );
            Item loadedWithCachedCollection = (Item) s.load( Item.class, item.getId() );
            stats.logSummary();
            assertEquals( item.getName(), loadedWithCachedCollection.getName() );
            assertEquals( item.getItems().size(), loadedWithCachedCollection.getItems().size() );
            assertEquals( 1, cStats.getHitCount() );
            Map cacheEntries = cStats.getEntries();
            assertEquals( 1, cacheEntries.size() );
            Item itemElement = loadedWithCachedCollection.getItems().iterator().next();
            itemElement.setOwner( null );
            loadedWithCachedCollection.getItems().clear();
            s.delete( itemElement );
View Full Code Here

Examples of org.hibernate.stat.SecondLevelCacheStatistics

  @Test
  @TestForIssue( jiraKey = "HHH-9231" )
  public void testAddNewOneToManyElementInitFlushLeaveCacheConsistent() throws Exception {
    Statistics stats = sessionFactory().getStatistics();
    stats.clear();
    SecondLevelCacheStatistics cStats = stats.getSecondLevelCacheStatistics( Item.class.getName() + ".items" );

    Item item = null;
    Transaction txn = null;
    Session s = null;
View Full Code Here

Examples of org.hibernate.stat.SecondLevelCacheStatistics

  @Test
  @TestForIssue( jiraKey = "HHH-9231" )
  public void testAddNewOneToManyElementNoInitFlushLeaveCacheConsistent() throws Exception {
    Statistics stats = sessionFactory().getStatistics();
    stats.clear();
    SecondLevelCacheStatistics cStats = stats.getSecondLevelCacheStatistics( Item.class.getName() + ".items" );

    Item item = null;
    Transaction txn = null;
    Session s = null;
View Full Code Here

Examples of org.hibernate.stat.SecondLevelCacheStatistics

  @Test
  public void testAddNewOneToManyElementNoInitFlushInitLeaveCacheConsistent() throws Exception {
    Statistics stats = sessionFactory().getStatistics();
    stats.clear();
    SecondLevelCacheStatistics cStats = stats.getSecondLevelCacheStatistics( Item.class.getName() + ".items" );

    Item item = null;
    Transaction txn = null;
    Session s = null;
View Full Code Here

Examples of org.hibernate.stat.SecondLevelCacheStatistics

  @Test
  public void testAddNewManyToManyPropertyRefNoInitFlushInitLeaveCacheConsistent() throws Exception {
    Statistics stats = sessionFactory().getStatistics();
    stats.clear();
    SecondLevelCacheStatistics cStats = stats.getSecondLevelCacheStatistics( Item.class.getName() + ".items" );

    OtherItem otherItem = null;
    Transaction txn = null;
    Session s = null;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.