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

com.jn.sqlhelper.jsqlparser.expression.ExpressionConverterRegistry Maven / Gradle / Ivy

The newest version!
package com.jn.sqlhelper.jsqlparser.expression;

import com.jn.langx.annotation.Singleton;
import com.jn.langx.util.Preconditions;
import com.jn.langx.util.collection.Collects;
import com.jn.langx.util.function.Consumer;
import com.jn.langx.util.spi.CommonServiceProvider;
import com.jn.sqlhelper.dialect.expression.SQLExpression;
import net.sf.jsqlparser.expression.Expression;

import java.util.HashMap;
import java.util.Map;

@Singleton
public class ExpressionConverterRegistry {
    private static final ExpressionConverterRegistry instance = new ExpressionConverterRegistry();

    private Map, ExpressionConverter> standardExpressionConverterMap = new HashMap, ExpressionConverter>();
    private Map, ExpressionConverter> jsqlparserExpressionConverterMap = new HashMap, ExpressionConverter>();

    private ExpressionConverterRegistry() {
        registryBuiltins();
    }

    public static ExpressionConverterRegistry getInstance() {
        return instance;
    }

    public void registry(ExpressionConverter converter) {
        Class standardExpressionClass = converter.getStandardExpressionClass();
        Class jSqlParserExpressionClass = converter.getJSqlParserExpressionClass();
        Preconditions.checkNotNull(standardExpressionClass);
        Preconditions.checkNotNull(jSqlParserExpressionClass);
        standardExpressionConverterMap.put(standardExpressionClass, converter);
        jsqlparserExpressionConverterMap.put(jSqlParserExpressionClass, converter);
    }

    private void registryBuiltins(){
        Collects.forEach(CommonServiceProvider.loadService(ExpressionConverter.class), new Consumer() {
            @Override
            public void accept(ExpressionConverter converter) {
                registry(converter);
            }
        });
    }

    public ExpressionConverter getExpressionConverterByStandardExpressionClass(Class  clazz){
        return standardExpressionConverterMap.get(clazz);
    }
    public ExpressionConverter getExpressionConverterByJSqlParserExpressionClass(Class  clazz){
        return jsqlparserExpressionConverterMap.get(clazz);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy