Introduction to the
Sharding-jdbc is the first product of ShardingSphere and the predecessor of ShardingSphere. It is positioned as a lightweight Java framework that provides additional services in Java’s JDBC layer. It uses the client directly connected to the database, in the form of JAR package to provide services, without additional deployment and dependence, can be understood as an enhanced VERSION of THE JDBC driver, fully compatible with JDBC and various ORM frameworks.
- Works with any JDBC-based ORM framework, such as JPA, Hibernate, Mybatis, Spring JDBC Template or directly using JDBC.
- Support any third party database connection pool, such as DBCP, C3P0, BoneCP, Druid, HikariCP, etc.
- Support for any database that implements the JDBC specification. Currently supports MySQL, Oracle, SQLServer, PostgreSQL and any database that complies with the SQL92 standard.
contrast
Sharding-JDBC | Sharding-Proxy | Sharding-Sidecar | |
---|---|---|---|
The database | any |
MySQL/PostgreSQL | MySQL/PostgreSQL |
Connection consumption | high |
low | high |
Heterogeneous language | Only the Java |
any | any |
performance | Low loss |
Loss is slightly high | Low loss |
There is no centralized | is |
no | is |
Static entry | There is no |
There are | There is no |
Sharding-jdbc has the advantage of being friendly to Java applications.
The internal structure
The yellow part
The yellow part of the figure represents the sharding-JDBC entry API, provided in the form of a factory method. There are two ShardingDataSourceFactory and MasterSlaveDataSourceFactory factory class. ShardingDataSourceFactory used to create the depots table separation or depots table +, speaking, reading and writing JDBC driver, MasterSlaveDataSourceFactory used to create separate JDBC driver used independently, speaking, reading and writing.
The blue part
The blue parts of the figure represent sharding-JDBC configuration objects, which provide flexible configuration methods. ShardingRuleConfiguration is the core of the depots table configuration and entry, and it can contain multiple TableRuleConfiguration MasterSlaveRuleConfiguration. A TableRuleConfiguration is configured for each set of tables with the same rule fragment. If it is necessary to separate or depots table and read and write common use, read and write each separate a MasterSlaveRuleConfiguration logic library configuration. Each TableRuleConfiguration corresponds to a ShardingStrategyConfiguration, it has 5 implementation classes to choose from.
Separate use MasterSlaveRuleConfiguration can only, speaking, reading and writing.
The red part
The red parts of the figure represent internal objects, which are used internally by Sharding-JDBC and are of no concern to application developers. Sharding – JDBC by ShardingRuleConfiguration and MasterSlaveRuleConfiguration generation for real ShardingDataSource and MasterSlaveDataSource rules for use Elephant. ShardingDataSource and MasterSlaveDataSource realize DataSource interface, is the complete implementation of JDBC.
Initialization Process
- Configure the Configuration object.
- The Configuration object is converted into a Rule object using the Factory object.
- The Rule object is assembled with the DataSource object through the Factory object.
- Sharding-jdbc uses the DataSource object for sorting libraries.
Use conventions
In the org. Apache. Shardingsphere. API and org. Apache. Shardingsphere. Shardingjdbc. API classes in the package is user-oriented API, every change will be explicitly stated in the release notes. Classes in other packages are internal implementations and may be modified at any time. Do not use them directly.