shardingsphere oracle各种问题总结
本文说下shardingsphere使用oracle数据库下的各种问题 。
环境:springboot2.2.10.RELEASE+mybatis+jpa+shardingsphere4.1.1
1、配置文件
- pom.xml
1.8 4.1.1 org.springframework.boot spring-boot-starter-weborg.springframework.boot spring-boot-starter-data-jpaorg.mybatis.spring.boot mybatis-spring-boot-starter2.1.3 com.github.pagehelper pagehelper4.1.3 org.apache.shardingsphere sharding-jdbc-spring-boot-starter${shardingsphere.version} com.github.noraui ojdbc712.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 ; } }
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- keytypes(org.Hs.eg.db)基因的各种样子
- 如果你的手机出现“3大症状”,说明被“监听”了!请尽快自查
- 更新小彩蛋:iOS 14.3可让Siri播放各种动物和乐器的声音
- 不懂参数,不懂硬件,新手小白如何选购合适各种需要的电脑主机
- “闪修侠”上门换电池,修完后出现各种问题?
- SQL竞争对手简史
- 小程序开发行业各种“低价乱飞”,该怎么面对低价竞争?
- Oracle Linux希望吸引正寻找替代方案的CentOS用户
- Windows 10用户报告奇怪的蓝屏故障 各种原因都有
- 币价创新高,显卡都卖疯了,那么各种显卡的收益有多少呢