Package org.hibernate.stat

Examples of org.hibernate.stat.SecondLevelCacheStatistics


    public long getEmployeesInMemory() {
        Session session = em.unwrap(Session.class);
        String entityRegionNames[] = session.getSessionFactory().getStatistics().getSecondLevelCacheRegionNames();
        for (String name : entityRegionNames) {
            if (name.contains(Employee.class.getName())) {
                SecondLevelCacheStatistics stats = session.getSessionFactory().getStatistics().getSecondLevelCacheStatistics(name);
                return stats.getElementCountInMemory();
            }
        }
        return -1;

    }
View Full Code Here


        session.getSessionFactory().getStatistics().setStatisticsEnabled(true);
        session.getSessionFactory().getStatistics().logSummary();
        String entityRegionNames[] = session.getSessionFactory().getStatistics().getSecondLevelCacheRegionNames();
        for (String name : entityRegionNames) {
            log.info("cache entity region name = " + name);
            SecondLevelCacheStatistics stats = session.getSessionFactory().getStatistics().getSecondLevelCacheStatistics(name);
            log.info("2lc for " + name + ": " + stats.toString());

        }
        // we will want to return the SecondLevelCacheStatistics for Employee

    }
View Full Code Here

    } else if(parent==queries) {
      return stats.getQueryStatistics(stats.getQueries()[index]);
    } else if(parent==secondlevelcache) {
      return stats.getSecondLevelCacheStatistics( stats.getSecondLevelCacheRegionNames()[index]);
    } else if(parent instanceof SecondLevelCacheStatistics) {
      SecondLevelCacheStatistics slcs = (SecondLevelCacheStatistics) parent;     
      return slcs.getEntries();
    }
    return null;
  }
View Full Code Here

    getCustomerIDs().add( customerId );

    assertNull( "contact exists despite not being added", getFirstContact( customerId ) );

    // check that cache was hit
    SecondLevelCacheStatistics customerSlcs = sessionFactory()
        .getStatistics()
        .getSecondLevelCacheStatistics( Customer.class.getName() );
    assertEquals( customerSlcs.getPutCount(), 1 );
    assertEquals( customerSlcs.getElementCountInMemory(), 1 );
    assertEquals( customerSlcs.getEntries().size(), 1 );

    log.infof( "Add contact to customer {0}", customerId );
    SecondLevelCacheStatistics contactsCollectionSlcs = sessionFactory()
        .getStatistics()
        .getSecondLevelCacheStatistics( Customer.class.getName() + ".contacts" );
    assertEquals( 1, contactsCollectionSlcs.getPutCount() );
    assertEquals( 1, contactsCollectionSlcs.getElementCountInMemory() );
    assertEquals( 1, contactsCollectionSlcs.getEntries().size() );

    final Contact contact = addContact( customerId );
    assertNotNull( "contact returned by addContact is null", contact );
    assertEquals(
        "Customer.contacts cache was not invalidated after addContact", 0,
        contactsCollectionSlcs.getElementCountInMemory()
    );

    assertNotNull( "Contact missing after successful add call", getFirstContact( customerId ) );

    // read everyone's contacts
View Full Code Here

      List<Integer> rhContacts = getContactsByCustomer( "Red Hat" );
      assertNotNull( "Red Hat contacts exist", rhContacts );
      assertEquals( "Created expected number of Red Hat contacts", 10, rhContacts.size() );

      SecondLevelCacheStatistics contactSlcs = sessionFactory()
          .getStatistics()
          .getSecondLevelCacheStatistics( Contact.class.getName() );
      assertEquals( 20, contactSlcs.getElementCountInMemory() );

      assertEquals( "Deleted all Red Hat contacts", 10, deleteContacts() );
      assertEquals( 0, contactSlcs.getElementCountInMemory() );

      List<Integer> jbContacts = getContactsByCustomer( "JBoss" );
      assertNotNull( "JBoss contacts exist", jbContacts );
      assertEquals( "JBoss contacts remain", 10, jbContacts.size() );

      for ( Integer id : rhContacts ) {
        assertNull( "Red Hat contact " + id + " cannot be retrieved", getContact( id ) );
      }
      rhContacts = getContactsByCustomer( "Red Hat" );
      if ( rhContacts != null ) {
        assertEquals( "No Red Hat contacts remain", 0, rhContacts.size() );
      }

      updateContacts( "Kabir", "Updated" );
      assertEquals( 0, contactSlcs.getElementCountInMemory() );
      for ( Integer id : jbContacts ) {
        Contact contact = getContact( id );
        assertNotNull( "JBoss contact " + id + " exists", contact );
        String expected = ("Kabir".equals( contact.getName() )) ? "Updated" : "2222";
        assertEquals( "JBoss contact " + id + " has correct TLF", expected, contact.getTlf() );
      }

      List<Integer> updated = getContactsByTLF( "Updated" );
      assertNotNull( "Got updated contacts", updated );
      assertEquals( "Updated contacts", 5, updated.size() );

      updateContactsWithOneManual( "Kabir", "UpdatedAgain" );
      assertEquals( contactSlcs.getElementCountInMemory(), 0 );
      for ( Integer id : jbContacts ) {
        Contact contact = getContact( id );
        assertNotNull( "JBoss contact " + id + " exists", contact );
        String expected = ("Kabir".equals( contact.getName() )) ? "UpdatedAgain" : "2222";
        assertEquals( "JBoss contact " + id + " has correct TLF", expected, contact.getTlf() );
View Full Code Here

        int totalMemorySize = 0;
        int totalMemoryCount = 0;
        int totalDiskCount = 0;

        for(String secondLevelCacheRegionName : secondLevelCacheRegionNames) {
            SecondLevelCacheStatistics secondLevelCacheStatistics =
                    statistics.getSecondLevelCacheStatistics(secondLevelCacheRegionName);
            totalMemorySize += secondLevelCacheStatistics.getSizeInMemory();
            totalMemoryCount += secondLevelCacheStatistics.getElementCountInMemory();
            totalDiskCount += secondLevelCacheStatistics.getElementCountOnDisk();
        }

        model.addAttribute("totalMemorySize", totalMemorySize);
        model.addAttribute("totalMemoryCount", totalMemoryCount);
        model.addAttribute("totalDiskCount", totalDiskCount);
View Full Code Here

    getCustomerIDs().add( customerId );

    assertNull( "contact exists despite not being added", getFirstContact( customerId ) );

    // check that cache was hit
    SecondLevelCacheStatistics customerSlcs = sessionFactory()
        .getStatistics()
        .getSecondLevelCacheStatistics( Customer.class.getName() );
    assertEquals( customerSlcs.getPutCount(), 1 );
    assertEquals( customerSlcs.getElementCountInMemory(), 1 );
    assertEquals( customerSlcs.getEntries().size(), 1 );

    log.infof( "Add contact to customer {0}", customerId );
    SecondLevelCacheStatistics contactsCollectionSlcs = sessionFactory()
        .getStatistics()
        .getSecondLevelCacheStatistics( Customer.class.getName() + ".contacts" );
    assertEquals( 1, contactsCollectionSlcs.getPutCount() );
    assertEquals( 1, contactsCollectionSlcs.getElementCountInMemory() );
    assertEquals( 1, contactsCollectionSlcs.getEntries().size() );

    final Contact contact = addContact( customerId );
    assertNotNull( "contact returned by addContact is null", contact );
    assertEquals(
        "Customer.contacts cache was not invalidated after addContact", 0,
        contactsCollectionSlcs.getElementCountInMemory()
    );

    assertNotNull( "Contact missing after successful add call", getFirstContact( customerId ) );

    // read everyone's contacts
View Full Code Here

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

    i.setDescription("A really top-quality, full-featured widget.");
    s.persist(i);
    t.commit();
    s.close();

    SecondLevelCacheStatistics slcs = s.getSessionFactory().getStatistics()
        .getSecondLevelCacheStatistics( Item.class.getName() );

    assertEquals( slcs.getPutCount(), 1 );
    assertEquals( slcs.getElementCountInMemory(), 1 );
    assertEquals( slcs.getEntries().size(), 1 );

    s = openSession();
    t = s.beginTransaction();
    i = (Item) s.get( Item.class, i.getId() );

    assertEquals( slcs.getHitCount(), 1 );
    assertEquals( slcs.getMissCount(), 0 );

    i.setDescription("A bog standard item");

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

    assertEquals( slcs.getPutCount(), 2 );

    Object entry = slcs.getEntries().get( i.getId() );
    Map map;
    if ( entry instanceof ReadWriteCache.Item ) {
      map = (Map) ( (ReadWriteCache.Item) entry ).getValue();
    }
    else {
View Full Code Here

  public void testEmptySecondLevelCacheEntry() throws Exception {
    getSessions().evictEntity( Item.class.getName() );
    Statistics stats = getSessions().getStatistics();
    stats.clear();
    SecondLevelCacheStatistics statistics = stats.getSecondLevelCacheStatistics( Item.class.getName() );
        Map cacheEntries = statistics.getEntries();
    assertEquals( 0, cacheEntries.size() );
  }
View Full Code Here

TOP

Related Classes of org.hibernate.stat.SecondLevelCacheStatistics

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.