(151) - 数据添加Ehcache缓存支持
parent
ea6d92f563
commit
ec46267f66
|
@ -0,0 +1,38 @@
|
|||
package com.monkeyk.sos.infrastructure;
|
||||
|
||||
/**
|
||||
* 2016/7/22
|
||||
* <p/>
|
||||
* 定义系统中使用的CACHE的常量
|
||||
* 名称与 ehcache.xml 中对应
|
||||
* <p/>
|
||||
*
|
||||
* @author Shengzhao Li
|
||||
*/
|
||||
public abstract class CacheConstants {
|
||||
|
||||
/**
|
||||
* client Details Cache
|
||||
*/
|
||||
public static final String CLIENT_DETAILS_CACHE = "clientDetailsCache";
|
||||
|
||||
/**
|
||||
* access Token Cache
|
||||
*/
|
||||
public static final String ACCESS_TOKEN_CACHE = "accessTokenCache";
|
||||
|
||||
/**
|
||||
* authorization Code Cache
|
||||
*/
|
||||
public static final String AUTHORIZATION_CODE_CACHE = "authorizationCodeCache";
|
||||
|
||||
/**
|
||||
* user Cache
|
||||
*/
|
||||
public static final String USER_CACHE = "userCache";
|
||||
|
||||
|
||||
private CacheConstants() {
|
||||
}
|
||||
|
||||
}
|
|
@ -13,7 +13,10 @@ package com.monkeyk.sos.infrastructure.jdbc;
|
|||
|
||||
import com.monkeyk.sos.domain.oauth.OauthClientDetails;
|
||||
import com.monkeyk.sos.domain.oauth.OauthRepository;
|
||||
import com.monkeyk.sos.infrastructure.CacheConstants;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
@ -28,7 +31,6 @@ import java.util.List;
|
|||
public class OauthRepositoryJdbc implements OauthRepository {
|
||||
|
||||
|
||||
|
||||
private static OauthClientDetailsRowMapper oauthClientDetailsRowMapper = new OauthClientDetailsRowMapper();
|
||||
|
||||
|
||||
|
@ -37,6 +39,7 @@ public class OauthRepositoryJdbc implements OauthRepository {
|
|||
|
||||
|
||||
@Override
|
||||
@Cacheable(value = CacheConstants.CLIENT_DETAILS_CACHE, key = "#clientId")
|
||||
public OauthClientDetails findOauthClientDetails(String clientId) {
|
||||
final String sql = " select * from oauth_client_details where client_id = ? ";
|
||||
final List<OauthClientDetails> list = this.jdbcTemplate.query(sql, new Object[]{clientId}, oauthClientDetailsRowMapper);
|
||||
|
@ -50,6 +53,7 @@ public class OauthRepositoryJdbc implements OauthRepository {
|
|||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = CacheConstants.CLIENT_DETAILS_CACHE, key = "#clientId")
|
||||
public void updateOauthClientDetailsArchive(String clientId, boolean archive) {
|
||||
final String sql = " update oauth_client_details set archived = ? where client_id = ? ";
|
||||
this.jdbcTemplate.update(sql, archive, clientId);
|
||||
|
|
|
@ -14,8 +14,11 @@ package com.monkeyk.sos.infrastructure.jdbc;
|
|||
import com.monkeyk.sos.domain.user.Privilege;
|
||||
import com.monkeyk.sos.domain.user.User;
|
||||
import com.monkeyk.sos.domain.user.UserRepository;
|
||||
import com.monkeyk.sos.infrastructure.CacheConstants;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
@ -93,6 +96,7 @@ public class UserRepositoryJdbc implements UserRepository {
|
|||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = CacheConstants.USER_CACHE, key = "#user.username()")
|
||||
public void updateUser(final User user) {
|
||||
final String sql = " update user_ set username = ?, password = ?, phone = ?,email = ? where guid = ? ";
|
||||
this.jdbcTemplate.update(sql, ps -> {
|
||||
|
@ -107,6 +111,7 @@ public class UserRepositoryJdbc implements UserRepository {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = CacheConstants.USER_CACHE, key = "#username")
|
||||
public User findByUsername(String username) {
|
||||
final String sql = " select * from user_ where username = ? and archived = 0 ";
|
||||
final List<User> list = this.jdbcTemplate.query(sql, new Object[]{username}, userRowMapper);
|
||||
|
|
Loading…
Reference in New Issue