クラス TransactionAspectSupport

java.lang.ObjectSE
org.springframework.transaction.interceptor.TransactionAspectSupport
実装されたすべてのインターフェース:
AwareBeanFactoryAwareInitializingBean
既知の直属サブクラス
TransactionInterceptor

public abstract class TransactionAspectSupport extends ObjectSE implements BeanFactoryAware, InitializingBean
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
関連事項:
  • フィールドの詳細

    • logger

      protected final Log 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

      public static TransactionStatus currentTransactionStatus() throws NoTransactionException
      現在のメソッド呼び出しのトランザクションステータスを返します。主に、現在のトランザクションをロールバックのみに設定し、アプリケーション例外をスローしないコードを対象としています。

      これにより、アスペクトによって管理されるように、ローカルに宣言されたトランザクション境界が、その宣言された名前と特性とともに公開されます。実行時、ローカル境界は外部トランザクションに参加する可能性があります。そのような外部トランザクション (実際のリソーストランザクション) からのトランザクションメタデータが必要な場合は、代わりに TransactionSynchronizationManager の使用を検討してください。

      例外:
      NoTransactionException - メソッドが AOP 呼び出しコンテキストの外で呼び出されたため、トランザクション情報が見つからない場合
      関連事項:
    • setTransactionManagerBeanName

      public void setTransactionManagerBeanName(@Nullable StringSE transactionManagerBeanName)
      デフォルトのトランザクションマネージャー Bean の名前を指定します。

      これは、従来の PlatformTransactionManager または ReactiveTransactionManager のいずれかをポイントして、リアクティブトランザクション管理を行うことができます。

    • getTransactionManagerBeanName

      @Nullable protected final StringSE getTransactionManagerBeanName()
      デフォルトのトランザクションマネージャー Bean の名前を返します。
    • setTransactionManager

      public void setTransactionManager(@Nullable TransactionManager transactionManager)
      トランザクションの駆動に使用するデフォルトのトランザクションマネージャーを指定します

      これは、従来の PlatformTransactionManager または ReactiveTransactionManager のいずれかで、リアクティブトランザクション管理に使用できます。

      デフォルトのトランザクションマネージャーは、特定のトランザクションに対して修飾子が宣言されていない場合、またはデフォルトのトランザクションマネージャー Bean の明示的な名前が指定されていない場合に使用されます。

      関連事項:
    • getTransactionManager

      @Nullable public TransactionManager getTransactionManager()
      デフォルトのトランザクションマネージャー、または不明の場合は null を返します。

      これは、従来の PlatformTransactionManager または ReactiveTransactionManager のいずれかで、リアクティブトランザクション管理に使用できます。

    • setTransactionAttributes

      public void setTransactionAttributes(PropertiesSE transactionAttributes)
      メソッド名をキーとして、トランザクション属性記述子(TransactionAttributeEditor を介して解析)を値としてプロパティを設定します。キー = "myMethod"、値 = "PROPAGATION_REQUIRED、readOnly"。

      メモ: メソッド名は、インターフェースで定義されているか、クラス自体で定義されているかに関係なく、常にターゲットクラスに適用されます。

      内部的には、NameMatchTransactionAttributeSource は指定されたプロパティから作成されます。

      関連事項:
    • setTransactionAttributeSources

      public void setTransactionAttributeSources(TransactionAttributeSource... transactionAttributeSources)
      トランザクション属性の検索に使用される複数のトランザクション属性ソースを設定します。指定されたソースの CompositeTransactionAttributeSource を構築します。
      関連事項:
    • setTransactionAttributeSource

      public void setTransactionAttributeSource(@Nullable TransactionAttributeSource transactionAttributeSource)
      トランザクション属性の検索に使用されるトランザクション属性ソースを設定します。String プロパティ値を指定すると、PropertyEditor はその値から MethodMapTransactionAttributeSource を作成します。
      関連事項:
    • getTransactionAttributeSource

      @Nullable public TransactionAttributeSource getTransactionAttributeSource()
      トランザクション属性ソースを返します。
    • setBeanFactory

      public void setBeanFactory(@Nullable BeanFactory beanFactory)
      TransactionManager Bean の取得に使用する BeanFactory を設定します。
      次で指定:
      インターフェース BeanFactoryAwaresetBeanFactory 
      パラメーター:
      beanFactory - 所有 BeanFactory(非 null)。Bean は、ファクトリのメソッドをすぐに呼び出すことができます。
      関連事項:
    • getBeanFactory

      @Nullable protected final BeanFactory getBeanFactory()
      TransactionManager Bean の取得に使用する BeanFactory を返します。
    • afterPropertiesSet

      public void afterPropertiesSet()
      必要なプロパティが設定されていることを確認します。
      次で指定:
      インターフェース InitializingBeanafterPropertiesSet 
    • 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

      指定された属性およびステータスオブジェクトの 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

      protected void cleanupTransactionInfo(@Nullable TransactionAspectSupport.TransactionInfo txInfo)
      TransactionInfo ThreadLocal をリセットします。

      すべての場合にこれを呼び出します: 例外または通常の復帰 !

      パラメーター:
      txInfo - 現在のトランザクションに関する情報 (null の場合があります)