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

com.github.chengyuxing.sql.dsl.clause.ColumnHelper Maven / Gradle / Ivy

Go to download

Light wrapper of JDBC, support ddl, dml, query, plsql/procedure/function, transaction and manage sql file.

There is a newer version: 9.0.2
Show newest version
package com.github.chengyuxing.sql.dsl.clause;

import com.github.chengyuxing.sql.dsl.types.FieldReference;
import com.github.chengyuxing.sql.dsl.types.Operator;
import com.github.chengyuxing.sql.dsl.types.StandardOperator;
import com.github.chengyuxing.sql.utils.EntityUtil;
import org.jetbrains.annotations.NotNull;

import java.lang.reflect.Field;
import java.util.Objects;
import java.util.Set;

public abstract class ColumnHelper {
    protected final Class clazz;

    protected ColumnHelper(@NotNull Class clazz) {
        this.clazz = clazz;
    }

    protected abstract Set columnWhiteList();

    protected abstract Set operatorWhiteList();

    protected @NotNull String getColumnName(@NotNull FieldReference fieldReference) {
        String fieldName = EntityUtil.getFieldNameWithCache(fieldReference);
        try {
            Field field = clazz.getDeclaredField(fieldName);
            field.setAccessible(true);
            return EntityUtil.getColumnName(field);
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        }
    }

    protected boolean isIllegalColumn(String column) {
        if (Objects.isNull(columnWhiteList()) || columnWhiteList().isEmpty()) {
            return true;
        }
        return !columnWhiteList().contains(column);
    }

    protected boolean isIllegalOperator(@NotNull Operator operator) {
        if (operator instanceof StandardOperator) {
            return false;
        }
        if (Objects.isNull(operatorWhiteList()) || operatorWhiteList().isEmpty()) {
            return true;
        }
        return !operatorWhiteList().contains(operator.getValue());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy