The target

Get the JDBC version of ShardingSphere-5.0.0-beta, and implement the simplest library table, read and write separation (fake slave library can be used), and encryption function demonstration. Document your own process and submit documentation.

Implementation steps

Prepare the environment

  1. Git clone code
  2. Install MVN clean install MVN clean install
mvn clean install -Dmaven.test.skip=true -Dmaven.javadoc.skip=true -Drat.skip=true -Dcheckstyle.skip=true
Copy the code
  1. Use Maven to introduce example and MVN clean install
  2. The local database executes the SQL script, the script path: \ shardingSphere \examples\ SRC \resources\manual_schema.sql
  3. Database Settings, account: root, password: none (same as the configuration in Example), port: 3306

Debug the demo

Depots table

  1. Select the use case
org.apache.shardingsphere.example.sharding.raw.jdbc.ShardingRawYamlRangeConfigurationExample
Copy the code

ShardingType Select SHARDING_DATABASES

  1. There is a point in the code where records are deleted and breakpoints are set so that table data can be observed

  1. Debug Executes the main method
  2. Observation table data

  1. Contrast with the current sharding rules
  2. The breakpoint is released and the process ends

Reading and writing separation

  1. Select the use case
org.apache.shardingsphere.example.sharding.raw.jdbc.ShardingRawYamlRangeConfigurationExample
Copy the code

ShardingType Select READWRITE_SPLITTING

  1. Enable SQL printing in configuration
props:
  sql-show: true
Copy the code
  1. Execute the main method to observe the console logs

encryption

  1. Select the use case
org.apache.shardingsphere.example.encrypt.table.raw.jdbc.EncryptRawYamlConfigurationExample
Copy the code
  1. There is a point in the code where records are deleted and breakpoints are set so that table data can be observed

  1. Debug Executes the main method
  2. Observation table data

  1. The breakpoint is released and the process ends

conclusion

My first contact with ShardingSphere was also my first contact with open source project. In the process, THERE were some bumps and bumps, and I felt very tired when stepping on pits. Fortunately, I finally finished the first debugging, and the implementation details of which need further study.