クラス TransactionAspectSupport
- 実装されているすべてのインターフェース:
Aware
、BeanFactoryAware
、InitializingBean
- 既知の直属サブクラス
TransactionInterceptor
TransactionInterceptor
や AspectJ アスペクトなどのトランザクションアスペクトの基本クラス。これにより、基になる Spring トランザクションインフラストラクチャを簡単に使用して、任意のアスペクトシステムのアスペクトを実装できます。
サブクラスは、このクラスのメソッドを正しい順序で呼び出すロールを果たします。
TransactionAttribute
でトランザクション名が指定されていない場合、公開される名前は fully-qualified class name + "." + method name
(デフォルト)です。
Strategy 設計パターンを使用します。PlatformTransactionManager
または ReactiveTransactionManager
実装は実際のトランザクション管理を実行し、TransactionAttributeSource
(たとえば、アノテーションベース) は特定のクラスまたはメソッドのトランザクション定義を決定するために使用されます。
TransactionManager
と TransactionAttributeSource
が直列化可能な場合、トランザクションアスペクトは直列化可能です。
- 導入:
- 1.1
- 作成者:
- Rod Johnson, Juergen Hoeller, St é phane Nicoll, Sam Brannen, Mark Paluch, Sebastien Deleuze, Enric Sala
- 関連事項:
ネストされたクラスのサマリー
ネストされたクラス修飾子と型クラス説明protected static interface
ターゲット呼び出しを続行するためのシンプルなコールバックインターフェース。protected static final class
トランザクション情報を保持するために使用される不透明なオブジェクト。フィールドのサマリー
フィールドコンストラクターの概要
コンストラクターメソッドのサマリー
修飾子と型メソッド説明void
必要なプロパティが設定されていることを確認します。protected void
TransactionInfo ThreadLocal をリセットします。protected void
トランザクションマネージャーのキャッシュをクリアします。protected void
呼び出しが正常に完了した後で実行されますが、例外が処理された後ではありません。protected void
completeTransactionAfterThrowing
(@Nullable TransactionAspectSupport.TransactionInfo txInfo, ThrowableSE ex) スロー可能オブジェクトを処理し、トランザクションを完了します。protected TransactionAspectSupport.TransactionInfo
createTransactionIfNecessary
(@Nullable PlatformTransactionManager tm, @Nullable TransactionAttribute txAttr, StringSE joinpointIdentification) 必要に応じて、指定された TransactionAttribute に基づいてトランザクションを作成します。protected static @Nullable TransactionAspectSupport.TransactionInfo
サブクラスはこれを使用して、現在の TransactionInfo を返すことができます。static TransactionStatus
現在のメソッド呼び出しのトランザクションステータスを返します。protected @Nullable TransactionManager
使用すべきではありません。protected @Nullable TransactionManager
determineTransactionManager
(@Nullable TransactionAttribute txAttr, @Nullable ClassSE<?> targetClass) 特定のトランザクションに使用する特定のトランザクションマネージャーを決定します。protected final @Nullable BeanFactory
TransactionManager
Bean の取得に使用する BeanFactory を返します。トランザクション属性ソースを返します。デフォルトのトランザクションマネージャー、または不明の場合はnull
を返します。デフォルトのトランザクションマネージャー Bean の名前を返します。invokeWithinTransaction
(MethodSE method, @Nullable ClassSE<?> targetClass, TransactionAspectSupport.InvocationCallback invocation) アドバイスに基づくサブクラスの一般的なデリゲート。このクラスの他のいくつかのテンプレートメソッドに委譲します。methodIdentification
(MethodSE method, @Nullable ClassSE<?> targetClass) ロギングで使用するためにこのメソッドの文字列表現を返す簡易メソッド。protected TransactionAspectSupport.TransactionInfo
prepareTransactionInfo
(@Nullable PlatformTransactionManager tm, @Nullable TransactionAttribute txAttr, StringSE joinpointIdentification, @Nullable TransactionStatus status) 指定された属性およびステータスオブジェクトの TransactionInfo を準備します。void
setBeanFactory
(@Nullable BeanFactory beanFactory) TransactionManager
Bean の取得に使用する BeanFactory を設定します。void
setTransactionAttributes
(PropertiesSE transactionAttributes) メソッド名をキーとして、トランザクション属性記述子 (TransactionAttributeEditor 経由で解析) を値としてプロパティを設定します。たとえば、key="myMethod"、value="PROPAGATION_REQUIRED,readOnly" です。void
setTransactionAttributeSource
(@Nullable TransactionAttributeSource transactionAttributeSource) トランザクション属性の検索に使用されるトランザクション属性ソースを設定します。void
setTransactionAttributeSources
(TransactionAttributeSource... transactionAttributeSources) トランザクション属性の検索に使用される複数のトランザクション属性ソースを設定します。void
setTransactionManager
(@Nullable TransactionManager transactionManager) トランザクションの駆動に使用するデフォルトのトランザクションマネージャーを指定します。void
setTransactionManagerBeanName
(@Nullable StringSE transactionManagerBeanName) デフォルトのトランザクションマネージャー Bean の名前を指定します。
フィールドの詳細
logger
protected final org.apache.commons.logging.Log logger
コンストラクターの詳細
TransactionAspectSupport
protected TransactionAspectSupport()
メソッドの詳細
currentTransactionInfo
protected static @Nullable TransactionAspectSupport.TransactionInfo currentTransactionInfo() throws NoTransactionExceptionサブクラスはこれを使用して、現在の TransactionInfo を返すことができます。このメカニズムを使用して現在の TransactionInfo に到達する必要があるのは、1 つのメソッドですべての操作を処理できないサブクラス(たとえば、前と後の個別のアドバイスを含む AspectJ アスペクト)だけです。AOP Alliance MethodInterceptor などのアラウンドアドバイスは、アスペクトメソッド全体で TransactionInfo への参照を保持できます。トランザクションが作成されていなくても、TransactionInfo が返されます。これを照会するには、
TransactionInfo.hasTransaction()
メソッドを使用できます。特定のトランザクション特性について調べるには、TransactionSynchronizationManager の
isSynchronizationActive()
および / またはisActualTransactionActive()
メソッドの使用を検討してください。- 戻り値:
- このスレッドにバインドされた TransactionInfo。存在しない場合は
null
- 例外:
NoTransactionException
- 関連事項:
currentTransactionStatus
現在のメソッド呼び出しのトランザクションステータスを返します。主に、現在のトランザクションをロールバックのみに設定し、アプリケーション例外をスローしないコードを対象としています。これにより、アスペクトによって管理されるように、ローカルに宣言されたトランザクション境界が、その宣言された名前と特性とともに公開されます。実行時、ローカル境界は外部トランザクションに参加する可能性があります。そのような外部トランザクション (実際のリソーストランザクション) からのトランザクションメタデータが必要な場合は、代わりに
TransactionSynchronizationManager
の使用を検討してください。- 例外:
NoTransactionException
- メソッドが AOP 呼び出しコンテキストの外で呼び出されたため、トランザクション情報が見つからない場合- 関連事項:
setTransactionManagerBeanName
デフォルトのトランザクションマネージャー Bean の名前を指定します。これは、従来の
PlatformTransactionManager
またはReactiveTransactionManager
のいずれかをポイントして、リアクティブトランザクション管理を行うことができます。getTransactionManagerBeanName
setTransactionManager
トランザクションの駆動に使用するデフォルトのトランザクションマネージャーを指定します。これは、従来の
PlatformTransactionManager
またはReactiveTransactionManager
のいずれかで、リアクティブトランザクション管理に使用できます。デフォルトのトランザクションマネージャーは、特定のトランザクションに対して修飾子が宣言されていない場合、またはデフォルトのトランザクションマネージャー Bean の明示的な名前が指定されていない場合に使用されます。
- 関連事項:
getTransactionManager
デフォルトのトランザクションマネージャー、または不明の場合はnull
を返します。これは、従来の
PlatformTransactionManager
またはReactiveTransactionManager
のいずれかで、リアクティブトランザクション管理に使用できます。setTransactionAttributes
メソッド名をキーとして、トランザクション属性記述子 (TransactionAttributeEditor 経由で解析) を値としてプロパティを設定します。たとえば、key="myMethod"、value="PROPAGATION_REQUIRED,readOnly" です。メモ: メソッド名は、インターフェースで定義されているか、クラス自体で定義されているかに関係なく、常にターゲットクラスに適用されます。
内部的には、NameMatchTransactionAttributeSource は指定されたプロパティから作成されます。
- 関連事項:
setTransactionAttributeSources
public void setTransactionAttributeSources(TransactionAttributeSource... transactionAttributeSources) トランザクション属性の検索に使用される複数のトランザクション属性ソースを設定します。指定されたソースの CompositeTransactionAttributeSource を構築します。- 関連事項:
setTransactionAttributeSource
public void setTransactionAttributeSource(@Nullable TransactionAttributeSource transactionAttributeSource) トランザクション属性の検索に使用されるトランザクション属性ソースを設定します。String プロパティ値を指定すると、PropertyEditor はその値から MethodMapTransactionAttributeSource を作成します。- 関連事項:
getTransactionAttributeSource
トランザクション属性ソースを返します。setBeanFactory
TransactionManager
Bean の取得に使用する BeanFactory を設定します。- 次で指定:
- インターフェース
BeanFactoryAware
のsetBeanFactory
- パラメーター:
beanFactory
- 所有 BeanFactory(非null
)。Bean は、ファクトリのメソッドをすぐに呼び出すことができます。- 関連事項:
getBeanFactory
TransactionManager
Bean の取得に使用する BeanFactory を返します。afterPropertiesSet
public void afterPropertiesSet()必要なプロパティが設定されていることを確認します。- 次で指定:
- インターフェース
InitializingBean
のafterPropertiesSet
invokeWithinTransaction
protected @Nullable ObjectSE invokeWithinTransaction(MethodSE method, @Nullable ClassSE<?> targetClass, TransactionAspectSupport.InvocationCallback invocation) throws ThrowableSE アラウンドアドバイスベースのサブクラスの一般的なデリゲートで、このクラスの他のいくつかのテンプレートメソッドに委譲します。CallbackPreferringPlatformTransactionManager
だけでなく、通常のPlatformTransactionManager
実装およびリアクティブな戻り値型のReactiveTransactionManager
実装も処理できます。- パラメーター:
method
- 呼び出されるメソッドtargetClass
- メソッドを呼び出すターゲットクラスinvocation
- ターゲット呼び出しを続行するために使用するコールバック- 戻り値:
- メソッドの戻り値(存在する場合)
- 例外:
ThrowableSE
- ターゲット呼び出しから伝播されます
clearTransactionManagerCache
protected void clearTransactionManagerCache()トランザクションマネージャーのキャッシュをクリアします。determineTransactionManager
protected @Nullable TransactionManager determineTransactionManager(@Nullable TransactionAttribute txAttr, @Nullable ClassSE<?> targetClass) 特定のトランザクションに使用する特定のトランザクションマネージャーを決定します。- パラメーター:
txAttr
- 現在のトランザクション属性targetClass
- 属性が宣言されているターゲットクラス- 導入:
- 6.2
determineTransactionManager
@DeprecatedSE(since="6.2") protected @Nullable TransactionManager determineTransactionManager(@Nullable TransactionAttribute txAttr) 使用すべきではありません。特定のトランザクションに使用する特定のトランザクションマネージャーを決定します。methodIdentification
protected @Nullable StringSE methodIdentification(MethodSE method, @Nullable ClassSE<?> targetClass) ロギングで使用するためにこのメソッドの文字列表現を返す簡易メソッド。特定のメソッドに異なる識別子を提供するために、サブクラスでオーバーライドできます。デフォルトの実装は
null
を返し、代わりにDefaultTransactionAttribute.getDescriptor()
を使用することを示し、最終的にClassUtils.getQualifiedMethodName(Method, Class)
になります。- パラメーター:
method
- 興味のある方法targetClass
- メソッドが呼び出されているクラス- 戻り値:
- このメソッドを識別する String 表現
- 関連事項:
createTransactionIfNecessary
protected TransactionAspectSupport.TransactionInfo createTransactionIfNecessary(@Nullable PlatformTransactionManager tm, @Nullable TransactionAttribute txAttr, StringSE joinpointIdentification) 必要に応じて、指定された TransactionAttribute に基づいてトランザクションを作成します。呼び出し元が TransactionAttributeSource を介してカスタム TransactionAttribute ルックアップを実行できるようにします。
- パラメーター:
txAttr
- TransactionAttribute (null
の場合があります)joinpointIdentification
- 完全修飾メソッド名 (監視とロギングの目的で使用)- 戻り値:
- TransactionInfo オブジェクト、トランザクションが作成されたかどうか。TransactionInfo の
hasTransaction()
メソッドを使用して、トランザクションが作成されたかどうかを確認できます。 - 関連事項:
prepareTransactionInfo
protected TransactionAspectSupport.TransactionInfo prepareTransactionInfo(@Nullable PlatformTransactionManager tm, @Nullable TransactionAttribute txAttr, StringSE joinpointIdentification, @Nullable TransactionStatus status) 指定された属性およびステータスオブジェクトの TransactionInfo を準備します。- パラメーター:
txAttr
- TransactionAttribute (null
の場合があります)joinpointIdentification
- 完全修飾メソッド名 (監視とロギングの目的で使用)status
- 現在のトランザクションの TransactionStatus- 戻り値:
- 準備された TransactionInfo オブジェクト
commitTransactionAfterReturning
protected void commitTransactionAfterReturning(@Nullable TransactionAspectSupport.TransactionInfo txInfo) 呼び出しが正常に完了した後で実行されますが、例外が処理された後は実行されません。トランザクションを作成しなかった場合は何もしません。- パラメーター:
txInfo
- 現在のトランザクションに関する情報
completeTransactionAfterThrowing
protected void completeTransactionAfterThrowing(@Nullable TransactionAspectSupport.TransactionInfo txInfo, ThrowableSE ex) スロー可能なオブジェクトを処理して、トランザクションを完了します。構成によっては、コミットまたはロールバックする場合があります。- パラメーター:
txInfo
- 現在のトランザクションに関する情報ex
- 投げられる
cleanupTransactionInfo
TransactionInfo ThreadLocal をリセットします。すべての場合にこれを呼び出します: 例外または通常の復帰 !
- パラメーター:
txInfo
- 現在のトランザクションに関する情報 (null
の場合があります)
determineTransactionManager(TransactionAttribute, Class)
を推奨