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

com.yuweix.kuafu.permission.dao.SysRoleDaoImpl Maven / Gradle / Ivy

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


import com.yuweix.kuafu.permission.mapper.SysRoleMapper;
import com.yuweix.kuafu.permission.model.SysRole;
import com.yuweix.kuafu.dao.mybatis.BaseMapper;
import com.yuweix.kuafu.dao.mybatis.CacheableDao;
import com.yuweix.kuafu.permission.common.Properties;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;


/**
 * @author yuwei
 */
@Repository("sysRoleDao")
public class SysRoleDaoImpl extends CacheableDao implements SysRoleDao {
	@Resource
	private SysRoleMapper sysRoleMapper;
	@Resource
	private Properties properties;


	private static final String CACHE_KEY_ROLE_BY_NO = "cache.%s.role.by.no.%s";


	@Override
	protected BaseMapper getMapper() {
		return sysRoleMapper;
	}

	@Override
	protected String getAppName() {
		return properties.getAppName();
	}

	@Override
	protected void onchange(SysRole t) {
		deleteRoleByNoFromCache(t.getRoleNo());
	}

	@Override
	public SysRole queryRoleByNo(String roleNo) {
		String key = String.format(CACHE_KEY_ROLE_BY_NO, getAppName(), roleNo);
		SysRole role = cache.get(key);
		if (role != null) {
			return role;
		}

		role = sysRoleMapper.queryRoleByNo(roleNo);
		if (role != null) {
			cache.put(key, role, DEFAULT_CACHE_TIMEOUT);
		}
		return role;
	}

	@Override
	public void deleteRoleByNoFromCache(String roleNo) {
		String key = String.format(CACHE_KEY_ROLE_BY_NO, getAppName(), roleNo);
		cache.remove(key);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy