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 |
*/
|