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

net.paoding.rose.jade.config.JadeConfig Maven / Gradle / Ivy

package net.paoding.rose.jade.config;

import net.paoding.rose.jade.cache.JadeCache;
import net.paoding.rose.jade.cache.impl.CaffeineCache;
import net.paoding.rose.jade.cache.impl.LocalCache;
import net.paoding.rose.jade.properties.JadeDatasourceProperties;
import net.paoding.rose.jade.properties.RoseJadeProperties;
import net.paoding.rose.jade.statement.Statement;
import net.paoding.rose.jade.statement.interpreter.Interpreter;
import net.paoding.rose.jade.statement.interpreter.Jexl3Interpreter;
import net.paoding.rose.jade.statement.jexl.analysis.Analysis;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

import java.lang.reflect.Method;
import java.util.List;

/**
 * @author zhangfusheng
 * @date 2023/5/9
 */
@EnableConfigurationProperties({RoseJadeProperties.class, JadeDatasourceProperties.class})
public class JadeConfig {

    @Bean("jadeMethodStatementCache")
    @ConditionalOnClass(name = {"com.github.benmanes.caffeine.cache.Caffeine"})
    public JadeCache jadeCaffeineCache(RoseJadeProperties roseJadeProperties) {
        return new CaffeineCache<>(roseJadeProperties);
    }

    @Bean("jadeMethodStatementCache")
    @ConditionalOnMissingClass("com.github.benmanes.caffeine.cache.Caffeine")
    public JadeCache jadeLocalCache() {
        return new LocalCache<>();
    }

    @Bean("jadeSqlAnalysisCache")
    @ConditionalOnClass(name = {"com.github.benmanes.caffeine.cache.Caffeine"})
    public JadeCache> jadeSqlCaffeineCache(RoseJadeProperties roseJadeProperties) {
        return new CaffeineCache<>(roseJadeProperties);
    }

    @Bean("jadeSqlAnalysisCache")
    @ConditionalOnMissingClass("com.github.benmanes.caffeine.cache.Caffeine")
    public JadeCache> jadeSqlLocalCache() {
        return new LocalCache<>();
    }

    @Bean
    @ConditionalOnProperty(value = "jade.config.use-jexl3-interpreter", havingValue = "true")
    public Interpreter jexl3Interpreter(
            @Qualifier("jadeSqlAnalysisCache") JadeCache> jadeSqlAnalysisCache) {
        return new Jexl3Interpreter(jadeSqlAnalysisCache);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy