Example usage for org.apache.ibatis.mapping CacheBuilder addDecorator

List of usage examples for org.apache.ibatis.mapping CacheBuilder addDecorator

Introduction

In this page you can find the example usage for org.apache.ibatis.mapping CacheBuilder addDecorator.

Prototype

public CacheBuilder addDecorator(Class<? extends Cache> decorator) 

Source Link

Usage

From source file:com.badminton.interceptors.mySqlHelper.pagehelper.cache.SimpleCache.java

License:Open Source License

public SimpleCache(Properties properties, String prefix) {
    CacheBuilder cacheBuilder = new CacheBuilder("SQL_CACHE");
    String typeClass = properties.getProperty(prefix + ".typeClass");
    if (StringUtil.isNotEmpty(typeClass)) {
        try {/*w  w  w.  j  ava 2  s.c o m*/
            cacheBuilder
                    .implementation((Class<? extends org.apache.ibatis.cache.Cache>) Class.forName(typeClass));
        } catch (ClassNotFoundException e) {
            cacheBuilder.implementation(PerpetualCache.class);
        }
    } else {
        cacheBuilder.implementation(PerpetualCache.class);
    }
    String evictionClass = properties.getProperty(prefix + ".evictionClass");
    if (StringUtil.isNotEmpty(evictionClass)) {
        try {
            cacheBuilder.addDecorator(
                    (Class<? extends org.apache.ibatis.cache.Cache>) Class.forName(evictionClass));
        } catch (ClassNotFoundException e) {
            cacheBuilder.addDecorator(FifoCache.class);
        }
    } else {
        cacheBuilder.addDecorator(FifoCache.class);
    }
    String flushInterval = properties.getProperty(prefix + ".flushInterval");
    if (StringUtil.isNotEmpty(flushInterval)) {
        cacheBuilder.clearInterval(Long.parseLong(flushInterval));
    }
    String size = properties.getProperty(prefix + ".size");
    if (StringUtil.isNotEmpty(size)) {
        cacheBuilder.size(Integer.parseInt(size));
    }
    cacheBuilder.properties(properties);
    CACHE = cacheBuilder.build();
}

From source file:com.sinotopia.mybatis.pagehelper.cache.SimpleCache.java

License:Open Source License

public SimpleCache(Properties properties, String prefix) {

    CacheBuilder cacheBuilder = new CacheBuilder("SQL_CACHE");
    String typeClass = properties.getProperty(prefix + ".typeClass");
    if (StringUtil.isNotEmpty(typeClass)) {
        try {//from   w  ww . j  ava 2  s  . co  m
            cacheBuilder
                    .implementation((Class<? extends org.apache.ibatis.cache.Cache>) Class.forName(typeClass));
        } catch (ClassNotFoundException e) {
            cacheBuilder.implementation(PerpetualCache.class);
        }
    } else {
        cacheBuilder.implementation(PerpetualCache.class);
    }
    String evictionClass = properties.getProperty(prefix + ".evictionClass");
    if (StringUtil.isNotEmpty(evictionClass)) {
        try {
            cacheBuilder.addDecorator(
                    (Class<? extends org.apache.ibatis.cache.Cache>) Class.forName(evictionClass));
        } catch (ClassNotFoundException e) {
            cacheBuilder.addDecorator(FifoCache.class);
        }
    } else {
        cacheBuilder.addDecorator(FifoCache.class);
    }
    String flushInterval = properties.getProperty(prefix + ".flushInterval");
    if (StringUtil.isNotEmpty(flushInterval)) {
        cacheBuilder.clearInterval(Long.parseLong(flushInterval));
    }
    String size = properties.getProperty(prefix + ".size");
    if (StringUtil.isNotEmpty(size)) {
        cacheBuilder.size(Integer.parseInt(size));
    }
    cacheBuilder.properties(properties);
    CACHE = cacheBuilder.build();
}