com.github.javaclub.cdl.client.matrix.jdbc.ShardingValue Maven / Gradle / Ivy
package com.github.javaclub.cdl.client.matrix.jdbc;
import java.util.Collection;
import java.util.Collections;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
import com.google.common.collect.Range;
/**
* 分片值.
*
*
* 目前支持{@code =, IN, BETWEEN};
* 不支持{@code , >, <=, >=, LIKE, NOT, NOT IN}.
*
*
*/
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
@ToString
public final class ShardingValue> {
private final String columnName;
private final T value;
private final Collection values;
private final Range valueRange;
public ShardingValue(final String columnName, final T value) {
this(columnName, value, Collections.emptyList(), null);
}
public ShardingValue(final String columnName, final Collection values) {
this(columnName, null, values, null);
}
public ShardingValue(final String columnName, final Range valueRange) {
this(columnName, null, Collections.emptyList(), valueRange);
}
/**
* 获取分片值类型.
*
* @return 分片值类型
*/
public ShardingValueType getType() {
if (null != value) {
return ShardingValueType.SINGLE;
}
if (!values.isEmpty()) {
return ShardingValueType.LIST;
}
return ShardingValueType.RANGE;
}
/**
* 分片值类型.
*
* @author zhangliang
*/
public enum ShardingValueType {
SINGLE, LIST, RANGE
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy