shardingsphere oracle各种问题总结

本文说下shardingsphere使用oracle数据库下的各种问题 。
环境:springboot2.2.10.RELEASE+mybatis+jpa+shardingsphere4.1.1
1、配置文件

  • pom.xml
1.84.1.1 org.springframework.bootspring-boot-starter-weborg.springframework.bootspring-boot-starter-data-jpaorg.mybatis.spring.bootmybatis-spring-boot-starter2.1.3com.github.pagehelperpagehelper4.1.3org.apache.shardingspheresharding-jdbc-spring-boot-starter${shardingsphere.version}com.github.norauiojdbc712.1.0.2
  • application.yml
server:port: 9900---spring:shardingsphere:enabled: trueprops:sql:show: truedatasource:names: ds0ds0:type: com.zaxxer.hikari.HikariDataSourcedriverClassName: oracle.jdbc.OracleDriver #com.mysql.cj.jdbc.DriverjdbcUrl: jdbc:oracle:thin:@10.100.102.113:1521/orcl #jdbc:mysql://localhost:3306/ds0?serverTimezone=GMT%2B8username: empi #rootpassword: empi #123123minimumIdle: 10maximumPoolSize: 200autoCommit: trueidleTimeout: 30000poolName: DS0DatabookHikariCPmaxLifetime: 1800000connectionTimeout: 30000connectionTestQuery: SELECT 1 FROM DUALsharding:tables:t_order: #逻辑表名actualDataNodes: ds$->{0}.t_order_$->{2020..2020}0$->{1..9}, ds$->{0}.t_order_$->{2020..2020}$->{10..12} #实际表tableStrategy: #分表策略standard: #标准分片策略shardingColumn: order_date #分片字段preciseAlgorithmClassName: com.pack.sharding.algorithm.DateTableShardingAlgorithmrangeAlgorithmClassName: com.pack.sharding.algorithm.DataTabeRangeShardingAlgorithmt_product:actualDataNodes: ds$->{0}.t_product_$->{0..1}tableStrategy:inline:shardingColumn: idalgorithmExpression: t_product_$->{id@Override public String doSharding(Collection availableTargetNames, PreciseShardingValue shardingValue) {Date value = http://kandian.youth.cn/index/shardingValue.getValue() ;if (value == null) {value = new Date() ;}String actualTableName = shardingValue.getLogicTableName() +"_" + formatter.format(value.toInstant().atZone(ZoneId.systemDefault())) ;if (availableTargetNames.contains(actualTableName)) {return actualTableName ;}throw new UnsupportedOperationException("未知的表名称: " + actualTableName); } }public class DataTabeRangeShardingAlgorithm implements RangeShardingAlgorithm { private static final Logger logger = LoggerFactory.getLogger(DataTabeRangeShardingAlgorithm.class) ;@Override public Collection doSharding(Collection availableTargetNames,RangeShardingValue shardingValue) {Collection result = new HashSet<>(availableTargetNames.size()) ;Range range = shardingValue.getValueRange() ;String lower = range.lowerEndpoint() ;String upper = range.upperEndpoint() ;if (lower != nullLocalDatelow = LocalDate.parse(lower, formatter); // LocalDateTime.ofInstant(lower.toInstant(), ZoneId.systemDefault()) ;LocalDate up = LocalDate.parse(upper, formatter); // LocalDateTime.ofInstant(upper.toInstant(), ZoneId.systemDefault()) ;logger.info("起始日期:{},结束日期:{}", low, up) ;while(low.isBefore(up)) {String tableName = shardingValue.getLogicTableName().toLowerCase() + "_" + DateTimeFormatter.ofPattern("yyyyMM").format(low) ;if (availableTargetNames.contains(tableName)) {result.add(tableName) ;}low = low.plusMonths(1) ;}String upperTable = shardingValue.getLogicTableName() + "_" + DateTimeFormatter.ofPattern("yyyyMM").format(up) ;if (!result.contains(upperTable)) {result.add(upperTable) ;}}logger.info("查询表集合:{}", result) ;return result ; } }