クラス OpenEntityManagerInViewFilter

実装されたすべてのインターフェース:
FilterEEAwareBeanNameAwareDisposableBeanInitializingBeanEnvironmentAwareEnvironmentCapableServletContextAware

public class OpenEntityManagerInViewFilter extends OncePerRequestFilter
JPA EntityManager をリクエストの処理全体のスレッドにバインドするサーブレットフィルター。"Open EntityManager in View" パターン、つまり元のトランザクションがすでに完了しているにもかかわらず Web ビューで遅延読み込みを可能にすることを目的としています。

このフィルターは、トランザクションマネージャーによって自動検出される現在のスレッドを介して JPA EntityManagers を利用できるようにします。JpaTransactionManager または JtaTransactionManager を介したサービスレイヤートランザクション、および非トランザクションの読み取り専用実行に適しています。

Spring のルート Web アプリケーションコンテキストで EntityManagerFactory を検索します。web.xml で "entityManagerFactoryBeanName" フィルターの init-param をサポートします。デフォルトの Bean 名は "entityManagerFactory" です。代わりに、"persistenceUnitName" init-param を使用すると、論理ユニット名(persistence.xml で指定)で検索できます。

導入:
2.0
作成者:
Juergen Hoeller
関連事項:
  • フィールドの詳細

  • コンストラクターの詳細

    • OpenEntityManagerInViewFilter

      public OpenEntityManagerInViewFilter()
  • メソッドの詳細

    • setEntityManagerFactoryBeanName

      public void setEntityManagerFactoryBeanName(@Nullable StringSE entityManagerFactoryBeanName)
      EntityManagerFactory の Bean 名を設定して、Spring のルートアプリケーションコンテキストから取得します。

      デフォルトは "entityManagerFactory" です。このデフォルトは、"persistenceUnitName" パラメーターが指定されていない場合にのみ適用されることに注意してください。

      関連事項:
    • getEntityManagerFactoryBeanName

      @Nullable protected StringSE getEntityManagerFactoryBeanName()
      Spring のルートアプリケーションコンテキストから取得する EntityManagerFactory の Bean 名を返します。
    • setPersistenceUnitName

      public void setPersistenceUnitName(@Nullable StringSE persistenceUnitName)
      EntityManagerFactory にアクセスする永続性ユニットの名前を設定します。

      これは、EntityManagerFactory を Bean 名で指定する代わりに、永続化ユニット名で解決します。Bean 名も永続ユニット名も指定されていない場合は、デフォルトの Bean 名 "entityManagerFactory" に Bean が存在するかどうかを確認します。そうでない場合、デフォルトの EntityManagerFactory は、型 EntityManagerFactory の単一の固有の Bean を見つけることによって取得されます。

      関連事項:
    • getPersistenceUnitName

      @Nullable protected StringSE getPersistenceUnitName()
      EntityManagerFactory にアクセスする永続性ユニットの名前を返します(存在する場合)。
    • shouldNotFilterAsyncDispatch

      protected boolean shouldNotFilterAsyncDispatch()
      フィルターが開いた EntityManager を非同期にディスパッチされた各スレッドに再バインドし、最後の非同期ディスパッチまで閉じるのを延期するように、"false" を返します。
      オーバーライド:
      クラス OncePerRequestFiltershouldNotFilterAsyncDispatch 
    • shouldNotFilterErrorDispatch

      protected boolean shouldNotFilterErrorDispatch()
      フィルターが各エラーディスパッチに EntityManager を提供できるように、"false" を返します。
      オーバーライド:
      クラス OncePerRequestFiltershouldNotFilterErrorDispatch 
    • doFilterInternal

      protected void doFilterInternal(HttpServletRequestEE request, HttpServletResponseEE response, FilterChainEE filterChain) throws ServletExceptionEE, IOExceptionSE
      クラスからコピーされた説明: OncePerRequestFilter
      doFilter と同じ契約ですが、単一のリクエストスレッド内のリクエストごとに 1 回だけ呼び出されることが保証されています。詳細については、OncePerRequestFilter.shouldNotFilterAsyncDispatch() を参照してください。

      デフォルトの ServletRequest および ServletResponse の代わりに、HttpServletRequest および HttpServletResponse 引数を提供します。

      次で指定:
      クラス OncePerRequestFilterdoFilterInternal 
      例外:
      ServletExceptionEE
      IOExceptionSE
    • lookupEntityManagerFactory

      protected EntityManagerFactoryEE lookupEntityManagerFactory(HttpServletRequestEE request)
      現在の HTTP リクエストを引数として、このフィルターが使用する EntityManagerFactory を検索します。

      デフォルトの実装は、引数なしで lookupEntityManagerFactory に委譲し、取得された EntityManagerFactory 参照をキャッシュします。

      戻り値:
      使用する EntityManagerFactory
      関連事項:
    • lookupEntityManagerFactory

      protected EntityManagerFactoryEE lookupEntityManagerFactory()
      このフィルターが使用する EntityManagerFactory を調べます。

      デフォルトの実装では、Spring のルートアプリケーションコンテキストで指定された名前の Bean を探します。

      戻り値:
      使用する EntityManagerFactory
      関連事項:
    • createEntityManager

      protected EntityManagerEE createEntityManager(EntityManagerFactoryEE emf)
      リクエストにバインドされる JPA EntityManager を作成します。

      サブクラスでオーバーライドできます。

      パラメーター:
      emf - 使用する EntityManagerFactory
      関連事項: