lvjingang-git opened a new issue, #29707:
URL: https://github.com/apache/shardingsphere/issues/29707

   In version 5.4.1, ShardingSphere jdbc was used, and only one table needed to 
be partitioned. The other tables did not need to be partitioned. After 
configuring it through the Java API, it was found that the sharded table was 
normal (storing log information by month), but non sharded tables reported 
errors
   
   Table or View ` log_ Server_ Resource_ The top ` does not exist 
'configuration of my Java API is as follows
   
   
   public DataSource getDataSource() throws SQLException {
               Properties otherProperties = new Properties();
               otherProperties.setProperty("sql.show", "true");
               return ShardingSphereDataSourceFactory.createDataSource(
                       "esspdf188_test",
                       createDataSourceMap(),
                       Arrays.asList(createShardingRuleConfiguration()),
                       otherProperties);
           }
   
           private ShardingRuleConfiguration createShardingRuleConfiguration() {
               //分片规则
               ShardingRuleConfiguration result = new 
ShardingRuleConfiguration();
               //配置表的分片策略
               result.getTables().add(getTableRuleConfiguration());
   
               HashMap<String, AlgorithmConfiguration> algorithmClassName = new 
HashMap<>();
               //配置分片算法
               Properties properties=new Properties();
               
properties.put("algorithmClassName","cn.logServer.start.service.DateStrategyShardingAlgorithm");
               properties.put("strategy","standard");
               AlgorithmConfiguration algorithmConfiguration = new 
AlgorithmConfiguration("CLASS_BASED",properties);
               
algorithmClassName.put("date-strategy-inline",algorithmConfiguration);
   
               result.setShardingAlgorithms(algorithmClassName);
               return result;
           }
   
           private ShardingTableRuleConfiguration getTableRuleConfiguration() {
               String year = DateUtils.getYear();
               ShardingTableRuleConfiguration shardingTableRuleConfiguration = 
new ShardingTableRuleConfiguration(
                       db_0_logic_table, db_0_dbName + ".log_server_save_$->{" 
+ year + "}_$->{01..12}");
               shardingTableRuleConfiguration.setTableShardingStrategy(new 
StandardShardingStrategyConfiguration(
                       "requestTime", "date-strategy-inline"));
               return shardingTableRuleConfiguration;
           }
   
           public SingleRuleConfiguration singleRuleConfiguration(){
               SingleRuleConfiguration singleRuleConfiguration=new 
SingleRuleConfiguration();
               singleRuleConfiguration.setDefaultDataSource("esspdf188_test");
               return singleRuleConfiguration;
           }
   
   
           private Map<String, DataSource> createDataSourceMap() {
               Map<String, DataSource> dataSourceMap = new HashMap<>();
               BasicDataSource dbcpDataSource = new BasicDataSource();
               dbcpDataSource.setDriverClassName(db_0_driverClassName);
               dbcpDataSource.setUrl(db_0_url);
               dbcpDataSource.setUsername(db_0_username);
               dbcpDataSource.setPassword(decrypt(db_0_password));
               dataSourceMap.put(db_0_dbName, dbcpDataSource);
               return dataSourceMap;
           }
   
       }


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