linghengqian commented on code in PR #37778:
URL: https://github.com/apache/shardingsphere/pull/37778#discussion_r2706804028
##########
docs/document/content/user-manual/shardingsphere-jdbc/distsql/_index.en.md:
##########
@@ -0,0 +1,121 @@
++++
+title = "DistSQL"
+weight = 6
+chapter = true
++++
+
+# Background Information
+
+Currently, DistSQL can be executed via ShardingSphere JDBC DataSource to
dynamically modify ShardingSphere configuration.
+
+# Configuration Example
+
+## Prerequisites
+
+Include the following dependencies in your business project:
+
+```xml
+<dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-jdbc</artifactId>
+ <version>${shardingsphere.version}</version>
+</dependency>
+<dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-jdbc-dialect-mysql</artifactId>
+ <version>${shardingsphere.version}</version>
+</dependency>
+<dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-infra-data-source-pool-hikari</artifactId>
+ <version>${shardingsphere.version}</version>
+</dependency>
+<dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-infra-url-classpath</artifactId>
+ <version>${shardingsphere.version}</version>
+</dependency>
+<dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-standalone-mode-repository-memory</artifactId>
+ <version>${shardingsphere.version}</version>
+</dependency>
+<dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-sharding-core</artifactId>
+ <version>${shardingsphere.version}</version>
+</dependency>
+<dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-authority-simple</artifactId>
+ <version>${shardingsphere.version}</version>
+</dependency>
+<dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>2.2.224</version>
+</dependency>
+```
+
+Write the ShardingSphere data source configuration file `demo.yaml` on the
classpath of your business project.
+
+```yaml
+props:
+ sql-show: false
+```
+
+## Enjoy the Integration
+
+Create a ShardingSphere data source to enjoy integration.
+
+```java
+import com.zaxxer.hikari.HikariConfig;
+import com.zaxxer.hikari.HikariDataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+public class ExampleUtils {
+ void test() throws SQLException {
+ HikariConfig config = new HikariConfig();
+ config.setJdbcUrl("jdbc:shardingsphere:classpath:demo.yaml");
+
config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver");
+ try (HikariDataSource dataSource = new HikariDataSource(config);
+ Connection connection = dataSource.getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.execute("register storage unit ds_0
(url='jdbc:h2:mem:local_sharding_ds_0;MODE=MYSQL;IGNORECASE=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE',user='sa',password=''),
ds_1
(url='jdbc:h2:mem:local_sharding_ds_1;MODE=MYSQL;IGNORECASE=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE',user='sa',password=''),
ds_2
(url='jdbc:h2:mem:local_sharding_ds_2;MODE=MYSQL;IGNORECASE=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE',user='sa',password='')");
+ statement.execute("create default sharding database strategy
(type='standard',
sharding_column=user_id,sharding_algorithm(type(name=class_based,
properties('strategy'='STANDARD',
'algorithmClassName'='org.apache.shardingsphere.test.natived.commons.algorithm.ClassBasedInlineShardingAlgorithmFixture'))))");
+ statement.execute("create sharding table rule t_order
(datanodes('<LITERAL>ds_0.t_order, ds_1.t_order, ds_2.t_order'),
key_generate_strategy(column=order_id,type(name='SNOWFLAKE'))), t_order_item
(datanodes('<LITERAL>ds_0.t_order_item, ds_1.t_order_item, ds_2.t_order_item'),
key_generate_strategy(column=order_item_id,type(name='SNOWFLAKE')))");
+ statement.execute("create broadcast table rule t_address");
+ statement.execute("CREATE TABLE IF NOT EXISTS t_order (order_id
BIGINT NOT NULL AUTO_INCREMENT,order_type INT(11),user_id INT NOT
NULL,address_id BIGINT NOT NULL,status VARCHAR(50),PRIMARY KEY (order_id))");
+ statement.execute("TRUNCATE TABLE t_order");
+ statement.execute("INSERT INTO t_order (user_id, order_type,
address_id, status) VALUES (1, 1, 1, 'INSERT_TEST')");
+ statement.executeQuery("SELECT * FROM t_order");
Review Comment:
The documentation already states that the connection is disabled; you simply
didn't understand the documentation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]