Package org.hibernate.stat

Examples of org.hibernate.stat.Statistics


      beginTx();
      try {
         Session s = openSession();
         Item found = (Item) s.load(Item.class, item.getId());
         Statistics stats = s.getSessionFactory().getStatistics();
         log.info(stats.toString());
         assertEquals(item.getDescription(), found.getDescription());
         assertEquals(0, stats.getSecondLevelCacheMissCount());
         assertEquals(1, stats.getSecondLevelCacheHitCount());
         s.delete(found);
         s.close();
      } catch (Exception e) {
         setRollbackOnlyTx(e);
      } finally {
View Full Code Here


         ut.begin();
         try {
            Session session = sessionFactory.openSession();
            session.getTransaction().begin();
            Item found = (Item) session.load(Item.class, item.getId());
            Statistics stats = session.getSessionFactory().getStatistics();
            log.info(stats.toString());
            assertEquals(item.getDescription(), found.getDescription());
            assertEquals(0, stats.getSecondLevelCacheMissCount());
            assertEquals(1, stats.getSecondLevelCacheHitCount());
            session.delete(found);
            session.getTransaction().commit();
            session.close();
         } catch(Exception e) {
            ut.setRollbackOnly();
View Full Code Here

    s.close();
  }

  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

   * Check if disabling 2LC works as expected
   */
  public String disabled2LCCheck() {
   
    EntityManager em = emfNo2LC.createEntityManager();
    Statistics stats = em.unwrap(Session.class).getSessionFactory().getStatistics();
    stats.clear();
   
    try {
      // check if entities are NOT cached in 2LC
      String names[] = stats.getSecondLevelCacheRegionNames();
      assertEquals("There aren't any 2LC regions.", 0, names.length);

      createEmployee(em, "Martin", "Prague 132", 1);
      assertEquals("There aren't any puts in the 2LC.", 0,stats.getSecondLevelCachePutCount());

      // check if queries are NOT cached in 2LC
      Employee emp = getEmployeeQuery(em, 1);
      assertNotNull("Employee returned", emp);
      assertEquals("There aren't any query puts in the 2LC.", 0,stats.getQueryCachePutCount());
     
      // cleanup
      em.remove(emp);
     
    }catch (AssertionError e) {
View Full Code Here

   *  Checking entity 2LC in one EntityManager session
   */
  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);
View Full Code Here

   *  Checking entity 2LC in a different EntityManager session
   */
  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());
View Full Code Here

   * Insert 2 entities and put them into the 2LC and then evicts entity cache.
   */
  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());
View Full Code Here

   * Checks if entity 2LC is empty.
   */
  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
View Full Code Here

   * @param id Employee's id in the query
   */
  public String queryCacheCheck(String id){
   
    EntityManager em = emf.createEntityManager();
    Statistics stats = em.unwrap(Session.class).getSessionFactory().getStatistics();
    stats.clear();

    try{
          // the nextTimestamp from infinispan is "return System.currentTimeMillis() / 100;"
          Thread.sleep(1000);
         
      String queryString = "from Employee e where e.id > "+id;
      QueryStatistics queryStats = stats.getQueryStatistics(queryString);
      Query query = em.createQuery(queryString);
      query.setHint("org.hibernate.cacheable", true);

      // query - this call should fill the cache
      query.getResultList();
View Full Code Here

   * @param id Employee's id in the query
   */
  public String queryCacheCheckIfEmpty(String id){
   
    EntityManager em = emf.createEntityManager();
    Statistics stats = em.unwrap(Session.class).getSessionFactory().getStatistics();
    stats.clear();

    try{
          // the nextTimestamp from infinispan is "return System.currentTimeMillis() / 100;"
          Thread.sleep(1000);
         
      String queryString = "from Employee e where e.id > "+id;
      QueryStatistics queryStats = stats.getQueryStatistics(queryString);
      Query query = em.createQuery(queryString);
      query.setHint("org.hibernate.cacheable", true);

      // query - this call shouldn't hit the cache -> query cache is empty
      query.getResultList();
View Full Code Here

TOP

Related Classes of org.hibernate.stat.Statistics

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.