com.taotao.boot.data.shardingsphere.algorithm.CreateTimeShardingTableAlgorithmBak Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of taotao-boot-starter-data-shardingsphere Show documentation
Show all versions of taotao-boot-starter-data-shardingsphere Show documentation
taotao-boot-starter-data-shardingsphere
The newest version!
/*
* Copyright (c) 2020-2030, Shuigedeng ([email protected] & https://blog.taotaocloud.top/).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.taotao.boot.data.shardingsphere.algorithm;
import com.taotao.boot.common.utils.date.DateUtils;
import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Properties;
/** 按创建时间月份分表 */
public class CreateTimeShardingTableAlgorithmBak implements StandardShardingAlgorithm {
@Override
public String doSharding(Collection collection, PreciseShardingValue preciseShardingValue) {
Long createTime = preciseShardingValue.getValue();
String value = DateUtils.toString(createTime, "MM");
Integer month = Integer.valueOf(value);
// t_order_1,t_order_2~
return "t_order_" + month;
}
@Override
public Collection doSharding(Collection collection, RangeShardingValue rangeShardingValue) {
Collection collect = new ArrayList<>();
// 因为考虑到 假设2019-05~2020-05
// 这快是没办法处理的,因为分库分表之后,每个库都要进行查询,如果操作为,1-4月,那么2020年数据查询正确了,可是2019年到5-12月数据就查询不到了
// 这里需要做一些性能的浪费,现在看来是没办法处理到
for (int i = 1; i <= 12; i++) {
collect.add("t_order_" + i);
}
return collect;
}
// @Override
// public void init() {
//
// }
@Override
public String getType() {
return null;
}
@Override
public void init(Properties props) {}
}