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

cn.echo.sharding.algorithm.DailyPreciseShardingAlgorithm 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 DailyPreciseShardingAlgorithm implements PreciseShardingAlgorithm {

    private final static SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");

	@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