@Override public void createUserSession(UserSessionModel userSession, boolean offline) { PersistentUserSessionAdapter adapter = new PersistentUserSessionAdapter(userSession); PersistentUserSessionModel model = adapter.getUpdatedModel(); PersistentUserSessionEntity entity = new PersistentUserSessionEntity(); entity.setUserSessionId(model.getUserSessionId()); entity.setCreatedOn(model.getStarted()); entity.setRealmId(adapter.getRealm().getId()); entity.setUserId(adapter.getUser().getId()); String offlineStr = offlineToString(offline); entity.setOffline(offlineStr); entity.setLastSessionRefresh(model.getLastSessionRefresh()); entity.setData(model.getData()); em.persist(entity); em.flush(); }
@Override public void createUserSession(UserSessionModel userSession, boolean offline) { PersistentUserSessionAdapter adapter = new PersistentUserSessionAdapter(userSession); PersistentUserSessionModel model = adapter.getUpdatedModel(); MongoUserSessionEntity entity = offline ? new MongoOfflineUserSessionEntity() : new MongoOnlineUserSessionEntity(); entity.setId(model.getUserSessionId()); entity.setRealmId(adapter.getRealm().getId()); entity.setUserId(adapter.getUser().getId()); entity.setLastSessionRefresh(model.getLastSessionRefresh()); entity.setData(model.getData()); entity.setClientSessions(new ArrayList<PersistentClientSessionEntity>()); getMongoStore().insertEntity(entity, invocationContext); }
@Override public void updateUserSession(UserSessionModel userSession, boolean offline) { PersistentUserSessionAdapter adapter; if (userSession instanceof PersistentUserSessionAdapter) { adapter = (PersistentUserSessionAdapter) userSession; } else { adapter = new PersistentUserSessionAdapter(userSession); } PersistentUserSessionModel model = adapter.getUpdatedModel(); MongoUserSessionEntity entity = loadUserSession(model.getUserSessionId(), offline); if (entity == null) { throw new ModelException("UserSession with ID " + userSession.getId() + ", offline: " + offline + " not found"); } entity.setLastSessionRefresh(model.getLastSessionRefresh()); entity.setData(model.getData()); getMongoStore().updateEntity(entity, invocationContext); }