All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.echo.sharding.algorithm.MonthPreciseShardingAlgorithm Maven / Gradle / Ivy

The newest version!
package cn.echo.sharding.algorithm;

import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;


/**
 * 按月拆表方式
 * @author lonyee
 *
 */
public class MonthPreciseShardingAlgorithm implements PreciseShardingAlgorithm {
    private final static SimpleDateFormat formatter = new SimpleDateFormat("yyyyMM");

	@Override
	public String doSharding(Collection availableTargetNames, PreciseShardingValue shardingValue) {
		String shardfix = formatter.format(shardingValue.getValue());
        for (String each : availableTargetNames) {	
            if (each.endsWith(shardfix)) {
                return each;
            }
        }
        throw new UnsupportedOperationException();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy