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

org.zodiac.datasource.jdbc.dynamic.DynamicDataSourceExpressionHolder Maven / Gradle / Ivy

The newest version!
package org.zodiac.datasource.jdbc.dynamic;

import org.springframework.expression.spel.support.StandardEvaluationContext;

public class DynamicDataSourceExpressionHolder {

    /**
     * 表达式上下文。
     */
    private static final ThreadLocal DYNAMIC_DATASOURCE_EXPRESSION_CONTEXT =
        new ThreadLocal() {
            @Override
            protected StandardEvaluationContext initialValue() {
                return new StandardEvaluationContext();
            }
        };

    /**
     * 设置表达式值。
     * 
     * @param exprKey 过期key
     * @param exprValue 过期值
     */
    public static void put(String exprKey, String exprValue) {
        DYNAMIC_DATASOURCE_EXPRESSION_CONTEXT.get().setVariable(exprKey, exprValue);
    }

    /**
     * 清除表达式值。
     * 
     * @param exprKey 过期key
     */
    public static void clear(String exprKey) {
        DYNAMIC_DATASOURCE_EXPRESSION_CONTEXT.get().setVariable(exprKey, null);
    }

    public static StandardEvaluationContext getExpressionContext() {
        return DYNAMIC_DATASOURCE_EXPRESSION_CONTEXT.get();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy