@Test public void testLoadRolesByUserIds() { Map<Long, List<Role>> roles = roleDao.loadRolesByUserIds(Collections.singletonList(user.getId())); assertEquals(3, roles.get(user.getId()).size()); }
public Map<Long, List<Role>> loadRolesByUserIds(List<Long> userIds) { String query = DaoHelper.replaceInClause(loadRolesByUserIdsQuery, userIds.size()); Map<Long, List<Role>> result = new HashMap<>(); RowMapper<Role> rowMapper = RoleParameters.getRowMapper(); getNamedParameterJdbcTemplate().query(query, new MapSqlParameterSource(LIST_PARAM, userIds), rs -> { Role role = rowMapper.mapRow(rs, 0); result.merge( rs.getLong(UserDao.UserParameters.USER_ID.name()), new ArrayList<>(Collections.singletonList(role)), (l1, l2) -> { l1.addAll(l2); return l1; } ); }); return result; }
RoleDao extends NamedParameterJdbcDaoSupport { public Map<Long, List<Role>> loadRolesByUserIds(List<Long> userIds) { String query = DaoHelper.replaceInClause(loadRolesByUserIdsQuery, userIds.size()); Map<Long, List<Role>> result = new HashMap<>(); RowMapper<Role> rowMapper = RoleParameters.getRowMapper(); getNamedParameterJdbcTemplate().query(query, new MapSqlParameterSource(LIST_PARAM, userIds), rs -> { Role role = rowMapper.mapRow(rs, 0); result.merge( rs.getLong(UserDao.UserParameters.USER_ID.name()), new ArrayList<>(Collections.singletonList(role)), (l1, l2) -> { l1.addAll(l2); return l1; } ); }); return result; } }
RoleDao extends NamedParameterJdbcDaoSupport { public Map<Long, List<Role>> loadRolesByUserIds(List<Long> userIds) { String query = DaoHelper.replaceInClause(loadRolesByUserIdsQuery, userIds.size()); Map<Long, List<Role>> result = new HashMap<>(); RowMapper<Role> rowMapper = RoleParameters.getRowMapper(); getNamedParameterJdbcTemplate().query(query, new MapSqlParameterSource(LIST_PARAM, userIds), rs -> { Role role = rowMapper.mapRow(rs, 0); result.merge( rs.getLong(UserDao.UserParameters.USER_ID.name()), new ArrayList<>(Collections.singletonList(role)), (l1, l2) -> { l1.addAll(l2); return l1; } ); }); return result; }  }
RoleDao extends NamedParameterJdbcDaoSupport { public Map<Long, List<Role>> loadRolesByUserIds(List<Long> userIds) { String query = DaoHelper.replaceInClause(loadRolesByUserIdsQuery, userIds.size()); Map<Long, List<Role>> result = new HashMap<>(); RowMapper<Role> rowMapper = RoleParameters.getRowMapper(); getNamedParameterJdbcTemplate().query(query, new MapSqlParameterSource(LIST_PARAM, userIds), rs -> { Role role = rowMapper.mapRow(rs, 0); result.merge( rs.getLong(UserDao.UserParameters.USER_ID.name()), new ArrayList<>(Collections.singletonList(role)), (l1, l2) -> { l1.addAll(l2); return l1; } ); }); return result; }  @Transactional(propagation = Propagation.MANDATORY) Role createRole(String name); @Transactional(propagation = Propagation.MANDATORY) Role createRole(String name, boolean predefined, boolean userDefault); @Transactional(propagation = Propagation.MANDATORY) void updateRole(Role role); @Transactional(propagation = Propagation.MANDATORY) void deleteRole(Long id); @Transactional(propagation = Propagation.MANDATORY) void deleteRoleReferences(Long id); List<Role> loadRoles(List<Long> roleIds); List<Role> loadAllRoles(boolean loadUsers); List<Role> loadAllRoles(); Map<Long, List<Role>> loadRolesByUserIds(List<Long> userIds); Optional<Role> loadRole(Long id); Optional<Role> loadRoleByName(String name); List<Role> loadDefaultRoles(); ExtendedRole loadExtendedRole(Long roleId); @Required void setLoadRolesByUserIdsQuery(String loadRolesByUserIdsQuery); @Required void setRoleSequence(String roleSequence); @Required void setCreateRoleQuery(String createRoleQuery); @Required void setUpdateRoleQuery(String updateRoleQuery); @Required void setDeleteRoleQuery(String deleteRoleQuery); @Required void setLoadAllRolesQuery(String loadAllRolesQuery); @Required void setLoadRolesQuery(String loadRolesQuery); @Required void setLoadRoleQuery(String loadRoleQuery); @Required void setLoadRoleByNameQuery(String loadRoleByNameQuery); @Required void setDeleteRolesReferencesQuery(String deleteRolesReferencesQuery); @Required void setLoadDefaultRolesQuery(String loadDefaultRolesQuery); @Required void setLoadRoleWithUsersQuery(String loadRoleWithUsersQuery); @Required void setLoadRolesWithUsersQuery(String loadRolesWithUsersQuery); }
RoleDao extends NamedParameterJdbcDaoSupport { public Map<Long, List<Role>> loadRolesByUserIds(List<Long> userIds) { String query = DaoHelper.replaceInClause(loadRolesByUserIdsQuery, userIds.size()); Map<Long, List<Role>> result = new HashMap<>(); RowMapper<Role> rowMapper = RoleParameters.getRowMapper(); getNamedParameterJdbcTemplate().query(query, new MapSqlParameterSource(LIST_PARAM, userIds), rs -> { Role role = rowMapper.mapRow(rs, 0); result.merge( rs.getLong(UserDao.UserParameters.USER_ID.name()), new ArrayList<>(Collections.singletonList(role)), (l1, l2) -> { l1.addAll(l2); return l1; } ); }); return result; }  @Transactional(propagation = Propagation.MANDATORY) Role createRole(String name); @Transactional(propagation = Propagation.MANDATORY) Role createRole(String name, boolean predefined, boolean userDefault); @Transactional(propagation = Propagation.MANDATORY) void updateRole(Role role); @Transactional(propagation = Propagation.MANDATORY) void deleteRole(Long id); @Transactional(propagation = Propagation.MANDATORY) void deleteRoleReferences(Long id); List<Role> loadRoles(List<Long> roleIds); List<Role> loadAllRoles(boolean loadUsers); List<Role> loadAllRoles(); Map<Long, List<Role>> loadRolesByUserIds(List<Long> userIds); Optional<Role> loadRole(Long id); Optional<Role> loadRoleByName(String name); List<Role> loadDefaultRoles(); ExtendedRole loadExtendedRole(Long roleId); @Required void setLoadRolesByUserIdsQuery(String loadRolesByUserIdsQuery); @Required void setRoleSequence(String roleSequence); @Required void setCreateRoleQuery(String createRoleQuery); @Required void setUpdateRoleQuery(String updateRoleQuery); @Required void setDeleteRoleQuery(String deleteRoleQuery); @Required void setLoadAllRolesQuery(String loadAllRolesQuery); @Required void setLoadRolesQuery(String loadRolesQuery); @Required void setLoadRoleQuery(String loadRoleQuery); @Required void setLoadRoleByNameQuery(String loadRoleByNameQuery); @Required void setDeleteRolesReferencesQuery(String deleteRolesReferencesQuery); @Required void setLoadDefaultRolesQuery(String loadDefaultRolesQuery); @Required void setLoadRoleWithUsersQuery(String loadRoleWithUsersQuery); @Required void setLoadRolesWithUsersQuery(String loadRolesWithUsersQuery);  }