[Seasar-user:5482] S2JDBCのバッチ更新処理について

藤本 正人 [E-MAIL ADDRESS DELETED]
2006年 12月 14日 (木) 20:04:53 JST


藤本と申します。

S2JDBCのバッチ更新を使用して複数行のレコードをinsertしています。
diconファイルにBasicBatchHandlerを1つだけ定義した状態だと正常に動作する
のですが、複数のバッチ更新処理を定義すると
TooManyRegistrationRuntimeExceptionが発生してしまいます。
複数のバッチ更新処理を定義する方法がありましたら、教えてください。

開発環境はSeasar2.4.6です。

----------------------------------------
テストプログラム
----------------------------------------
package sample;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.seasar.extension.jdbc.BatchHandler;
import org.seasar.framework.container.factory.SingletonS2ContainerFactory;

public class Test {

    private static Log _log = LogFactory.getLog(Test.class);

    private BatchHandler _insertHandler;

    public void setInsertHandler(BatchHandler insertHandler) {
        _insertHandler = insertHandler;
    }

    public void test() {
        // 10レコード追加
        List list = new ArrayList();
        for (int i = 0; i < 10; ++i) {
            Object obj = new Object[]{new Integer(i), new Integer(i + 1)};
            list.add(obj);
        }
        _insertHandler.execute(list);
    }

    public static void main(String[] args) {
        SingletonS2ContainerFactory.init();
        Test test = (Test)SingletonS2ContainerFactory.getContainer().getComponent("test");
        test.test();
    }
}

----------------------------------------
app.dicon
----------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN" 
    "http://www.seasar.org/dtd/components24.dtd">
<components>
  <include path="sample/query.dicon"/>
  <component name="test" class="sample.Test"/>
</components>

----------------------------------------
query.dicon
----------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.3//EN"
    "http://www.seasar.org/dtd/components23.dtd">
<components>
  <include path="j2ee.dicon"/>

  <component name="insertBumonHandler"
    class="org.seasar.extension.jdbc.impl.BasicBatchHandler">
    <property name="batchSize">1000</property>
    <property name="sql"><![CDATA["
    INSERT INTO TEST_BUMON
    ( BUMON_CODE
    , DAILY_KYAKUSU
    )
    VALUES
    ( ?
    , ?
    ) 
    "]]></property>
  </component>

  <!-- 以下を追加するとTooManyRegistrationRuntimeExceptionが発生 -->
  <component name="insertBumonHandler2"
    class="org.seasar.extension.jdbc.impl.BasicBatchHandler">
    <property name="batchSize">1000</property>
    <property name="sql"><![CDATA["
    INSERT INTO TEST_BUMON
    ( BUMON_CODE
    , DAILY_KYAKUSU
    )
    VALUES
    ( ?
    , ?
    ) 
    "]]></property>
  </component>
</components>

----------------------------------------
例外
----------------------------------------
Exception in thread "main" org.seasar.framework.beans.IllegalPropertyRuntimeException: [ESSR0059]クラス(sample.Test)のプロパティ(insertHandler)の設定に失敗しました。理由はorg.seasar.framework.container.TooManyRegistrationRuntimeException: [ESSR0045]interface org.seasar.extension.jdbc.BatchHandlerに複数のコンポーネント(org.seasar.extension.jdbc.impl.BasicBatchHandler, org.seasar.extension.jdbc.impl.BasicBatchHandler)が登録されています
    at org.seasar.framework.container.assembler.AbstractBindingTypeDef.getValue(AbstractBindingTypeDef.java:218)
    at org.seasar.framework.container.assembler.AbstractBindingTypeDef.bindAuto(AbstractBindingTypeDef.java:180)
    at org.seasar.framework.container.assembler.BindingTypeShouldDef.doBind(BindingTypeShouldDef.java:53)
    at org.seasar.framework.container.assembler.AbstractBindingTypeDef.bind(AbstractBindingTypeDef.java:73)
    at org.seasar.framework.container.assembler.AutoPropertyAssembler.assemble(AutoPropertyAssembler.java:65)
    at org.seasar.framework.container.deployer.SingletonComponentDeployer.assemble(SingletonComponentDeployer.java:63)
    at org.seasar.framework.container.deployer.SingletonComponentDeployer.deploy(SingletonComponentDeployer.java:43)
    at org.seasar.framework.container.deployer.SingletonComponentDeployer.init(SingletonComponentDeployer.java:71)
    at org.seasar.framework.container.impl.ComponentDefImpl.init(ComponentDefImpl.java:299)
    at org.seasar.framework.container.impl.S2ContainerImpl.init(S2ContainerImpl.java:492)
    at org.seasar.framework.container.factory.SingletonS2ContainerFactory.init(SingletonS2ContainerFactory.java:81)
    at sample.Test.main(Test.java:110)
Caused by: org.seasar.framework.container.TooManyRegistrationRuntimeException: [ESSR0045]interface org.seasar.extension.jdbc.BatchHandlerに複数のコンポーネント(org.seasar.extension.jdbc.impl.BasicBatchHandler, org.seasar.extension.jdbc.impl.BasicBatchHandler)が登録されています
    at org.seasar.framework.container.impl.TooManyRegistrationComponentDefImpl.getComponent(TooManyRegistrationComponentDefImpl.java:45)
    at org.seasar.framework.container.impl.S2ContainerImpl.getComponent(S2ContainerImpl.java:117)
    at org.seasar.framework.container.assembler.AbstractBindingTypeDef.getValue(AbstractBindingTypeDef.java:216)
    ... 11 more

---
Masato FUJIMOTO



Seasar-user メーリングリストの案内