| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- package jnpf.database.constant;
- import com.google.common.collect.ImmutableMap;
- import jnpf.constant.MsgCode;
- import jnpf.exception.DataException;
- import lombok.AllArgsConstructor;
- import java.util.Map;
- import java.util.Optional;
- /**
- * 字段别名特殊标识
- *
- * @author JNPF开发平台组 YanYu
- * @version v3.4.6
- * @copyrignt 引迈信息技术有限公司
- * @date 2023-02-11
- */
- public class DbAliasConst {
- /**
- * 允空
- */
- public static final String NULL = "NULL";
- /**
- * 非空
- */
- public static final String NOT_NULL = "NOT NULL";
- /**
- * 允空
- * 0:空值 NULL、1:非空值 NOT NULL
- */
- public static final NumFieldAttr<String> ALLOW_NULL = new NumFieldAttr<>(ImmutableMap.of(
- 1, NULL,
- 0, NOT_NULL,
- -1, NOT_NULL
- ));
- /**
- * 主键
- * 0:非主键、1:主键
- */
- public static final NumFieldAttr<Boolean> PRIMARY_KEY = new NumFieldAttr<>(ImmutableMap.of(
- 1, true,
- 0, false,
- -1, false
- ));
- public static final NumFieldAttr<Boolean> AUTO_INCREMENT = new NumFieldAttr<>(ImmutableMap.of(
- 1, true,
- 0, false,
- -1, false
- ));
- /**
- * 数值对应字段属性
- * @param <T>
- */
- @AllArgsConstructor
- public static class NumFieldAttr<T>{
- private Map<Integer, T> config;
- /**
- * 获取标识
- */
- public T getSign(Integer i) {
- return config.get(i == null ? -1 : i);
- }
- /**
- * 获取数值
- */
- public Integer getNum(T sign) throws DataException {
- if(sign == null){
- return 0;
- }
- Optional<Map.Entry<Integer, T>> first = config.entrySet().stream().filter(map -> map.getValue().equals(sign)).findFirst();
- if(first.isPresent()){
- return first.get().getKey();
- }else {
- throw new DataException(MsgCode.DB012.get());
- }
- }
- }
- }
|