public class OpenEntityManagerInViewFilter extends OncePerRequestFilter
このフィルターは、トランザクションマネージャーによって自動検出される現在のスレッドを介して JPA EntityManagers を利用できるようにします。JpaTransactionManager
または JtaTransactionManager
を介したサービスレイヤートランザクション、および非トランザクションの読み取り専用実行に適しています。
Spring のルート Web アプリケーションコンテキストで EntityManagerFactory を検索します。web.xml
で "entityManagerFactoryBeanName" フィルター init-param をサポートします。デフォルトの Bean 名は "entityManagerFactory" です。代わりに、"persistenceUnitName" init-param を使用すると、論理ユニット名 (persistence.xml
で指定) による取得が可能になります。
OpenEntityManagerInViewInterceptor
, JpaTransactionManager
, SharedEntityManagerCreator
, TransactionSynchronizationManager
修飾子と型 | フィールドと説明 |
---|---|
static StringSE | DEFAULT_ENTITY_MANAGER_FACTORY_BEAN_NAME デフォルトの EntityManagerFactory Bean 名: "entityManagerFactory" . |
ALREADY_FILTERED_SUFFIX
logger
コンストラクターと説明 |
---|
OpenEntityManagerInViewFilter() |
修飾子と型 | メソッドと説明 |
---|---|
protected EntityManagerEE | createEntityManager(EntityManagerFactoryEE emf) リクエストにバインドされる JPA EntityManager を作成します。 |
protected void | doFilterInternal(HttpServletRequestEE request, HttpServletResponseEE response, FilterChainEE filterChain) doFilter と同じ契約ですが、単一のリクエストスレッド内のリクエストごとに 1 回だけ呼び出されることが保証されています。 |
protected StringSE | getEntityManagerFactoryBeanName() Spring のルートアプリケーションコンテキストから取得する EntityManagerFactory の Bean 名を返します。 |
protected StringSE | getPersistenceUnitName() EntityManagerFactory にアクセスする永続性ユニットの名前を返します(存在する場合)。 |
protected EntityManagerFactoryEE | lookupEntityManagerFactory() このフィルターが使用する EntityManagerFactory を調べます。 |
protected EntityManagerFactoryEE | lookupEntityManagerFactory(HttpServletRequestEE request) 現在の HTTP リクエストを引数として、このフィルターが使用する EntityManagerFactory を検索します。 |
void | setEntityManagerFactoryBeanName(StringSE entityManagerFactoryBeanName) EntityManagerFactory の Bean 名を設定して、Spring のルートアプリケーションコンテキストから取得します。 |
void | setPersistenceUnitName(StringSE persistenceUnitName) EntityManagerFactory にアクセスする永続性ユニットの名前を設定します。 |
protected boolean | shouldNotFilterAsyncDispatch() フィルターが開いた EntityManager を非同期にディスパッチされた各スレッドに再バインドし、最後の非同期ディスパッチまで閉じるのを延期するように、"false" を返します。 |
protected boolean | shouldNotFilterErrorDispatch() フィルターが各エラーディスパッチに EntityManager を提供できるように、"false" を返します。 |
doFilter, doFilterNestedErrorDispatch, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter
addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, toStringSE, waitSE, waitSE, waitSE
public static final StringSE DEFAULT_ENTITY_MANAGER_FACTORY_BEAN_NAME
public void setEntityManagerFactoryBeanName(@Nullable StringSE entityManagerFactoryBeanName)
デフォルトは "entityManagerFactory" です。このデフォルトは、"persistenceUnitName" パラメーターが指定されていない場合にのみ適用されることに注意してください。
@Nullable protected StringSE getEntityManagerFactoryBeanName()
public void setPersistenceUnitName(@Nullable StringSE persistenceUnitName)
これは、Bean 名で EntityManagerFactory を指定する代わりに、永続ユニット名で解決する方法です。Bean 名と永続ユニット名が指定されていない場合は、デフォルトの Bean 名 "entityManagerFactory" に対して Bean が存在するかどうかを確認します。存在しない場合は、型 EntityManagerFactory の単一の一意の Bean を検索して、デフォルトの EntityManagerFactory を取得します。
@Nullable protected StringSE getPersistenceUnitName()
protected boolean shouldNotFilterAsyncDispatch()
EntityManager
を非同期にディスパッチされた各スレッドに再バインドし、最後の非同期ディスパッチまで閉じるのを延期するように、"false" を返します。OncePerRequestFilter
の shouldNotFilterAsyncDispatch
protected boolean shouldNotFilterErrorDispatch()
EntityManager
を提供できるように、"false" を返します。OncePerRequestFilter
の shouldNotFilterErrorDispatch
protected void doFilterInternal(HttpServletRequestEE request, HttpServletResponseEE response, FilterChainEE filterChain) throws ServletExceptionEE, IOExceptionSE
OncePerRequestFilter
doFilter
と同じ契約ですが、単一のリクエストスレッド内のリクエストごとに 1 回だけ呼び出されることが保証されています。詳細については、OncePerRequestFilter.shouldNotFilterAsyncDispatch()
を参照してください。デフォルトの ServletRequest および ServletResponse の代わりに、HttpServletRequest および HttpServletResponse 引数を提供します。
OncePerRequestFilter
の doFilterInternal
ServletExceptionEE
IOExceptionSE
protected EntityManagerFactoryEE lookupEntityManagerFactory(HttpServletRequestEE request)
デフォルトの実装は、引数なしで lookupEntityManagerFactory
に委譲し、取得された EntityManagerFactory 参照をキャッシュします。
lookupEntityManagerFactory()
protected EntityManagerFactoryEE lookupEntityManagerFactory()
デフォルトの実装では、Spring のルートアプリケーションコンテキストで指定された名前の Bean を探します。
getEntityManagerFactoryBeanName()
protected EntityManagerEE createEntityManager(EntityManagerFactoryEE emf)
サブクラスでオーバーライドできます。
emf
- 使用する EntityManagerFactoryEntityManagerFactory.createEntityManager()
EE