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

com.github.dennisit.vplus.data.dsource.shard.strategy.SimpleModStrategy Maven / Gradle / Ivy

There is a newer version: 2.0.8
Show newest version
package com.github.dennisit.vplus.data.dsource.shard.strategy;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class SimpleModStrategy implements ShardStrategy {

    public SimpleModStrategy() {
    }

    public String getShardType() {
        return "mod";
    }

    public DataTableName handle(String tableName, String dataSourceKey, int tableShardNum, int dbShardNum, Object shardValue) {
        log.debug("进入取余算法:handle({},{},{},{},{})", new Object[]{tableShardNum, dbShardNum, tableName, dataSourceKey, shardValue});
        long shard_value = Long.valueOf(shardValue.toString());
        long tablePosition = shard_value % (long) tableShardNum;
        long dbPosition = tablePosition / (long) (tableShardNum / dbShardNum);
        String finalTableName = tableName + "_" + tablePosition;
        String finalDataSourceKey = dataSourceKey + dbPosition;
        return new DataTableName(finalTableName, finalDataSourceKey);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy