[[S2i18n]]

* 元文 [#b923d83e]

**トランザクションの自動制御 [#k9290a7a]

S2Txの機能を使って、POJO(普通のJavaのクラス)に対して、Aspectでトランザクションの自動管理機能を組み込むことができます。EJBコンテナが提供するようなトランザクション管理機能をPOJOに対して透明に組み込むことができるのです。組む込むことのできるトランザクション属性は次のとおりです。
**トランザクション属性 [#j854a034]

コンポーネント名がAdviceの名前です
|属性|コンポーネント名|説明|
|Required|j2ee.requiredTx|トランザクションが開始されていなければ、自動的にトランザクションを開始します。&br;既にトランザクションが開始されていれば、そのトランザクションを引き継ぎます。|
|RequiresNew|j2ee.requiresNewTx|常に新しいトランザクションを開始させます。&br;既存のトランザクションが開始されているなら、既存のトランザクションを中断し、&br;自分自身のトランザクションの終了後、中断したトランザクションを復帰させます。|
|Mandatory|j2ee.mandatoryTx|トランザクションが既に開始されてなければエラーにします。|
**Example [#j5003a38]
Hoge.java

 package examples.tx;
 
 public interface Hoge {
 
    public void foo();
 }

HogeImpl.java

 package examples.tx;
 
 public class HogeImpl implements Hoge {
 
    public void foo() {
        System.out.println("foo");
    }
 }

HogeClient.dicon

 <components>
    <include path="j2ee.dicon"/>
    <component class="examples.tx.HogeImpl">
        <aspect>j2ee.requiredTx</aspect>
    </component>
 </components>

HogeClient.java

 package examples.tx;
 
 import org.seasar.framework.container.S2Container;
 import org.seasar.framework.container.factory.S2ContainerFactory;
 
 public class HogeClient {
 
    private static final String PATH =
        "examples/tx/HogeClient.dicon";
        
    public static void main(String[] args) {
        S2Container container = S2ContainerFactory.create(PATH);
        Hoge hoge = (Hoge) container.getComponent(Hoge.class);
        hoge.foo();
    }
 }

**実行結果 [#pf401c0d]

 DEBUG 2004-03-14 18:05:18,402 [main] Transaction.begin()
 foo
 DEBUG 2004-03-14 18:05:18,432 [main] Transaction.commit()

j2ee.diconはS2としてあらかじめ用意(srcの直下)されています。Adviceのコンポーネント名をaspectタグのボディに指定するだけなので簡単です。 POJOに簡単にトランザクション管理機能が組み込めることがわかってもらえたと思います。 

* 英文 [#df1b8d9a]
**Transaction Management [#e9683c01]
S2Tx provides the automatic transaction management by using Aspect for POJOs. You can use the transaction management that the EJB container offers without adding the code to POJOs. Showing as follows is a transaction attribute offered with S2tx. 

**Transaction Attributes [#n2eb75ff]
The column of the component is a name of Advice. 
|attribute|component|description|
|Required|j2ee.requiredTx|If the method's caller is already part of a transaction, it does not create a new transaction, but continues in the same transaction as its caller. If the caller is not in a transaction, a new transaction is created.|
|RequiresNew|j2ee.requiresNewTx|A new transaction is created always, regardless of the transactional state of the caller. If the caller was operating in a transaction, its transaction is suspended until the method completes.|
|Mandatory|j2ee.mandatoryTx|The method will not even start unless its caller is in a transaction. It will throw a Exception instead.|

**Example [#m74c5aad]

Hoge.java

 package examples.tx;
 
 public interface Hoge {
 
    public void foo();
 }

HogeImpl.java

 package examples.tx;
 
 public class HogeImpl implements Hoge {
 
    public void foo() {
        System.out.println("foo");
    }
 }

HogeClient.dicon

 <components>
    <include path="j2ee.dicon"/>
    <component class="examples.tx.HogeImpl">
        <aspect>j2ee.requiredTx</aspect>
    </component>
 </components>

HogeClient.java

 package examples.tx;
 
 import org.seasar.framework.container.S2Container;
 import org.seasar.framework.container.factory.S2ContainerFactory;
 
 public class HogeClient {
 
    private static final String PATH =
        "examples/tx/HogeClient.dicon";
        
    public static void main(String[] args) {
        S2Container container = S2ContainerFactory.create(PATH);
        Hoge hoge = (Hoge) container.getComponent(Hoge.class);
        hoge.foo();
    }
 }

**Execution result [#n22e696c]

 DEBUG 2004-03-14 18:05:18,402 [main] Transaction.begin()
 foo
 DEBUG 2004-03-14 18:05:18,432 [main] Transaction.commit()

J2ee.dicon file is in S2(under src directory). You only specify the component name of Advice for the body of the aspect tag. Thus, it is very easy to manage the transaction with POJO by using S2tx.
-12 -- [[abcd]] &new{2005-03-08 18:10:34 (火)};
-acbd -- [[12]] &new{2005-03-08 18:12:34 (火)};

#comment

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS