Index: kernel-impl/src/test/java/org/sakai/memory/impl/test/MockUsageSessionService.java =================================================================== --- kernel-impl/src/test/java/org/sakai/memory/impl/test/MockUsageSessionService.java (revision 77500) +++ kernel-impl/src/test/java/org/sakai/memory/impl/test/MockUsageSessionService.java (working copy) @@ -206,5 +206,10 @@ // TODO Auto-generated method stub return false; } + + public List getActiveUsers(List userIds) { + // TODO Auto-generated method stub + return null; + } } Index: kernel-impl/src/main/java/org/sakaiproject/event/impl/UsageSessionServiceAdaptor.java =================================================================== --- kernel-impl/src/main/java/org/sakaiproject/event/impl/UsageSessionServiceAdaptor.java (revision 77500) +++ kernel-impl/src/main/java/org/sakaiproject/event/impl/UsageSessionServiceAdaptor.java (working copy) @@ -1055,6 +1055,36 @@ } /** + * Get the list of users with active Sakai sessions, given the supplied list of userIds. + * @param userIds userIds to check + * @return List of userIds that have active Sakai sessions + */ + @SuppressWarnings("unchecked") + public List getActiveUsers(List userIds) { + + String statement = usageSessionServiceSql.getUsersWithOpenSakaiSessionsSql(userIds); + if (M_log.isDebugEnabled()) { + M_log.debug("will get users with active sessions with SQL=" + statement); + } + + + List results = sqlService().dbRead(statement, null, new SqlReader() { + public Object readSqlResultRecord(ResultSet result) { + try { + return result.getString(1); + } + catch (SQLException e) { + M_log.error("getActiveUsers: failed: " + e); + return null; + } + } + }); + + return results; + } + + + /** * Get the most recent Sakai session that is active, for a given user * @param userId userId to check * @return most recent UsageSession or null if none Index: kernel-impl/src/main/java/org/sakaiproject/event/impl/UsageSessionServiceSql.java =================================================================== --- kernel-impl/src/main/java/org/sakaiproject/event/impl/UsageSessionServiceSql.java (revision 77500) +++ kernel-impl/src/main/java/org/sakaiproject/event/impl/UsageSessionServiceSql.java (working copy) @@ -74,6 +74,11 @@ String getCountOpenSakaiSessionsForUserSql(); /** + * @return the SQL statement which gets the list of users with active session, from the supplied list + */ + String getUsersWithOpenSakaiSessionsSql(List userIds); + + /** * @return the SQL statement which retrieves the most recent active sakai session for each of the given userIds */ String getMostRecentOpenSakaiSessionForMultipleUsersSql(List userIds); Index: kernel-impl/src/main/java/org/sakaiproject/event/impl/UsageSessionServiceSqlDefault.java =================================================================== --- kernel-impl/src/main/java/org/sakaiproject/event/impl/UsageSessionServiceSqlDefault.java (revision 77500) +++ kernel-impl/src/main/java/org/sakaiproject/event/impl/UsageSessionServiceSqlDefault.java (working copy) @@ -109,8 +109,26 @@ public String getCountOpenSakaiSessionsForUserSql() { return "select count(SESSION_ID) from SAKAI_SESSION where SESSION_ACTIVE=1 and SESSION_USER=?"; } - + /** + * @return the SQL statement which gets the list of users with active session, from the supplied list + */ + public String getUsersWithOpenSakaiSessionsSql(List userIds) { + + StringBuilder sql = new StringBuilder("select SESSION_USER from SAKAI_SESSION where SESSION_ACTIVE=1 and SESSION_USER in ("); + for (int i = 0; i < userIds.size(); i++) + { + String userId = userIds.get(i); + if (i > 0) sql.append(","); + sql.append("'").append(userId).append("'"); + } + sql.append(")"); + sql.append(" GROUP BY SESSION_USER"); + + return sql.toString(); + } + + /** * @return the SQL statement which retrieves the most recent active sakai session for the given userIds */ public String getMostRecentOpenSakaiSessionForMultipleUsersSql(List userIds) { Index: api/src/main/java/org/sakaiproject/event/api/UsageSessionService.java =================================================================== --- api/src/main/java/org/sakaiproject/event/api/UsageSessionService.java (revision 77500) +++ api/src/main/java/org/sakaiproject/event/api/UsageSessionService.java (working copy) @@ -220,6 +220,13 @@ public boolean isUserActive(String userId); /** + * Get the list of users with active Sakai sessions, given the supplied list of userIds. + * @param userIds userIds to check + * @return List of userIds that have active Sakai sessions + */ + public List getActiveUsers(List userIds); + + /** * Get the most recent Sakai session that is active, for a given user * @param userId userId to check * @return most recent UsageSession or null if none