<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/tx   
        http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

    <description>database数据源配置</description>

    <!-- onedb configure start -->

    <bean id="onedbDataSource" abstract="true"
          class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        <property name="driverClass">
            <value>${jdbc.driverClassName}</value>
        </property>
        <property name="initialPoolSize">
            <value>${jdbc.initialPoolSize}</value>
        </property>
        <property name="maxPoolSize">
            <value>${jdbc.maxPoolSize}</value>
        </property>
        <property name="minPoolSize">
            <value>${jdbc.minPoolSize}</value>
        </property>
        <property name="idleConnectionTestPeriod">
            <value>${jdbc.idleConnectionTestPeriod}</value>
        </property>
        <property name="maxIdleTime">
            <value>${jdbc.maxIdleTime}</value>
        </property>
    </bean>

    <bean id="onedb_0" parent="onedbDataSource">
        <property name="jdbcUrl">
            <value>${jdbc.db_0.url}</value>
        </property>
        <property name="user">
            <value>${jdbc.db_0.username}</value>
        </property>
        <property name="password">
            <value>${jdbc.db_0.password}</value>
        </property>
    </bean>

    <bean id="vdb_one"
          class="com.baidu.ub.common.dbmanage.datasource.VirtualDataSource">
        <property name="masterSet">
            <list>
                <value>onedb_0</value>
            </list>
        </property>
        <property name="loadbalance" value="1"/>
    </bean>

    <bean id="onedbMultiDataSource" class="com.baidu.ub.common.dbmanage.datasource.MultiDataSource">
        <property name="targetDataSources">
            <map key-type="java.lang.String">
                <entry key="onedb_0" value-ref="onedb_0"/>
            </map>
        </property>
        <property name="defaultTargetDataSource" ref="onedb_0"/>
        <property name="multiDataSourceKeyContext">
            <ref local="onedbMultiDSKeyContext"/>
        </property>
    </bean>

    <bean id="onedbRouter" class="com.baidu.ub.common.dbmanage.router.IDRouter">
        <property name="prefix" value="vdb_one"/>
        <property name="dbShardingRule">
            <ref local="onedbShardingRule"/>
        </property>
    </bean>
    <bean id="onedbShardingRule"
          class="com.baidu.ub.common.dbmanage.rule.SimpleDBShardingRuleImpl">
        <property name="shardingNum" value="1"/>
    </bean>
    <bean id="onedbMultiDSKeyContext"
          class="com.baidu.ub.common.dbmanage.datasource.MultiDataSourceKeyContext">
        <property name="router">
            <ref local="onedbRouter"/>
        </property>
        <property name="dbName" value="oneDB"/>
    </bean>

    <bean id="onedbJdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="onedbMultiDataSource"/>
    </bean>
    <!-- onedb configure end -->


    <!-- Transaction config -->
    <bean id="onedbTransactionManager"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="onedbMultiDataSource"/>
    </bean>
    <tx:annotation-driven transaction-manager="onedbTransactionManager"/>

</beans>