protected List<UserSessionModel> getUserSessions(RealmModel realm, ClientModel client, int firstResult, int maxResults, boolean offline) { Cache<String, SessionEntity> cache = getCache(offline);
private void onClientRemoved(RealmModel realm, ClientModel client, boolean offline) { Cache<String, SessionEntity> cache = getCache(offline); Map<String, ClientSessionEntity> map = new MapReduceTask(cache) .mappedWith(ClientSessionMapper.create(realm.getId()).client(client.getId())) .reducedWith(new FirstResultReducer()) .execute(); for (Map.Entry<String, ClientSessionEntity> entry : map.entrySet()) { // detach from userSession ClientSessionAdapter adapter = wrap(realm, entry.getValue(), offline); adapter.setUserSession(null); tx.remove(cache, entry.getKey()); } }
protected void removeUserSessions(RealmModel realm, boolean offline) { Cache<String, SessionEntity> cache = getCache(offline); Map<String, String> ids = new MapReduceTask(cache) .mappedWith(SessionMapper.create(realm.getId()).emitKey()) .reducedWith(new FirstResultReducer()) .execute(); for (String id : ids.keySet()) { cache.remove(id); } }
protected void removeClientSession(RealmModel realm, ClientSessionModel clientSession, boolean offline) { Cache<String, SessionEntity> cache = getCache(offline); UserSessionModel userSession = clientSession.getUserSession(); if (userSession != null) { UserSessionEntity entity = ((UserSessionAdapter) userSession).getEntity(); if (entity.getClientSessions() != null) { entity.getClientSessions().remove(clientSession.getId()); } tx.replace(cache, entity.getId(), entity); } tx.remove(cache, clientSession.getId()); }
protected long getUserSessionsCount(RealmModel realm, ClientModel client, boolean offline) { Cache<String, SessionEntity> cache = getCache(offline); Map map = new MapReduceTask(cache) .mappedWith(ClientSessionMapper.create(realm.getId()).client(client.getId()).emitUserSessionAndTimestamp()) .reducedWith(new LargestResultReducer()).execute(); return map.size(); }
protected void removeUserSessions(RealmModel realm, UserModel user, boolean offline) { Cache<String, SessionEntity> cache = getCache(offline); Map<String, String> sessions = new MapReduceTask(cache) .mappedWith(UserSessionMapper.create(realm.getId()).user(user.getId()).emitKey()) .reducedWith(new FirstResultReducer()) .execute(); for (String id : sessions.keySet()) { removeUserSession(realm, id, offline); } }
protected void removeUserSession(RealmModel realm, String userSessionId, boolean offline) { Cache<String, SessionEntity> cache = getCache(offline); tx.remove(cache, userSessionId); // TODO: Isn't more effective to retrieve from userSessionEntity directly? Map<String, String> map = new MapReduceTask(cache) .mappedWith(ClientSessionMapper.create(realm.getId()).userSession(userSessionId).emitKey()) .reducedWith(new FirstResultReducer()) .execute(); for (String id : map.keySet()) { tx.remove(cache, id); } }