mirror of
https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
synced 2025-10-29 08:05:04 +08:00
fixed issue 'returned null for key'
This commit is contained in:
@@ -43,7 +43,8 @@ public class TableUser extends SQLCore {
|
|||||||
|
|
||||||
public static User getByWechat(String wechat) {
|
public static User getByWechat(String wechat) {
|
||||||
try {
|
try {
|
||||||
return cache.get(wechat);
|
User u = cache.get(wechat);
|
||||||
|
return u == NULL_USER ? null : u;
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
@@ -55,6 +56,7 @@ public class TableUser extends SQLCore {
|
|||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
s.update(user);
|
s.update(user);
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
|
cache.put(user.getWechatId(), user);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,10 +78,13 @@ public class TableUser extends SQLCore {
|
|||||||
private static class ValueLoader extends CacheLoader<String, User> {
|
private static class ValueLoader extends CacheLoader<String, User> {
|
||||||
@Override
|
@Override
|
||||||
public User load(String key) throws Exception {
|
public User load(String key) throws Exception {
|
||||||
return TableUser.getByWechat0(key);
|
User u = TableUser.getByWechat0(key);
|
||||||
|
return u == null ? NULL_USER : u;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final User NULL_USER = new User();
|
||||||
|
|
||||||
private static User getByWechat0(String wechat) {
|
private static User getByWechat0(String wechat) {
|
||||||
try (Session s = sf.openSession()) {
|
try (Session s = sf.openSession()) {
|
||||||
return (User) s.createCriteria(User.class).add(Restrictions.eq(User.PROPERTY_WECHAT, wechat)).uniqueResult();
|
return (User) s.createCriteria(User.class).add(Restrictions.eq(User.PROPERTY_WECHAT, wechat)).uniqueResult();
|
||||||
|
|||||||
Reference in New Issue
Block a user