-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdata-stack.xml
More file actions
96 lines (82 loc) · 5.54 KB
/
data-stack.xml
File metadata and controls
96 lines (82 loc) · 5.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:sharding="http://shardingsphere.apache.org/schema/shardingsphere/sharding"
xmlns:governance="http://shardingsphere.apache.org/schema/shardingsphere/governance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://shardingsphere.apache.org/schema/shardingsphere/sharding
http://shardingsphere.apache.org/schema/shardingsphere/sharding/sharding.xsd
http://shardingsphere.apache.org/schema/shardingsphere/governance
http://shardingsphere.apache.org/schema/shardingsphere/governance/governance.xsd
">
<import resource="classpath*:META-INF/zookeeper/registry-center.xml" />
<context:component-scan base-package="org.apache.shardingsphere.example.core.mybatis" />
<bean id="demo_ds_0" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/demo_ds_0"/>
<property name="username" value="root"/>
<property name="password" value=""/>
</bean>
<bean id="demo_ds_1" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/demo_ds_1"/>
<property name="username" value="root"/>
<property name="password" value=""/>
</bean>
<sharding:sharding-algorithm id="databaseInlineStrategyShardingAlgorithm" type="INLINE">
<props>
<prop key="algorithm-expression">demo_ds_${user_id % 2}</prop>
</props>
</sharding:sharding-algorithm>
<sharding:sharding-algorithm id="orderInlineStrategyShardingAlgorithm" type="INLINE">
<props>
<prop key="algorithm-expression">t_order_${order_id % 2}</prop>
</props>
</sharding:sharding-algorithm>
<sharding:sharding-algorithm id="orderItemInlineStrategyShardingAlgorithm" type="INLINE">
<props>
<prop key="algorithm-expression">t_order_item_${order_id % 2}</prop>
</props>
</sharding:sharding-algorithm>
<sharding:standard-strategy id="databaseStrategy" sharding-column="user_id" algorithm-ref="databaseInlineStrategyShardingAlgorithm"/>
<sharding:standard-strategy id="orderTableStrategy" sharding-column="order_id" algorithm-ref="orderInlineStrategyShardingAlgorithm"/>
<sharding:standard-strategy id="orderItemTableStrategy" sharding-column="order_id" algorithm-ref="orderItemInlineStrategyShardingAlgorithm"/>
<sharding:key-generate-algorithm id="snowflakeAlgorithm" type="SNOWFLAKE">
<props>
<prop key="worker-id">123</prop>
</props>
</sharding:key-generate-algorithm>
<sharding:key-generate-strategy id="orderKeyGenerator" column="order_id" algorithm-ref="snowflakeAlgorithm" />
<sharding:key-generate-strategy id="itemKeyGenerator" column="order_item_id" algorithm-ref="snowflakeAlgorithm" />
<sharding:rule id="shardingRule">
<sharding:table-rules>
<sharding:table-rule logic-table="t_order" actual-data-nodes="demo_ds_${0..1}.t_order_${0..1}" database-strategy-ref="databaseStrategy" table-strategy-ref="orderTableStrategy" key-generate-strategy-ref="orderKeyGenerator" />
<sharding:table-rule logic-table="t_order_item" actual-data-nodes="demo_ds_${0..1}.t_order_item_${0..1}" database-strategy-ref="databaseStrategy" table-strategy-ref="orderItemTableStrategy" key-generate-strategy-ref="itemKeyGenerator" />
</sharding:table-rules>
<sharding:binding-table-rules>
<sharding:binding-table-rule logic-tables="t_order, t_order_item"/>
</sharding:binding-table-rules>
<sharding:broadcast-table-rules>
<sharding:broadcast-table-rule table="t_address"/>
</sharding:broadcast-table-rules>
</sharding:rule>
<governance:data-source id="shardingDatabasesTablesDataSource" data-source-names="demo_ds_0, demo_ds_1" reg-center-ref="regCenter" rule-refs="shardingRule" />
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="shardingDatabasesTablesDataSource" />
</bean>
<tx:annotation-driven />
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="shardingDatabasesTablesDataSource"/>
<property name="mapperLocations" value="classpath*:META-INF/mappers/*.xml"/>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="org.apache.shardingsphere.example.core.mybatis.repository"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
</beans>