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

Kazuya Sugimoto [E-MAIL ADDRESS DELETED]
2008年 1月 11日 (金) 08:13:33 JST


杉本です。

AOPについては実現する実装上、制限があるのですが、
AOPの制限については下記のURLを参照して下さい。
http://s2container.net.seasar.org/ja/aop-summary.html#DefaultAOP


08/01/11 に koyakさんは書きました:
> 中村様、堀口様
>
> 小谷です。
>
> ご協力ありがとうございます。
> 堀口さんがおっしゃる通り、GetComponentの第一引数に
> GetType(Itx)を渡すことでAspectがかかるかと思います。
>
> こちらの環境でインターフェースを指定した場合と
> 実装クラスを指定した場合で比較したところ
> ・インターフェース→Aspectがかかる
> ・実装クラス→Aspectがかからない
>
> となり、再現することが確認できました。
>
> 堀口さん、ありがとうございました。
>
> -----------------------------------------
> koyak
> [E-MAIL ADDRESS DELETED]
> ------------------------------------------
>
> 08/01/10 に Yuji Horiguchi<[E-MAIL ADDRESS DELETED]> さんは書きました:
> > こんにちは、以前要望を取り入れていただいた堀口です。
> >
> > その節はありがとうございました。おかげで順調に作業を進めることが出来ました。
> >
> > さて、中村さんのソースで気になった点があったので横から失礼かと思いました
> > がメールさせていただきます。
> >
> > Sub Main()中の↓の部分
> > >         'TxClientをDI
> > >         Dim client As Itx =
> > > DirectCast(container.GetComponent(GetType(TxClient), "TxClient"),
> > TxClient)
> >
> > このGetComponentに渡している第1引数がクラスを指定しているからではないで
> > しょうか。
> > 以前自分が質問をしたときにクラスだとAspectが適用されないという回答をいた
> > だいたかと思います。
> > ですので、GetComponentの第1引数にインターフェースを指定するとどうでしょ
> > うか。
> > DirectCast(container.GetComponent(GetType(Itx), "TxClient"), Itx)
> >
> > 全然見当違いのことをいっていたらすみません。スルーしてください。
> >
> > Mitsuo Nakamura さんは書きました:
> > > はじめまして。いつもお世話になっております。
> > > 中村と申します。
> > >
> > > 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
> >
> > --
> > Yuji Horiguchi
> > [E-MAIL ADDRESS DELETED]
> > _______________________________________________
> > 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
>


-- 
Kazuya Sugimoto
Microsoft MVP Visual Developer - Solutions Architect
http://d.hatena.ne.jp/sugimotokazuya/


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