クラス 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 voidTransactionInfo ThreadLocal をリセットします。protected voidトランザクションマネージャーのキャッシュをクリアします。protected void呼び出しが正常に完了した後で実行されますが、例外が処理された後ではありません。protected voidスロー可能オブジェクトを処理し、トランザクションを完了します。protected TransactionAspectSupport.TransactionInfocreateTransactionIfNecessary(PlatformTransactionManager tm, TransactionAttribute txAttr, StringSE joinpointIdentification) 必要に応じて、指定された TransactionAttribute に基づいてトランザクションを作成します。protected static TransactionAspectSupport.TransactionInfoサブクラスはこれを使用して、現在の TransactionInfo を返すことができます。static TransactionStatus現在のメソッド呼び出しのトランザクションステータスを返します。protected TransactionManager特定のトランザクションに使用する特定のトランザクションマネージャーを決定します。protected final BeanFactoryTransactionManagerBean の取得に使用する BeanFactory を返します。トランザクション属性ソースを返します。デフォルトのトランザクションマネージャー、または不明の場合はnullを返します。protected final StringSEデフォルトのトランザクションマネージャー Bean の名前を返します。protected ObjectSEinvokeWithinTransaction(MethodSE method, ClassSE<?> targetClass, TransactionAspectSupport.InvocationCallback invocation) アドバイスに基づくサブクラスの一般的なデリゲート。このクラスの他のいくつかのテンプレートメソッドに委譲します。protected StringSEmethodIdentification(MethodSE method, ClassSE<?> targetClass) ロギングで使用するためにこのメソッドの文字列表現を返す簡易メソッド。protected TransactionAspectSupport.TransactionInfoprepareTransactionInfo(PlatformTransactionManager tm, TransactionAttribute txAttr, StringSE joinpointIdentification, TransactionStatus status) 指定された属性およびステータスオブジェクトの TransactionInfo を準備します。voidsetBeanFactory(BeanFactory beanFactory) TransactionManagerBean の取得に使用する BeanFactory を設定します。voidsetTransactionAttributes(PropertiesSE transactionAttributes) メソッド名をキーとして、トランザクション属性記述子(TransactionAttributeEditor を介して解析)を値としてプロパティを設定します。voidsetTransactionAttributeSource(TransactionAttributeSource transactionAttributeSource) トランザクション属性の検索に使用されるトランザクション属性ソースを設定します。voidsetTransactionAttributeSources(TransactionAttributeSource... transactionAttributeSources) トランザクション属性の検索に使用される複数のトランザクション属性ソースを設定します。voidsetTransactionManager(TransactionManager transactionManager) トランザクションの駆動に使用するデフォルトのトランザクションマネージャーを指定します。voidsetTransactionManagerBeanName(StringSE transactionManagerBeanName) デフォルトのトランザクションマネージャー Bean の名前を指定します。
フィールドの詳細
logger
コンストラクターの詳細
TransactionAspectSupport
protected TransactionAspectSupport()
メソッドの詳細
currentTransactionInfo
@Nullable protected static 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
デフォルトのトランザクションマネージャー Bean の名前を返します。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
TransactionManagerBean の取得に使用する BeanFactory を設定します。- 次で指定:
- インターフェース
BeanFactoryAwareのsetBeanFactory - パラメーター:
beanFactory- 所有 BeanFactory(非null)。Bean は、ファクトリのメソッドをすぐに呼び出すことができます。- 関連事項:
getBeanFactory
TransactionManagerBean の取得に使用する BeanFactory を返します。afterPropertiesSet
public void afterPropertiesSet()必要なプロパティが設定されていることを確認します。- 次で指定:
- インターフェース
InitializingBeanのafterPropertiesSet
invokeWithinTransaction
@Nullable protected ObjectSE invokeWithinTransaction(MethodSE method, @Nullable ClassSE<?> targetClass, TransactionAspectSupport.InvocationCallback invocation) throws ThrowableSE アラウンドアドバイスベースのサブクラスの一般的なデリゲートで、このクラスの他のいくつかのテンプレートメソッドに委譲します。CallbackPreferringPlatformTransactionManagerだけでなく、通常のPlatformTransactionManager実装およびリアクティブな戻り値型のReactiveTransactionManager実装も処理できます。- パラメーター:
method- 呼び出されるメソッドtargetClass- メソッドを呼び出すターゲットクラスinvocation- ターゲット呼び出しを続行するために使用するコールバック- 戻り値:
- メソッドの戻り値(存在する場合)
- 例外:
ThrowableSE- ターゲット呼び出しから伝播されます
clearTransactionManagerCache
protected void clearTransactionManagerCache()トランザクションマネージャーのキャッシュをクリアします。determineTransactionManager
@Nullable protected TransactionManager determineTransactionManager(@Nullable TransactionAttribute txAttr) 特定のトランザクションに使用する特定のトランザクションマネージャーを決定します。methodIdentification
@Nullable protected 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の場合があります)