Project

General

Profile

6695a_ecf_20220823.patch

Eric Faulhaber, 08/23/2022 06:31 PM

Download (3.55 KB)

View differences:

src/com/goldencode/p2j/persist/PreselectQuery.java 2022-08-23 22:26:37 +0000
3898 3898
   {
3899 3899
      if (!closed)
3900 3900
      {
3901
         System.out.println(hql);
3901 3902
         if (results != null)
3902 3903
         {
3903 3904
            results.cleanup();
......
3911 3912
            regWithSession = false;
3912 3913
            persistence.deregisterSessionListener(this);
3913 3914
         }
3915
         
3916
         SQLQuery.printMsg();
3914 3917
      }
3915 3918
   }
3916 3919
   
src/com/goldencode/p2j/persist/orm/SQLQuery.java 2022-08-23 19:32:24 +0000
635 635
    * @throws  PersistenceException
636 636
    *          When an issue was encountered in the process.
637 637
    */
638
   private static int hits = 0;
639
   private static int misses = 0;
640
   private static int cached = 0;
638 641
   static BaseRecord hydrateRecord(ResultSet resultSet,
639 642
                                   Class<? extends DataModelObject> iface,
640 643
                                   int rsOffset,
......
659 662
         Record cachedRec = session.getCached(recordClass, pk);
660 663
         if (cachedRec != null && !cachedRec.checkState(DmoState.STALE))
661 664
         {
665
            hits++;
662 666
            // we found an unSTALE CACHED record, do not bother reading from result set
663 667
            return cachedRec;
664 668
         }
......
666 670
         if (count == 1)
667 671
         {
668 672
            cachedRec = session.get(recordClass, pk);
669
            
673
            hits++;
670 674
            return cachedRec;
671 675
         }
672 676
      }
......
675 679
         // just log it, but continue to let the generic hydration detect other issues
676 680
         log.log(Level.WARNING, "Failed to locate the primary key of " + iface.getSimpleName() + ".");
677 681
      }
682
      finally
683
      {
684
         cached = Math.max(cached, session.getCacheSize());
685
      }
678 686
      
679 687
      BaseRecord r = null;
680 688
      try
681 689
      {
690
         misses++;
682 691
         r = recordClass.newInstance();
683 692
         
684 693
         // see FqlToSqlConverter.expandAlias()
......
784 793
      {
785 794
         throw new PersistenceException("Failed to populate record for class " + iface.getName(), e);
786 795
      }
796
      finally
797
      {
798
         cached = Math.max(cached, session.getCacheSize());
799
      }
787 800
      
788 801
      return r;
789 802
   }
790 803
   
804
   public static void printMsg()
805
   {
806
      int total = hits + misses;
807
      float hitRate = total == 0 ? 0.0f : hits / (float) total;
808
      System.out.println("hit/miss: " + hits + "/" + misses +
809
                         "; rate = " + hitRate +
810
                         "; total = " + total +
811
                         "; cached: " + cached);
812
      hits = 0;
813
      misses = 0;
814
      cached = 0;
815
   }
816
   
791 817
   /**
792 818
    * Closes this object by releasing all acquired resources.
793 819
    */
src/com/goldencode/p2j/persist/orm/Session.java 2022-08-23 22:28:39 +0000
500 500
      return getImpl(null, id, new RecordIdentifier<>(entity, id));
501 501
   }
502 502
   
503
   int getCacheSize()
504
   {
505
      return cache == null ? 0 : cache.size();
506
   }
507
   
503 508
   /**
504 509
    * Get a record. If found in cache, it is returned immediately, otherwise the database is
505 510
    * queried for the specified record. If found, it is saved to cache and returned. Otherwise