A simple database shard middleware, based on JDBC API. Applications can scale database by using new DataSource with simple-sharding. This project is not finished, and feel free to study.
- Transaction in single database shard
- Sharding
- Rewriting rules
git clone https://github.com/yuanwhy/simple-sharding.git
and then execute test/create_schema.sql
to init data.
mvn clean install
<dependency>
<groupId>com.yuanwhy</groupId>
<artifactId>simple-sharding</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:simple-sharding="http://yuanwhy.com/schema/simple-sharding"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd http://yuanwhy.com/schema/simple-sharding http://yuanwhy.com/schema/simple-sharding.xsd">
<simple-sharding:hashShardingRule id="hashShardingRule" dbCount="2" tableCount="2" fieldNameForDb="role"
fieldNameForTable="id"/>
<simple-sharding:logicDataSource id="dataSource"
name="passport"
shardingRule="hashShardingRule">
<simple-sharding:physicalDataSource name="passport_0" jdbcUrl="jdbc:mysql://127.0.0.1:3306/passport_0"
user="root" password=""/>
<simple-sharding:physicalDataSource name="passport_1" jdbcUrl="jdbc:mysql://127.0.0.1:3306/passport_0"
user="root" password=""/>
</simple-sharding:logicDataSource>
</beans>
- Support Spring custom namespace
- Finish other methods
- Support multiple tables in one datasource
Apache License, Version 2.0