[seasar-dotnet:735] Re: メソッド単位のトランザクション指定について

Mitsuo Nakamura [E-MAIL ADDRESS DELETED]
2008年 1月 10日 (木) 13:50:26 JST


小谷様

お返事ありがとうございます。中村です。

以下2点についてですが、いずれの場合も、同じ結果となります。
TxClient.Execメソッドはaspect指定を無視しているような動きです。

逆に、IsampleDaoコンポーネントでRequiredTxを以下の様に指定します。

 <aspect pointcut="Insert,Delete">RequiredTx</aspect>

こうした場合、IsampleDao内のInsert、Deleteメソッドでそれぞれトラン
ザクション制御が行えています。
(トランザクションの開始・終了ログは出力されます。)

以上です。
よろしくお願いいたします。

>
> 中村様
>
> 小谷です。
>
> ログに「トランザクションを開始しました」「〜コミットしました。」といった
> メッセージが出力されていないため、インターセプターが適用されて
> いないと思うのですが、
> 自分が見る限りではdicon、ソース共に問題はないように思えます。
>
> pointcutが関係しているかどうかをまず切り分けさせていただきたいと思うので
> すが、
> Dao.diconの
> <aspect pointcut="Exec">RequiredTx</aspect>
> としている部分を以下のように変更して実行した場合は
> どうなるでしょうか?
> ・<aspect>RequiredTx</aspect>    (ポイントカットを指定しない)
> ・<aspect pointcut=".*">RequiredTx</aspect>
>
> --------------------------------------------
> koyak
> [E-MAIL ADDRESS DELETED]
> --------------------------------------------
>
> 08/01/10 に Mitsuo Nakamura<[E-MAIL ADDRESS DELETED]> さんは書きました:
> > はじめまして。いつもお世話になっております。
> > 中村と申します。
> >
> > S2DAO.NET+S2AOP.NETを利用しようとしております。
> > DBのトランザクション管理を、S2Container.NETのAOPで行おうと試しておりま
> > すが、想定する動きとなりません。今やりたいことは、メソッド単位(ここで
は、
> > TxClient.Execメソッド)にトランザクションをかける事です。
> >
> > 現状では、以下のような結果となってしまい、メソッド全体にトランザクション
>> > かけられていません。(コネクション切断と同時にコミットされています。)正し
>> > aspectできていない事が原因のようですが、理由がわかりませんでした。
> >
> > 【実行結果】
> > DEBUG [10:44:12] 論理的なコネクションを取得しました
> > DEBUG [10:44:12] 論理的なコネクションを閉じました
> > DEBUG [10:44:12] 論理的なコネクションを取得しました
> > DEBUG [10:44:12] INSERT INTO Sample (ID, DATA) VALUES ('1', 'ああああ')
> > DEBUG [10:44:12] 論理的なコネクションを閉じました
> >
> > DEBUG [10:44:17] 論理的なコネクションを取得しました
> > DEBUG [10:44:17] DELETE FROM Sample WHERE ID = '1'
> > DEBUG [10:44:17] 論理的なコネクションを閉じました
> > INFO  [10:44:17] 完了です
> >
> > 以下にソースを添付いたしますので、お手数をおかけいたしますが、ご指摘のほ
> ど、
> > よろしくお願いいたします。
> >
> > なお、環境は、以下の通りです。
> >
> > OS         :Windows Vista Business(32bit)
> > 開発環境:VB .Net2005
> > 検証DB  :InterBase BDP
> >             SqlServer NativeClient
> > S2.NET   :1.3.5
> >
> > 以下、dicon・ソースファイルです。
> >
> --------------------------------------------------------------------------
> --
> > ---------------------
> > [Dao.dicon]
> >
> > <?xml version="1.0" encoding="utf-8" ?>
> > <!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container//EN"
> > "http://www.seasar.org/dtd/components.dtd">
> >
> > <components>
> >     <!-- Tx.dicon -->
> >     <include path="S2DaoSample/Ado.dicon" />
> >               <!-- S2Dao.NETのDaoInterceptorとそれに必要なコンポーネン
> ト -->
> >               <component
> > class="Seasar.Extension.ADO.Impl.BasicDataReaderFactory" />
> >               <component
> > class="Seasar.Extension.ADO.Impl.BasicCommandFactory" />
> >               <component
> > class="Seasar.Extension.ADO.Impl.DatabaseMetaDataImpl" />
> >               <component
> > class="Seasar.Dao.Impl.FieldAnnotationReaderFactory" />
> >               <component class="Seasar.Dao.Impl.DaoMetaDataFactoryImpl"
> />
> >               <component
> > class="Seasar.Extension.Component.Impl.ComponentInvoker" />
> >               <component name="TransactionStateHandler"
> > class="Seasar.Extension.Tx.Impl.TransactionStateHandler" />
> >               <component name="DaoInterceptor"
> > class="Seasar.Dao.Interceptors.S2DaoInterceptor" />
> >               <component name="RequiredTx"
> > class="Seasar.Extension.Tx.TransactionInterceptor">
> >                             <arg>
> >                                           <component
> > class="Seasar.Extension.Tx.Impl.RequiredTxHandler" />
> >                             </arg>
> >               </component>
> >
> >               <!-- サンプルDao-->
> >               <component name="IsampleDao"
> > class="S2DaoSample.Dao.IsampleDao">
> >                             <aspect>DaoInterceptor</aspect>
> >               </component>
> >
> >               <!-- TxClientクラス -->
> >               <component name="TxClient" class="S2DaoSample.TxClient">
> >                             <aspect pointcut="Exec">RequiredTx</aspect>
> >               </component>
> > </components>
> >
> >
> --------------------------------------------------------------------------
> --
> > ---------------------
> > [Program.vb]
> >
> > Imports System.IO
> > Imports System.Reflection
> > Imports log4net
> > Imports log4net.Config
> > Imports log4net.Util
> > Imports Seasar.Framework.Container
> > Imports Seasar.Framework.Container.Factory
> >
> > Module Program
> >     Sub Main()
> >
> >         'log4netの初期化
> >         InitApplication()
> >
> >         'アプリケーション構成ファイルに定義されたDiconファイルのパスを
> 取得
> >         Dim diconPath As String = SingletonS2ContainerFactory.ConfigPath
> >         Dim container As IS2Container =
> S2ContainerFactory.Create(diconPath)
> >
> >         'S2Containerを初期化
> >         container.Init()
> >
> >         'TxClientをDI
> >         Dim client As Itx =
> > DirectCast(container.GetComponent(GetType(TxClient), "TxClient"),
> TxClient)
> >         '実行
> >         client.Exec()
> >
> >     End Sub
> >
> >     '初期化を行なうメソッド
> >     Private Sub InitApplication()
> >         'アプリケーション構成ファイル(<アプリケーション名>.exe.config)の
> 取得
> >         Dim info As New
> > FileInfo(SystemInfo.AssemblyShortName(Assembly.GetExecutingAssembly()) +
> > ".exe.config")
> >         'ログ出力ライブラリ「log4net」の初期化
> >         XmlConfigurator.Configure(LogManager.GetRepository(), info)
> >     End Sub
> > End Module
> >
> >
> --------------------------------------------------------------------------
> --
> > ---------------------
> > [TxClient.vb]
> >
> > Imports System
> > Imports System.IO
> > Imports System.Reflection
> > Imports log4net.Util
> > Imports log4net
> > Imports log4net.Config
> > Imports Seasar.Framework.Container
> > Imports Seasar.Framework.Container.Factory
> > Imports S2DaoSample.Entity           'Entityクラスの格納場所
> > Imports S2DaoSample.Dao              'Daoクラスの格納場所
> >
> > Public Interface Itx
> >     Sub Exec()
> > End Interface
> >
> > Public Class TxClient : Implements Itx
> >     'ロガーを取得
> >     Private ReadOnly logger As log4net.ILog = _
> >
> >
> log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod
> ()
> > .DeclaringType)
> >
> >     Private spDao As IsampleDao
> >     Public WriteOnly Property IsampleDao() As IsampleDao
> >         Set(ByVal value As IsampleDao)
> >             spDao = value
> >         End Set
> >     End Property
> >
> >     Public Sub Exec() Implements Itx.Exec
> >
> >         Dim sample As New Sample
> >         sample.id = 1
> >         sample.data = "ああああ"
> >
> >         spDao.Insert(sample)
> >         spDao.Delete(sample)
> >
> >         '結果を表示して停止
> >         logger.Info("完了です")
> >         Console.ReadLine()
> >
> >     End Sub
> > End Class
> >
> >
> --------------------------------------------------------------------------
> --
> > ---------------------
> > [IsampleDao.vb]
> >
> > Imports System
> > Imports Seasar.Dao.Attrs 'S2Dao.NETの属性を使用
> > Imports S2DaoSample.Entity           'Entityクラスの格納場所
> >
> > Namespace Dao
> >     ' Bookテーブルにアクセスする為のDao
> >     '対応するEntityを指定
> >     <Bean(GetType(Sample))> _
> >     Public Interface IsampleDao
> >         '追加登録
> >         Sub Insert(ByVal sample As Sample)
> >         '削除
> >         Sub Delete(ByVal sample As Sample)
> >     End Interface
> > End Namespace
> >
> >
> --------------------------------------------------------------------------
> --
> > ---------------------
> >
> > 以上です。
> > よろしくお願いいたします。
> >
> > _______________________________________________
> > seasar-dotnet mailing list
> > [E-MAIL ADDRESS DELETED]
> > https://ml.seasar.org/mailman/listinfo/seasar-dotnet
> >
> _______________________________________________
> seasar-dotnet mailing list
> [E-MAIL ADDRESS DELETED]
> https://ml.seasar.org/mailman/listinfo/seasar-dotnet



seasar-dotnet メーリングリストの案内