forked from cpsing/tddl
-
Notifications
You must be signed in to change notification settings - Fork 17
QuickStart
mengshi edited this page Jan 28, 2014
·
4 revisions
<dependency> <groupId>com.taobao.tddl</groupId> <artifactId>tddl-matrix</artifactId> <version>5.0.0-SNAPSHOT</version> </dependency>
//初始化DataSource,只需要一个appname,我们会帮您配好 TDataSource ds = new TDataSource(); ds.setAppName("app_name"); ds.init();//其余的just jdbc Connection con = null; con = us.getConnection(); PreparedStatement ps = con.prepareStatement("select * from auction_auctions limit 10"); ResultSet rs = ps.executeQuery(); while (rs.next()) { System.out.println(rs.getObject(1)); System.out.println(rs.getObject(2)); System.out.println(rs.getString(3)); System.out.println(rs.getObject(4)); }</pre>
<bean id="ds" class="com.taobao.tddl.matrix.jdbc.TDataSource" init-method="init"> <property name="appName" value="app_name" /> </bean>
拓扑文件
topology.xml
<?xml version="1.0" encoding="UTF-8"?> <matrix name="test_matrix" xmlns="https://github.com/tddl/tddl/schema/matrix" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://github.com/tddl/tddl/schema/matrix https://raw.github.com/tddl/tddl/master/tddl-common/src/main/resources/META-INF/matrix.xsd"><group name="andor_show_group0" type="MYSQL_JDBC"> <properties> <property name="com.taobao.tddl.jdbc.group_V2.4.1_andor_show_group0"> <value>andor_show_group0_atom0:r10w10p0</value> </property> </properties> <atom name="andor_show_group0_atom0"> <properties> <property name="com.taobao.tddl.atom.global.andor_show_group0_atom0"> <value> ip=10.232.31.21 port=3306 dbName=andor_show dbType=mysql dbStatus=RW </value> </property> <property name="com.taobao.tddl.atom.app.andor_show.andor_show_group0_atom0"> <value> userName=andor minPoolSize=20 maxPoolSize=40 idleTimeout=20 blockingTimeout=10000 preparedStatementCacheSize=1000 connectionProperties=characterEncoding=gbk;autoReconnect=true readRestrictTimes=0 writeRestrictTimes=0 timeSliceInMillis=0 </value> </property> <property name="com.taobao.tddl.atom.passwd.andor_show.mysql.andor"> <value>encPasswd=andor</value> </property> </properties> </atom> <atom name=""> </atom> <atom name=""> </atom> </group> <group name="andor_show_group1" type="MYSQL_JDBC"> </group> <group name="ob_group" type="OCEANBASE_JDBC"> <properties> <property name="CONFIGURL"> <value>http://obconsole.test.alibaba-inc.com/ob-config/config.co?dataId=wireless_message</value> </property> </properties> </group>
</matrix>
规则文件:
rule.xml
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="vtabroot" class="com.taobao.tddl.interact.rule.VirtualTableRoot" init-method="init"> <property name="dbType" value="MYSQL" /> <property name="defaultDbIndex" value="ob_group" /> <property name="tableRules"> <map> <entry key="auction_auctions._auction_id" value-ref="auction_auctions._auction_id" /> <entry key="bmw_users._id" value-ref="bmw_users._id" /> <entry key="buyer_tc_biz_order._biz_order_id" value-ref="buyer_tc_biz_order._biz_order_id" /> <entry key="seller_tc_biz_order._biz_order_id" value-ref="seller_tc_biz_order._biz_order_id" /> <entry key="sqls._id" value-ref="sqls._id" /> <entry key="testtable._id" value-ref="testtable._id" /> <entry key="testtable2._id" value-ref="testtable2._id" /> <entry key="bmw_users" value-ref="bmw_users._id" /> <entry key="xsl" value-ref="xsl._id" /> </map> </property> </bean><bean id="testtable._id" class="com.taobao.tddl.interact.rule.TableRule"> <property name="allowFullTableScan" value="true" /> <property name="dbNamePattern" value="andor_show_group0" /> <property name="tbRules" value="Math.abs(Long.valueOf(#id,1,4#)) % 4" /> <property name="tbNamePattern" value="testtable_{0000}" /> </bean> <bean id="testtable2._id" class="com.taobao.tddl.interact.rule.TableRule"> <property name="allowFullTableScan" value="true" /> <property name="dbNamePattern" value="andor_show_group0" /> <property name="tbRules" value="Math.abs(Long.valueOf(#id,1,4#)) % 4" /> <property name="tbNamePattern" value="testtable2_{0000}" /> </bean> <bean id="auction_auctions._auction_id" class="com.taobao.tddl.interact.rule.TableRule"> <property name="allowFullTableScan" value="true" /> <property name="dbNamePattern" value="andor_show_group0" /> <property name="tbRules" value="Math.abs(Long.valueOf(#auction_id,1,4#)) % 4" /> <property name="tbNamePattern" value="auction_auctions_{0000}" /> </bean> <bean id="bmw_users._id" class="com.taobao.tddl.interact.rule.TableRule"> <property name="allowFullTableScan" value="true" /> <property name="dbNamePattern" value="andor_show_group{0}" /> <property name="dbRules" value="Math.abs(Long.valueOf(#id,1,1#)) % 2" /> <property name="tbRules" value="Math.abs(Long.valueOf(#id,1,4#)) % 4" /> <property name="tbNamePattern" value="bmw_users_{0000}" /> </bean> <bean id="buyer_tc_biz_order._biz_order_id" class="com.taobao.tddl.interact.rule.TableRule"> <property name="allowFullTableScan" value="true" /> <property name="dbNamePattern" value="andor_show_group0" /> <property name="tbRules" value="Math.abs(Long.valueOf(#buyer_id,1,4#)) % 4" /> <property name="tbNamePattern" value="buyer_tc_biz_order_{0000}" /> </bean> <bean id="seller_tc_biz_order._biz_order_id" class="com.taobao.tddl.interact.rule.TableRule"> <property name="allowFullTableScan" value="true" /> <property name="dbNamePattern" value="andor_show_group0" /> <property name="tbRules" value="Math.abs(Long.valueOf(#seller_id,1,4#)) % 4" /> <property name="tbNamePattern" value="seller_tc_biz_order_{0000}" /> </bean> <bean id="sqls._id" class="com.taobao.tddl.interact.rule.TableRule"> <property name="allowFullTableScan" value="true" /> <property name="dbNamePattern" value="andor_show_group0" /> <property name="tbNamePattern" value="sqls" /> </bean> <bean id="xsl._id" class="com.taobao.tddl.interact.rule.TableRule"> <property name="allowFullTableScan" value="true" /> <property name="dbNamePattern" value="ob_group" /> <property name="tbNamePattern" value="xsl" /> </bean>
</beans>