linghengqian commented on issue #16725:
URL: 
https://github.com/apache/shardingsphere/issues/16725#issuecomment-3772787007

   - To make a long story short, modifying actualDataNodes via the Java API is 
still not very human-friendly. I've opened 
https://github.com/apache/shardingsphere/pull/37778 . The branch where the PR 
is located supports this syntax.
   
   ```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("""
                       create default sharding database strategy if not exists (
                           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 if not exists 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'))
                       )
                       """);
               statement.execute("SELECT * FROM t_order");
               statement.execute("""
                       alter sharding table rule t_order (
                           datanodes(
                               '<LITERAL>ds_0.t_order, ds_1.t_order, 
ds_2.t_order, ds_3.t_order'
                           ),
                           key_generate_strategy(column = order_id, type(name = 
'SNOWFLAKE'))
                       )
                       """);
               statement.execute("SELECT * FROM t_order");
           }
       }
   }
   ```
   - Feel free to submit reviews for 
https://github.com/apache/shardingsphere/pull/37778 .


-- 
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]

Reply via email to