public abstract class TransactionAspectSupport extends ObjectSE implements BeanFactoryAware, InitializingBean
TransactionInterceptor
や AspectJ アスペクトなどのトランザクションアスペクトの基本クラス。これにより、基になる Spring トランザクションインフラストラクチャを簡単に使用して、任意のアスペクトシステムのアスペクトを実装できます。
サブクラスは、このクラスのメソッドを正しい順序で呼び出すロールを果たします。
TransactionAttribute
でトランザクション名が指定されていない場合、公開される名前は fully-qualified class name + "." + method name
(デフォルト)です。
Strategy デザインパターンを使用します。PlatformTransactionManager
または ReactiveTransactionManager
の実装は実際のトランザクション管理を実行し、TransactionAttributeSource
(たとえばアノテーションベース)は特定のクラスまたはメソッドのトランザクション定義を決定するために使用されます。
PlatformTransactionManager
と TransactionAttributeSource
が直列化可能な場合、トランザクションアスペクトは直列化可能です。
PlatformTransactionManager
, ReactiveTransactionManager
, setTransactionManager(org.springframework.transaction.TransactionManager)
, setTransactionAttributes(java.util.Properties)
, setTransactionAttributeSource(org.springframework.transaction.interceptor.TransactionAttributeSource)
修飾子と型 | クラスと説明 |
---|---|
protected static interface | TransactionAspectSupport.InvocationCallback ターゲット呼び出しを続行するためのシンプルなコールバックインターフェース。 |
protected static class | TransactionAspectSupport.TransactionInfo トランザクション情報を保持するために使用される不透明なオブジェクト。 |
修飾子 | コンストラクターと説明 |
---|---|
protected | TransactionAspectSupport() |
修飾子と型 | メソッドと説明 |
---|---|
void | afterPropertiesSet() 必要なプロパティが設定されていることを確認します。 |
protected void | cleanupTransactionInfo(TransactionAspectSupport.TransactionInfo txInfo) TransactionInfo ThreadLocal をリセットします。 |
protected void | clearTransactionManagerCache() キャッシュをクリアします。 |
protected void | commitTransactionAfterReturning(TransactionAspectSupport.TransactionInfo txInfo) 呼び出しが正常に完了した後で実行されますが、例外が処理された後ではありません。 |
protected void | completeTransactionAfterThrowing(TransactionAspectSupport.TransactionInfo txInfo, ThrowableSE ex) スロー可能オブジェクトを処理し、トランザクションを完了します。 |
protected TransactionAspectSupport.TransactionInfo | createTransactionIfNecessary(PlatformTransactionManager tm, TransactionAttribute txAttr, StringSE joinpointIdentification) 必要に応じて、指定された TransactionAttribute に基づいてトランザクションを作成します。 |
protected static TransactionAspectSupport.TransactionInfo | currentTransactionInfo() サブクラスはこれを使用して、現在の TransactionInfo を返すことができます。 |
static TransactionStatus | currentTransactionStatus() 現在のメソッド呼び出しのトランザクションステータスを返します。 |
protected TransactionManager | determineTransactionManager(TransactionAttribute txAttr) 特定のトランザクションに使用する特定のトランザクションマネージャーを決定します。 |
protected BeanFactory | getBeanFactory() PlatformTransactionManager Bean の取得に使用する BeanFactory を返します。 |
TransactionAttributeSource | getTransactionAttributeSource() トランザクション属性ソースを返します。 |
TransactionManager | getTransactionManager() デフォルトのトランザクションマネージャー、または不明の場合は null を返します。 |
protected StringSE | getTransactionManagerBeanName() デフォルトのトランザクションマネージャー Bean の名前を返します。 |
protected ObjectSE | invokeWithinTransaction(MethodSE method, ClassSE<?> targetClass, TransactionAspectSupport.InvocationCallback invocation) アドバイスに基づくサブクラスの一般的なデリゲート。このクラスの他のいくつかのテンプレートメソッドに委譲します。 |
protected StringSE | methodIdentification(MethodSE method, ClassSE<?> targetClass) ロギングで使用するためにこのメソッドの文字列表現を返す簡易メソッド。 |
protected TransactionAspectSupport.TransactionInfo | prepareTransactionInfo(PlatformTransactionManager tm, TransactionAttribute txAttr, StringSE joinpointIdentification, TransactionStatus status) 指定された属性およびステータスオブジェクトの TransactionInfo を準備します。 |
void | setBeanFactory(BeanFactory beanFactory) PlatformTransactionManager Bean の取得に使用する BeanFactory を設定します。 |
void | setTransactionAttributes(PropertiesSE transactionAttributes) メソッド名をキーとして、トランザクション属性記述子(TransactionAttributeEditor を介して解析)を値としてプロパティを設定します。 |
void | setTransactionAttributeSource(TransactionAttributeSource transactionAttributeSource) トランザクション属性の検索に使用されるトランザクション属性ソースを設定します。 |
void | setTransactionAttributeSources(TransactionAttributeSource... transactionAttributeSources) トランザクション属性の検索に使用される複数のトランザクション属性ソースを設定します。 |
void | setTransactionManager(TransactionManager transactionManager) トランザクションの駆動に使用するデフォルトのトランザクションマネージャーを指定します。 |
void | setTransactionManagerBeanName(StringSE transactionManagerBeanName) デフォルトのトランザクションマネージャー Bean の名前を指定します。 |
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, toStringSE, waitSE, waitSE, waitSE
protected final Log logger
@Nullable protected static TransactionAspectSupport.TransactionInfo currentTransactionInfo() throws NoTransactionException
トランザクションが作成されていなくても、TransactionInfo が返されます。これを照会するには、TransactionInfo.hasTransaction()
メソッドを使用できます。
特定のトランザクション特性について調べるには、TransactionSynchronizationManager の isSynchronizationActive()
および / または isActualTransactionActive()
メソッドの使用を検討してください。
null
NoTransactionException
TransactionAspectSupport.TransactionInfo.hasTransaction()
, TransactionSynchronizationManager.isSynchronizationActive()
, TransactionSynchronizationManager.isActualTransactionActive()
public static TransactionStatus currentTransactionStatus() throws NoTransactionException
NoTransactionException
- メソッドが AOP 呼び出しコンテキストの外で呼び出されたため、トランザクション情報が見つからない場合 public void setTransactionManagerBeanName(@Nullable StringSE transactionManagerBeanName)
PlatformTransactionManager
または ReactiveTransactionManager
のいずれかをポイントして、リアクティブトランザクション管理を行うことができます。@Nullable protected final StringSE getTransactionManagerBeanName()
public void setTransactionManager(@Nullable TransactionManager transactionManager)
PlatformTransactionManager
または ReactiveTransactionManager
のいずれかで、リアクティブトランザクション管理に使用できます。デフォルトのトランザクションマネージャーは、特定のトランザクションに対して修飾子が宣言されていない場合、またはデフォルトのトランザクションマネージャー Bean の明示的な名前が指定されていない場合に使用されます。
@Nullable public TransactionManager getTransactionManager()
null
を返します。これは、従来の PlatformTransactionManager
または ReactiveTransactionManager
のいずれかで、リアクティブトランザクション管理に使用できます。public void setTransactionAttributes(PropertiesSE transactionAttributes)
メモ: メソッド名は、インターフェースで定義されているか、クラス自体で定義されているかに関係なく、常にターゲットクラスに適用されます。
内部的には、NameMatchTransactionAttributeSource は指定されたプロパティから作成されます。
public void setTransactionAttributeSources(TransactionAttributeSource... transactionAttributeSources)
public void setTransactionAttributeSource(@Nullable TransactionAttributeSource transactionAttributeSource)
@Nullable public TransactionAttributeSource getTransactionAttributeSource()
public void setBeanFactory(@Nullable BeanFactory beanFactory)
BeanFactoryAware
の setBeanFactory
beanFactory
- 所有 BeanFactory(非 null
)。Bean は、ファクトリのメソッドをすぐに呼び出すことができます。BeanInitializationException
@Nullable protected final BeanFactory getBeanFactory()
public void afterPropertiesSet()
InitializingBean
の afterPropertiesSet
@Nullable protected ObjectSE invokeWithinTransaction(MethodSE method, @Nullable ClassSE<?> targetClass, TransactionAspectSupport.InvocationCallback invocation) throws ThrowableSE
CallbackPreferringPlatformTransactionManager
および通常の PlatformTransactionManager
実装を処理できます。method
- 呼び出されるメソッド targetClass
- メソッドを呼び出すターゲットクラス invocation
- ターゲット呼び出しを続行するために使用するコールバック ThrowableSE
- ターゲット呼び出しから伝播されます protected void clearTransactionManagerCache()
@Nullable protected TransactionManager determineTransactionManager(@Nullable TransactionAttribute txAttr)
@Nullable protected StringSE methodIdentification(MethodSE method, @Nullable ClassSE<?> targetClass)
デフォルトの実装は null
を返し、代わりに DefaultTransactionAttribute.getDescriptor()
を使用することを示し、最終的に ClassUtils.getQualifiedMethodName(Method, Class)
になります。
method
- 興味のある方法 targetClass
- メソッドが呼び出されているクラス ClassUtils.getQualifiedMethodName(java.lang.reflect.Method)
protected TransactionAspectSupport.TransactionInfo createTransactionIfNecessary(@Nullable PlatformTransactionManager tm, @Nullable TransactionAttribute txAttr, StringSE joinpointIdentification)
呼び出し元が TransactionAttributeSource を介してカスタム TransactionAttribute ルックアップを実行できるようにします。
txAttr
- TransactionAttribute (null
の場合があります)joinpointIdentification
- 完全修飾メソッド名 (監視とロギングの目的で使用)hasTransaction()
メソッドを使用して、トランザクションが作成されたかどうかを確認できます。getTransactionAttributeSource()
protected TransactionAspectSupport.TransactionInfo prepareTransactionInfo(@Nullable PlatformTransactionManager tm, @Nullable TransactionAttribute txAttr, StringSE joinpointIdentification, @Nullable TransactionStatus status)
txAttr
- TransactionAttribute (null
の場合があります)joinpointIdentification
- 完全修飾メソッド名 (監視とロギングの目的で使用)status
- 現在のトランザクションの TransactionStatusprotected void commitTransactionAfterReturning(@Nullable TransactionAspectSupport.TransactionInfo txInfo)
txInfo
- 現在のトランザクションに関する情報 protected void completeTransactionAfterThrowing(@Nullable TransactionAspectSupport.TransactionInfo txInfo, ThrowableSE ex)
txInfo
- 現在のトランザクションに関する情報 ex
- 投げられる protected void cleanupTransactionInfo(@Nullable TransactionAspectSupport.TransactionInfo txInfo)
すべての場合にこれを呼び出します: 例外または通常の復帰 !
txInfo
- 現在のトランザクションに関する情報 (null
の場合があります)