public abstract class EntityManagerFactoryUtils extends ObjectSE
主にフレームワーク内での内部使用を目的としています。
修飾子と型 | フィールドと説明 |
---|---|
static int | ENTITY_MANAGER_SYNCHRONIZATION_ORDER JPA EntityManagers をクリーンアップする TransactionSynchronization オブジェクトのオーダー値。 |
コンストラクターと説明 |
---|
EntityManagerFactoryUtils() |
修飾子と型 | メソッドと説明 |
---|---|
static void | applyTransactionTimeout(QueryEE query, EntityManagerFactoryEE emf) 現在のトランザクションタイムアウトがある場合は、指定された JPA クエリオブジェクトに適用します。 |
static void | closeEntityManager(EntityManagerEE em) 指定された JPA EntityManager を閉じ、スローされたクリーンアップ例外をキャッチしてログに記録します。 |
static DataAccessException | convertJpaAccessExceptionIfPossible(RuntimeExceptionSE ex) 指定されたランタイム例外を、 org.springframework.dao 階層からの適切な例外に変換します。 |
static EntityManagerEE | doGetTransactionalEntityManager(EntityManagerFactoryEE emf, MapSE<?,?> properties) 指定されたファクトリから JPA EntityManager を取得します。 |
static EntityManagerEE | doGetTransactionalEntityManager(EntityManagerFactoryEE emf, MapSE<?,?> properties, boolean synchronizedWithTransaction) 指定されたファクトリから JPA EntityManager を取得します。 |
static EntityManagerFactoryEE | findEntityManagerFactory(ListableBeanFactory beanFactory, StringSE unitName) 指定された Spring アプリケーションコンテキスト(ListableBeanFactory で表されます)で指定された名前の EntityManagerFactory を見つけます。 |
static EntityManagerEE | getTransactionalEntityManager(EntityManagerFactoryEE emf) 指定されたファクトリから JPA EntityManager を取得します。 |
static EntityManagerEE | getTransactionalEntityManager(EntityManagerFactoryEE emf, MapSE<?,?> properties) 指定されたファクトリから JPA EntityManager を取得します。 |
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, toStringSE, waitSE, waitSE, waitSE
public static final int ENTITY_MANAGER_SYNCHRONIZATION_ORDER
public static EntityManagerFactoryEE findEntityManagerFactory(ListableBeanFactory beanFactory, @Nullable StringSE unitName) throws NoSuchBeanDefinitionException
検出された EntityManagerFactory が EntityManagerFactoryInfo
インターフェースを実装している場合、指定されたユニット名は構成された永続性ユニットと照合されます。そうでない場合、EntityManagerFactory Bean 名がその規則に従っていると想定して、永続性ユニット名は Spring Bean 名と照合されます。
ユニット名が指定されていない場合、このメソッドはデフォルトの EntityManagerFactory から BeanFactory.getBean(Class)
を検索します。
beanFactory
- 検索する ListableBeanFactoryunitName
- 永続性ユニットの名前 (null
または空の場合があります。その場合、型 EntityManagerFactory の単一の Bean が検索されます。)NoSuchBeanDefinitionException
- コンテキストにそのような EntityManagerFactory がない場合 EntityManagerFactoryInfo.getPersistenceUnitName()
@Nullable public static EntityManagerEE getTransactionalEntityManager(EntityManagerFactoryEE emf) throws DataAccessResourceFailureException
メモ: スレッドバインドの EntityManager が見つからない場合、null
を返します。
emf
- EntityManager を作成する EntityManagerFactorynull
DataAccessResourceFailureException
- EntityManager を取得できなかった場合 JpaTransactionManager
@Nullable public static EntityManagerEE getTransactionalEntityManager(EntityManagerFactoryEE emf, @Nullable MapSE<?,?> properties) throws DataAccessResourceFailureException
メモ: スレッドバインドの EntityManager が見つからない場合、null
を返します。
emf
- EntityManager を作成する EntityManagerFactoryproperties
- createEntityManager
呼び出しに渡されるプロパティ (null
の場合があります)null
DataAccessResourceFailureException
- EntityManager を取得できなかった場合 JpaTransactionManager
@Nullable public static EntityManagerEE doGetTransactionalEntityManager(EntityManagerFactoryEE emf, MapSE<?,?> properties) throws PersistenceExceptionEE
getEntityManager
と同じですが、元の PersistenceException をスローします。
emf
- EntityManager を作成する EntityManagerFactoryproperties
- createEntityManager
呼び出しに渡されるプロパティ (null
の場合があります)null
PersistenceExceptionEE
- EntityManager を作成できなかった場合 getTransactionalEntityManager(javax.persistence.EntityManagerFactory)
, JpaTransactionManager
@Nullable public static EntityManagerEE doGetTransactionalEntityManager(EntityManagerFactoryEE emf, @Nullable MapSE<?,?> properties, boolean synchronizedWithTransaction) throws PersistenceExceptionEE
getEntityManager
と同じですが、元の PersistenceException をスローします。
emf
- EntityManager を作成する EntityManagerFactoryproperties
- createEntityManager
呼び出しに渡されるプロパティ (null
の場合があります)synchronizedWithTransaction
- 進行中のトランザクションに自動的に参加するかどうか (JPA 2.1 SynchronizationType ルールに準拠)null
PersistenceExceptionEE
- EntityManager を作成できなかった場合 getTransactionalEntityManager(javax.persistence.EntityManagerFactory)
, JpaTransactionManager
public static void applyTransactionTimeout(QueryEE query, EntityManagerFactoryEE emf)
このメソッドは、それに応じて JPA 2.0 クエリヒント "javax.persistence.query.timeout" を設定します。
query
- JPA クエリオブジェクト emf
- クエリが作成された JPA EntityManagerFactory@Nullable public static DataAccessException convertJpaAccessExceptionIfPossible(RuntimeExceptionSE ex)
org.springframework.dao
階層からの適切な例外に変換します。適切な変換がない場合は null を返します。他の例外はユーザーコードが原因である可能性があるため、変換しないでください。ここでは、オブジェクトが見つからない、楽観的ロックの失敗などの最も重要なケースについて説明します。より細かく変換するために、JpaTransactionManager などは JpaDialect を介した例外の高度な変換をサポートしています。
ex
- 発生したランタイム例外 null
public static void closeEntityManager(@Nullable EntityManagerEE em)
em
- JPA EntityManager を閉じる (null
の場合があります)EntityManager.close()
EE