[Seasar-user:15044] 複数DBへの接続

=?ISO-2022-JP?B?GyRCekk4NiEhNTFNOhsoQg==?= [E-MAIL ADDRESS DELETED]
2008年 7月 16日 (水) 15:23:46 JST


桑原です。お世話になります。

「SMART deployで複数データソースに対応するには?」
http://www.seasar.org/wiki/index.php?FAQ%2FS2DAO#w7da6e0e

を参考にjdbc.diconやdao.diconを設定したのですが、2つの内1つの
DBにしかアクセスしません。
dao-my.diconに記載する2つのDBのincludeの順番を変えると、もう
一方のDBにアクセスできます。どうやら、1番目に来るincludeのdiconに
定義されたDBのみアクセスできるようです。

データソースの切り替えの定義をソースに書く必要があるのか無いのか分かりま
せんので、ご教示下さい。


#############################dao-my.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 namespace="dao">
	<include path="daotims.dicon"/>
	<include path="daooldcas.dicon"/>

	<include path="j2ee.dicon"/>
</components>


#############################daooldcas.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 namespace="daooldcas">
	<include path="jdbcoldcas.dicon"/>
	<component class="org.seasar.dao.impl.AnnotationReaderFactoryImpl"/>
	<component class="org.seasar.dao.impl.DaoMetaDataFactoryImpl"/>
	<component
		name="interceptor"
		class="org.seasar.dao.pager.PagerS2DaoInterceptorWrapper">
		<arg>
			<component class="org.seasar.dao.interceptors.S2DaoInterceptor"/>
		</arg>
	</component>
	<component class="org.seasar.dao.impl.ValueTypeFactoryImpl"/>
	<component
		name="stringClobType"
		class="org.seasar.extension.jdbc.types.StringClobType"
	/>
	<component class="org.seasar.dao.impl.BeanMetaDataFactoryImpl"/>
	<component class="org.seasar.dao.impl.DaoNamingConventionImpl"/>
	<component class="org.seasar.dao.impl.NullBeanEnhancer"/>
	<component class="org.seasar.dao.impl.ResultSetHandlerFactoryImpl"/>
	<component class="org.seasar.dao.impl.DtoMetaDataFactoryImpl"/>
	<component class="org.seasar.dao.impl.PropertyTypeFactoryBuilderImpl"/>
	<component
class="org.seasar.dao.impl.RelationPropertyTypeFactoryBuilderImpl"/>
	<component class="org.seasar.dao.impl.DefaultTableNaming"/>
	<component class="org.seasar.dao.impl.DefaultColumnNaming"/>
	<component class="org.seasar.dao.impl.ProcedureMetaDataFactoryImpl"/>
</components>

#############################daotims.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 namespace="daotims">
	<include path="jdbctims.dicon"/>
	<component class="org.seasar.dao.impl.AnnotationReaderFactoryImpl"/>
	<component class="org.seasar.dao.impl.DaoMetaDataFactoryImpl"/>
	<component
		name="interceptor"
		class="org.seasar.dao.pager.PagerS2DaoInterceptorWrapper">
		<arg>
			<component class="org.seasar.dao.interceptors.S2DaoInterceptor"/>
		</arg>
	</component>
	<component class="org.seasar.dao.impl.ValueTypeFactoryImpl"/>
	<component
		name="stringClobType"
		class="org.seasar.extension.jdbc.types.StringClobType"
	/>
	<component class="org.seasar.dao.impl.BeanMetaDataFactoryImpl"/>
	<component class="org.seasar.dao.impl.DaoNamingConventionImpl"/>
	<component class="org.seasar.dao.impl.NullBeanEnhancer"/>
	<component class="org.seasar.dao.impl.ResultSetHandlerFactoryImpl"/>
	<component class="org.seasar.dao.impl.DtoMetaDataFactoryImpl"/>
	<component class="org.seasar.dao.impl.PropertyTypeFactoryBuilderImpl"/>
	<component
class="org.seasar.dao.impl.RelationPropertyTypeFactoryBuilderImpl"/>
	<component class="org.seasar.dao.impl.DefaultTableNaming"/>
	<component class="org.seasar.dao.impl.DefaultColumnNaming"/>
	<component class="org.seasar.dao.impl.ProcedureMetaDataFactoryImpl"/>
</components>


#############################jdbc.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="jdbcoldcas.dicon"/>
	<include path="jdbctims.dicon"/>
</components>



#############################jdbcoldcas.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 namespace="jdbcoldcas">
	<include path="jta.dicon"/>
	<include path="jdbc-extension.dicon"/>

	<component class="org.seasar.extension.jdbc.impl.BasicResultSetFactory"/>
	<component
class="org.seasar.extension.jdbc.impl.ConfigurableStatementFactory">
		<arg>
			<component class="org.seasar.extension.jdbc.impl.BasicStatementFactory"/>
		</arg>
		<property name="fetchSize">100</property>
		<!--
		<property name="maxRows">100</property>
		-->
	</component>
	<!-- for PostgreSQL -->
	
	<component name="xaDataSource"
		class="org.seasar.extension.dbcp.impl.XADataSourceImpl">
		<property name="driverClassName">
			"org.postgresql.Driver"
        </property>
        <property name="URL">
          "jdbc:postgresql://localhost:5432/oldcss"
        </property>
        <property name="user">"postgres"</property>
        <property name="password">"postgres"</property>
    </component>
	<component name="connectionPool"
		class="org.seasar.extension.dbcp.impl.ConnectionPoolImpl">
		<property name="timeout">600</property>
		<property name="maxPoolSize">10</property>
		<property name="allowLocalTx">true</property>
		<destroyMethod name="close"/>
	</component>

	<component name="dataSource"
		class="org.seasar.extension.dbcp.impl.DataSourceImpl"
	/>
</components>




#############################jdbctims.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 namespace="jdbctims">
	<include path="jta.dicon"/>
	<include path="jdbc-extension.dicon"/>

	<component class="org.seasar.extension.jdbc.impl.BasicResultSetFactory"/>
	<component
class="org.seasar.extension.jdbc.impl.ConfigurableStatementFactory">
		<arg>
			<component class="org.seasar.extension.jdbc.impl.BasicStatementFactory"/>
		</arg>
		<property name="fetchSize">100</property>
		<!--
		<property name="maxRows">100</property>
		-->
	</component>
	
	<!-- for PostgreSQL -->
	
	<component name="xaDataSource"
		class="org.seasar.extension.dbcp.impl.XADataSourceImpl">
		<property name="driverClassName">
			"org.postgresql.Driver"
        </property>
        <property name="URL">
          "jdbc:postgresql://localhost:5432/e3lp20"
        </property>
        <property name="user">"postgres"</property>
        <property name="password">"postgres"</property>
    </component>
    	<component name="connectionPool"
		class="org.seasar.extension.dbcp.impl.ConnectionPoolImpl">
		<property name="timeout">600</property>
		<property name="maxPoolSize">10</property>
		<property name="allowLocalTx">true</property>
		<destroyMethod name="close"/>
	</component>

	<component name="dataSource"
		class="org.seasar.extension.dbcp.impl.DataSourceImpl"
	/>
</components>



#############################custmizer.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="default-customizer.dicon"/>
  <component name="pageCustomizer"
class="org.seasar.framework.container.customizer.CustomizerChain">
    <initMethod name="addCustomizer">
      <arg>traceCustomizer</arg>
    </initMethod>
    <initMethod name="addCustomizer">
      <arg>
        <component
class="org.seasar.framework.container.customizer.AspectCustomizer">
          <initMethod name="addInterceptorName">
            <arg>"app_aop.appFacesExceptionThrowsInterceptor"</arg>
          </initMethod>
          <property name="pointcut">"do.*, initialize, prerender"</property>
        </component>
      </arg>
    </initMethod>
    <initMethod name="addCustomizer">
      <arg>
        <component
class="org.seasar.framework.container.customizer.AspectCustomizer">
          <initMethod name="addInterceptorName">
            <arg>"j2ee.requiredTx"</arg>
          </initMethod>
          <property name="pointcut">"do.*, initialize, prerender"</property>
        </component>
      </arg>
    </initMethod>
  </component>
  <component name="actionCustomizer"
class="org.seasar.framework.container.customizer.CustomizerChain">
    <initMethod name="addCustomizer">
      <arg>traceCustomizer</arg>
    </initMethod>
    <initMethod name="addCustomizer">
      <arg>
        <component
class="org.seasar.framework.container.customizer.AspectCustomizer">
          <initMethod name="addInterceptorName">
            <arg>"app_aop.actionSupportInterceptor"</arg>
          </initMethod>
          <property name="pointcut">"do.*, initialize, prerender"</property>
        </component>
      </arg>
    </initMethod>
  </component>
  <component name="serviceCustomizer"
class="org.seasar.framework.container.customizer.CustomizerChain">
    <initMethod name="addCustomizer">
      <arg>traceCustomizer</arg>
    </initMethod>
    <initMethod name="addCustomizer">
      <arg>requiredTxCustomizer</arg>
    </initMethod>
  </component>
  <component name="logicCustomizer"
class="org.seasar.framework.container.customizer.CustomizerChain">
    <initMethod name="addCustomizer">
      <arg>traceCustomizer</arg>
    </initMethod>
  </component>
  <component name="daoCustomizer"
class="org.seasar.framework.container.customizer.CustomizerChain">
    <initMethod name="addCustomizer">
      <arg>traceCustomizer</arg>
    </initMethod>
    <initMethod name="addCustomizer">
      <arg>s2DaoCustomizer</arg>
    </initMethod>
 	<initMethod name="addCustomizer">
		<arg>daotimsSupportAspectCustomizer</arg>
	</initMethod>
	<initMethod name="addCustomizer">
		<arg>daooldcasSupportAspectCustomizer</arg>
	</initMethod>
  </component>
  <component name="dxoCustomizer"
class="org.seasar.framework.container.customizer.CustomizerChain">
    <initMethod name="addCustomizer">
      <arg>traceCustomizer</arg>
    </initMethod>
    <initMethod name="addCustomizer">
      <arg>s2DxoCustomizer</arg>
    </initMethod>
  </component>
  <component name="helperCustomizer"
class="org.seasar.framework.container.customizer.CustomizerChain">
    <initMethod name="addCustomizer">
      <arg>traceCustomizer</arg>
    </initMethod>
  </component>
  <component name="daooldcasSupportAspectCustomizer"
class="org.seasar.framework.container.customizer.AspectCustomizer">
	<property name="interceptorName">"daooldcas.interceptor"</property>
	<initMethod name="addClassPattern">
		<arg>"ordersheet.dao.daooldcas"</arg>
		<arg>".*Dao"</arg>
	</initMethod>
  </component>
  <component name="daotimsSupportAspectCustomizer"
class="org.seasar.framework.container.customizer.AspectCustomizer">
	<property name="interceptorName">"daotims.interceptor"</property>
	<initMethod name="addClassPattern">
		<arg>"ordersheet.dao.daotims"</arg>
		<arg>".*Dao"</arg>
	</initMethod>	
  </component>

</components>


#############################s2container.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 condition="#ENV == 'ut'" path="warmdeploy.dicon"/>
    <include condition="#ENV == 'ct'" path="hotdeploy.dicon"/>
    <include condition="#ENV != 'ut' and #ENV != 'ct'"
path="cooldeploy.dicon"/>

    <component
class="org.seasar.framework.container.factory.SimplePathResolver">
  		<initMethod name="addRealPath">
    	<arg>"dao.dicon"</arg>
    	<arg>"dao-my.dicon"</arg><!-- 実際に使用する定義ファイル -->
  		</initMethod>
	</component>

</components>





###########################エラーメッセージ#############################
2008-07-16 15:05:35,187 [http-8080-1] DEBUG
org.seasar.framework.aop.interceptors.TraceInterceptor - BEGIN
ordersheet.dao.V_userDao#getUserByUsercd(el00001)
2008-07-16 15:05:35,265 [http-8080-1] DEBUG
org.seasar.extension.dbcp.impl.ConnectionPoolImpl - 物理的なコネクション
を取得しました
2008-07-16 15:05:35,265 [http-8080-1] DEBUG
org.seasar.extension.dbcp.impl.ConnectionPoolImpl - 論理的なコネクション
を取得しました。tx=[FormatId=4360, GlobalId=1216186452953/6, BranchId=]
2008-07-16 15:05:35,265 [http-8080-1] DEBUG
org.seasar.extension.dbcp.impl.ConnectionWrapperImpl - 論理的なコネク
ションを閉じました。tx=[FormatId=4360, GlobalId=1216186452953/6, BranchId=]
2008-07-16 15:05:35,265 [http-8080-1] DEBUG
org.seasar.extension.dbcp.impl.ConnectionPoolImpl - 論理的なコネクション
を取得しました。tx=[FormatId=4360, GlobalId=1216186452953/6, BranchId=]
2008-07-16 15:05:35,312 [http-8080-1] WARN
org.seasar.dao.impl.PropertyTypeFactoryImpl - テーブル(v_user)が見つかり
ません
2008-07-16 15:05:35,312 [http-8080-1] DEBUG
org.seasar.extension.dbcp.impl.ConnectionWrapperImpl - 論理的なコネク
ションを閉じました。tx=[FormatId=4360, GlobalId=1216186452953/6, BranchId=]
2008-07-16 15:05:35,312 [http-8080-1] DEBUG
org.seasar.extension.dbcp.impl.ConnectionPoolImpl - 論理的なコネクション
を取得しました。tx=[FormatId=4360, GlobalId=1216186452953/6, BranchId=]
2008-07-16 15:05:35,328 [http-8080-1] DEBUG
org.seasar.extension.jdbc.impl.BasicHandler - SELECT
user_cd,name_family,name_first,post,company_cd,company,organization_cd,organization,password
FROM v_user where login_ok = '1' and user_cd = 'el00001'
2008-07-16 15:05:35,328 [http-8080-1] DEBUG
org.seasar.extension.dbcp.impl.ConnectionWrapperImpl - 論理的なコネク
ションを閉じました。tx=[FormatId=4360, GlobalId=1216186452953/6, BranchId=]
2008-07-16 15:05:35,328 [http-8080-1] DEBUG
org.seasar.framework.aop.interceptors.TraceInterceptor - END
ordersheet.dao.V_userDao#getUserByUsercd(el00001)
Throwable:org.seasar.framework.exception.SQLRuntimeException:
[ESSR0072]SQLで例外(SQL=[SELECT
user_cd,name_family,name_first,post,company_cd,company,organization_cd,organization,password
FROM v_user where login_ok = '1' and user_cd = ?],
Message=[[ESSR0072]SQLで例外(SQL=[SELECT
user_cd,name_family,name_first,post,company_cd,company,organization_cd,organization,password
FROM v_user where login_ok = '1' and user_cd = ?], Message=[0],
ErrorCode=42P01, SQLState={3})が発生しました : [SQLで例外(Message=
[ERROR: relation "v_user" does not exist], ErrorCode=0, SQLState=42P01)
が発生しました。], [ERROR: relation "v_user" does not exist],
ErrorCode=0, SQLState=42P01)が発生しました
2008-07-16 15:05:35,359 [http-8080-1] DEBUG
org.seasar.extension.jta.TransactionImpl - トランザクションをロールバッ
クしました。tx=[FormatId=4360, GlobalId=1216186452953/6, BranchId=]
2008-07-16 15:05:35,359 [http-8080-1] DEBUG
org.seasar.framework.aop.interceptors.TraceInterceptor - END
ordersheet.web.NewentrustPage#doItakukanriseiSearch()
Throwable:org.seasar.framework.exception.SQLRuntimeException:
[ESSR0072]SQLで例外(SQL=[SELECT
user_cd,name_family,name_first,post,company_cd,company,organization_cd,organization,password
FROM v_user where login_ok = '1' and user_cd = ?],
Message=[[ESSR0072]SQLで例外(SQL=[SELECT
user_cd,name_family,name_first,post,company_cd,company,organization_cd,organization,password
FROM v_user where login_ok = '1' and user_cd = ?], Message=[0],
ErrorCode=42P01, SQLState={3})が発生しました : [SQLで例外(Message=
[ERROR: relation "v_user" does not exist], ErrorCode=0, SQLState=42P01)
が発生しました。], [ERROR: relation "v_user" does not exist],
ErrorCode=0, SQLState=42P01)が発生しました
2008-07-16 15:05:35,375 [http-8080-1] DEBUG
org.seasar.teeda.extension.util.TeedaExtensionErrorPageManagerImpl -
[ESSR0072]SQLで例外(SQL=[SELECT
user_cd,name_family,name_first,post,company_cd,company,organization_cd,organization,password
FROM v_user where login_ok = '1' and user_cd = ?],
Message=[[ESSR0072]SQLで例外(SQL=[SELECT
user_cd,name_family,name_first,post,company_cd,company,organization_cd,organization,password
FROM v_user where login_ok = '1' and user_cd = ?], Message=[0],
ErrorCode=42P01, SQLState={3})が発生しました : [SQLで例外(Message=
[ERROR: relation "v_user" does not exist], ErrorCode=0, SQLState=42P01)
が発生しました。], [ERROR: relation "v_user" does not exist],
ErrorCode=0, SQLState=42P01)が発生しました
org.seasar.framework.exception.SQLRuntimeException: [ESSR0072]SQLで例外
(SQL=[SELECT
user_cd,name_family,name_first,post,company_cd,company,organization_cd,organization,password
FROM v_user where login_ok = '1' and user_cd = ?],
Message=[[ESSR0072]SQLで例外(SQL=[SELECT
user_cd,name_family,name_first,post,company_cd,company,organization_cd,organization,password
FROM v_user where login_ok = '1' and user_cd = ?], Message=[0],
ErrorCode=42P01, SQLState={3})が発生しました : [SQLで例外(Message=
[ERROR: relation "v_user" does not exist], ErrorCode=0, SQLState=42P01)
が発生しました。], [ERROR: relation "v_user" does not exist],
ErrorCode=0, SQLState=42P01)が発生しました
	at
org.seasar.framework.util.PreparedStatementUtil.executeQuery(PreparedStatementUtil.java:48)
	at
org.seasar.extension.jdbc.impl.BasicResultSetFactory.createResultSet(BasicResultSetFactory.java:44)
	at
org.seasar.extension.jdbc.impl.BasicSelectHandler.createResultSet(BasicSelectHandler.java:281)
	at
org.seasar.extension.jdbc.impl.BasicSelectHandler.execute(BasicSelectHandler.java:257)
	at
org.seasar.extension.jdbc.impl.BasicSelectHandler.execute(BasicSelectHandler.java:210)
	at
org.seasar.extension.jdbc.impl.BasicSelectHandler.execute(BasicSelectHandler.java:184)
	at
org.seasar.dao.impl.SelectDynamicCommand.execute(SelectDynamicCommand.java:69)
	at
org.seasar.dao.interceptors.S2DaoInterceptor.invoke(S2DaoInterceptor.java:53)
	at
org.seasar.dao.pager.PagerS2DaoInterceptorWrapper.invoke(PagerS2DaoInterceptorWrapper.java:71)
	at
ordersheet.dao.V_userDao$$EnhancedByS2AOP$$1bb747a$$MethodInvocation$$getUserByUsercd0.proceed(MethodInvocationClassGenerator.java)
	at
org.seasar.framework.aop.interceptors.TraceInterceptor.invoke(TraceInterceptor.java:73)
	at
ordersheet.dao.V_userDao$$EnhancedByS2AOP$$1bb747a$$MethodInvocation$$getUserByUsercd0.proceed(MethodInvocationClassGenerator.java)
	at
ordersheet.dao.V_userDao$$EnhancedByS2AOP$$1bb747a.getUserByUsercd(V_userDao$$EnhancedByS2AOP$$1bb747a.java)
	at
ordersheet.web.NewentrustPage.doItakukanriseiSearch(NewentrustPage.java:89)
	at
ordersheet.web.NewentrustPage$$EnhancedByS2AOP$$56681b.$$doItakukanriseiSearch$$invokeSuperMethod$$(NewentrustPage$$EnhancedByS2AOP$$56681b.java)
	at
ordersheet.web.NewentrustPage$$EnhancedByS2AOP$$56681b$$MethodInvocation$$doItakukanriseiSearch5.proceed(MethodInvocationClassGenerator.java)



###########################ソース#############################

SingletonS2ContainerFactory.setConfigPath("dao.dicon");
SingletonS2ContainerFactory.init();
S2Container container = SingletonS2ContainerFactory.getContainer();
V_userDao dao = (V_userDao) container.getComponent(V_userDao.class);

List<V_user> userinfo = dao.getUserByUsercd(itakukanriseiid);// ←ここで
エラーになる
itakukanriseitel = "";
itakukanriseimail = "";
for (int i = 0; i < userinfo.size(); ++i) {
	// 検索がヒットした時
	itakukanriseiname = userinfo.get(i).getName_family() + " " +
userinfo.get(i).getName_first();
	itakukanriseiorg = userinfo.get(i).getCompany() + " " +
userinfo.get(i).getOrganization() + " " + userinfo.get(i).getPost();
	return null;
}	






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