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

com.yuweix.kuafu.boot.dao.HibernateAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package com.yuweix.kuafu.boot.dao;


import com.yuweix.kuafu.dao.PersistCache;
import com.yuweix.kuafu.dao.springboot.HibernateConf;
import com.yuweix.kuafu.data.cache.Cache;
import com.yuweix.kuafu.sequence.springboot.SequenceConf;
import com.yuweix.kuafu.sharding.springboot.ShardingConf;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;


/**
 * @author yuwei
 */
@Configuration
@ConditionalOnProperty(name = "kuafu.boot.dao.hibernate.enabled")
@Import({HibernateConf.class, SequenceConf.class, ShardingConf.class})
public class HibernateAutoConfiguration {
    @ConditionalOnMissingBean(PersistCache.class)
    @Bean(name = "persistCache")
    public PersistCache persistCache(@Autowired(required = false) Cache cache) {
        return new PersistCache() {
            @Override
            public  boolean put(String key, T t, long timeout) {
                return cache != null && cache.put(key, t, timeout);
            }
            @Override
            public  T get(String key) {
                return cache == null ? null : cache.get(key);
            }
            @Override
            public void remove(String key) {
                if (cache == null) {
                    return;
                }
                cache.remove(key);
            }
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy