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

com.sagframe.sagacity.sqltoy.plus.MultiFiledMappingStrategy Maven / Gradle / Ivy

The newest version!
package com.sagframe.sagacity.sqltoy.plus;

import com.sagframe.sagacity.sqltoy.plus.conditions.toolkit.FiledNature;
import com.sagframe.sagacity.sqltoy.plus.conditions.toolkit.StringPool;
import com.sagframe.sagacity.sqltoy.plus.multi.MultiContext;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public interface MultiFiledMappingStrategy extends FiledMappingStrategy {

    default String getColumnName(MultiContext context, Class clazz, String filedName) {
        String tableAlisaName = context.getEntityAlisaName(clazz);
        if (tableAlisaName == null || tableAlisaName.isEmpty()) {
            return getColumnName(clazz, filedName);
        }
        return tableAlisaName + StringPool.DOT + getColumnName(clazz, filedName);
    }

    default String getSplitColumnName(MultiContext context, List natures, String regex) {
        if (natures != null && !natures.isEmpty()) {
            return natures.stream().filter(Objects::nonNull).map(e -> getColumnName(context, e.getClazz(), e.getFiledName())).collect(Collectors.joining(regex));
        }
        return null;
    }

    class DefaultFiledMappingStrategy implements MultiFiledMappingStrategy {

        private DefaultFiledMappingStrategy() {}

        @Override
        public String getColumnName(Class clazz, String filedName) {
            return filedName;
        }

        public static DefaultFiledMappingStrategy getInstance() {
            return DefaultFiledMappingStrategy.DefaultFiledMappingStrategyHolder.instance;
        }

        protected static class DefaultFiledMappingStrategyHolder {
            private static DefaultFiledMappingStrategy instance = new DefaultFiledMappingStrategy();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy