2012-12-28 69 views
0

我想查看EclipseLink中的隔離緩存(L1緩存)中存儲了哪些對象。有沒有讓我這樣做的API?我試過谷歌,但找不到任何東西。如何在EclipseLink中打印存儲在獨立緩存中的對象?

如果您有興趣瞭解爲什麼這是因爲我發現在持久化上下文中加載某些對象之後,查詢速度減慢,例如僅在事務啓動時花費了100毫秒的查詢,現在需要200毫秒在一些其他操作已經發生之後在交易中間執行。如果我在執行查詢之前執行entityManager.clear(),則查詢再次需要100毫秒。我相信會發生這種情況,因爲Persistence Context中有很多對象會影響EclipseLink的性能。這就是爲什麼我想驗證持久化上下文中有哪些對象。

回答

0

在瀏覽完EclipseLink源代碼後,我發現存儲在持久化上下文(獨立緩存)中的對象位於名爲identityMaps的映射中,對於每個實體類都有一個存儲該類型所有對象的映射。

您可以使用以下方法打印地圖的內容:

public interface IdentityMapAccessor { 
    /** 
    * PUBLIC: 
    * Used to print all the Objects in the identity map of the given Class type. 
    * The output of this method will be logged to this session's SessionLog at SEVERE level. 
    */ 
    public void printIdentityMap(Class theClass); 

    /** 
    * PUBLIC: 
    * Used to print all the Objects in every identity map in this session. 
    * The output of this method will be logged to this session's SessionLog at SEVERE level. 
    */ 
    public void printIdentityMaps(); 
} 

例子:

((JpaEntityManager) entityManager.getDelegate()) 
      .getActiveSession() 
      .getIdentityMapAccessor() 
      .printIdentityMaps(); 
((JpaEntityManager) entityManager.getDelegate()) 
      .getActiveSession() 
      .getIdentityMapAccessor() 
      .printIdentityMap(MyClass.class); 
相關問題