Class MembershipDAOHibernate
java.lang.Object
com.atlassian.crowd.util.persistence.hibernate.StatelessDao
com.atlassian.crowd.util.persistence.hibernate.HibernateDao<InternalMembership>
com.atlassian.crowd.dao.membership.MembershipDAOHibernate
- All Implemented Interfaces:
InternalMembershipDao
,MembershipDao
public class MembershipDAOHibernate
extends HibernateDao<InternalMembership>
implements MembershipDao, InternalMembershipDao
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
Fields inherited from class com.atlassian.crowd.util.persistence.hibernate.HibernateDao
batchFinder, batchProcessor, logger, statelessSessionBatchProcessor, timeSource
Fields inherited from class com.atlassian.crowd.util.persistence.hibernate.StatelessDao
sessionFactory
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddAll
(Set<InternalMembership> memberships) Bulk add of memberships.addAllGroupsToGroup
(long directoryId, Collection<String> childGroupNames, String groupName) Bulk adds all the given child groups into the given group.addAllUsersToGroup
(long directoryId, Collection<String> userNames, String groupName) Bulk adds all the given users into the given group.void
addGroupToGroup
(long directoryId, String childGroup, String parentGroup) Adds group as a child of the (supposedly) parent group.void
addUserToGroup
(long directoryId, String username, String groupName) Adds user as a member of group.addUserToGroups
(long directoryId, String username, Set<String> groupNames) Bulk adds the given user to all the given groups.countDirectMembersOfGroup
(long directoryId, String groupName, int potentialMaxCount) Count the direct members of a group with a recommended upper bound on the count.findAll
(Collection<Directory> directories) findAllLocal
(Collection<Directory> directories) getMembershipsCreatedAfter
(long directoryId, Date timestamp, int maxResults) Retrieves memberships with the creation timestamp greater than the specified dateAll subclasses of HibernateDao must implement this method forHibernateDao.load(Serializable)
to work correctly.boolean
isGroupDirectMember
(long directoryId, String childGroup, String parentGroup) Determines whether the group is a direct member of the (supposedly) parent group.boolean
isUserDirectMember
(long directoryId, String username, String groupName) Determines whether the user is a direct member of the group.removeAll
(Set<InternalMembership> memberships) void
removeAllRelationships
(long directoryId) Removes all relationships the the given directory identified by directory id.void
removeAllUserRelationships
(long directoryId) Removes all user relationships the the given directory identified by directory id.void
removeGroupFromGroup
(long directoryId, String childGroup, String parentGroup) Removes group from the parent group.void
removeGroupMembers
(long directoryId, String groupName) Removes all members of the given group name.void
removeGroupMemberships
(long directoryId, String groupName) Removes all relationships from parent groups to the given group name.removeGroupsFromGroup
(long directoryId, Collection<String> childGroupNames, String groupName) Bulk remove all the given child groups from the given group.void
removeUserFromGroup
(long directoryId, String username, String groupName) Removes user as a member of the given group.void
removeUserMemberships
(long directoryId, String username) Removes allMembershipType.GROUP_USER
relationships from parent groups to the given username.removeUsersFromGroup
(long directoryId, Collection<String> usernames, String groupName) Bulk remove all the given users into the given group.void
renameGroupRelationships
(long directoryId, String oldName, String newName) Renames group name in all relationships.void
renameUserRelationships
(long directoryId, String oldName, String newName) Renames username in all relationships.<T> List<T>
search
(long directoryId, MembershipQuery<T> query) Search for memberships by the given criteria.searchGroupedByName
(long directoryId, MembershipQuery<T> query) Search for memberships by the given criteria.void
setAuditProcessor
(MembershipAuditProcessor auditProcessor) void
setGroupDao
(InternalGroupDao groupDao) void
setHqlQueryTranslater
(HQLQueryTranslater hqlQueryTranslater) void
setUserDao
(InternalUserDao userDao) Methods inherited from class com.atlassian.crowd.util.persistence.hibernate.HibernateDao
createDeleteQuery, createDeleteQuery, createQuery, createQuery, executeHQLQuery, findAllInternal, findByProperties, findByPropertiesOptional, findByProperty, findByProperty, findByPropertyOptional, findByPropertyOrThrow, getCountByProperties, load, load, loadOptional, loadReference, loadReference, remove, removeByIdIfPresent, save, saveOrUpdate, session, setBatchFinder, setBatchProcessor, setClock, setStatelessSessionBatchProcessor, toPredicates, update
Methods inherited from class com.atlassian.crowd.util.persistence.hibernate.StatelessDao
setSessionFactory, withStatelessSession
-
Field Details
-
DIRECTORY_ID
- See Also:
-
LOWER_PARENT_NAME
- See Also:
-
LOWER_CHILD_NAME
- See Also:
-
MEMBERSHIP_TYPE
- See Also:
-
-
Constructor Details
-
MembershipDAOHibernate
public MembershipDAOHibernate()
-
-
Method Details
-
addAll
Description copied from interface:InternalMembershipDao
Bulk add of memberships.- Specified by:
addAll
in interfaceInternalMembershipDao
- Parameters:
memberships
- Set of memberships.- Returns:
- Batch result.
-
removeAll
-
getMembershipsCreatedAfter
public List<InternalMembership> getMembershipsCreatedAfter(long directoryId, Date timestamp, int maxResults) Description copied from interface:InternalMembershipDao
Retrieves memberships with the creation timestamp greater than the specified date- Specified by:
getMembershipsCreatedAfter
in interfaceInternalMembershipDao
- Parameters:
directoryId
- the id of the directory to searchtimestamp
- the date to limit the search bymaxResults
- the maximum number of results to return- Returns:
-
addAllUsersToGroup
public BatchResult<String> addAllUsersToGroup(long directoryId, Collection<String> userNames, String groupName) throws GroupNotFoundException Description copied from interface:MembershipDao
Bulk adds all the given users into the given group. Users that are already direct members of the group are reported as failures. Usernames that cannot be found in the database are also reported as failures. Implementations must make sure that changes in bulk methods such as this are immediately visible to other bulk methods. For example, if this is run in a transaction, either that transaction must be committed when this method returns, or all other bulk method implementations must guarantee to reuse the same transaction.- Specified by:
addAllUsersToGroup
in interfaceMembershipDao
- Parameters:
directoryId
- the directory to perform the operationuserNames
- the collection of usersgroupName
- name of the group- Returns:
- result containing both successful (membership successfully added) and failed users (unknown username, or already existing membership)
- Throws:
GroupNotFoundException
- if the group does not exist
-
addGroupToGroup
public void addGroupToGroup(long directoryId, String childGroup, String parentGroup) throws GroupNotFoundException, MembershipAlreadyExistsException Description copied from interface:MembershipDao
Adds group as a child of the (supposedly) parent group.- Specified by:
addGroupToGroup
in interfaceMembershipDao
- Parameters:
directoryId
- the directory to perform the operationchildGroup
- the (supposedly) child groupparentGroup
- parent group- Throws:
GroupNotFoundException
- if either child or parent group is not foundMembershipAlreadyExistsException
- if the child group is already a child of the parent group
-
addAllGroupsToGroup
public BatchResult<String> addAllGroupsToGroup(long directoryId, Collection<String> childGroupNames, String groupName) throws GroupNotFoundException Description copied from interface:MembershipDao
Bulk adds all the given child groups into the given group. Child groups that are already direct members of the group are reported as failures. childGroupNames that cannot be found in the database are also reported as failures. Implementations must make sure that changes in bulk methods such as this are immediately visible to other bulk methods. For example, if this is run in a transaction, either that transaction must be committed when this method returns, or all other bulk method implementations must guarantee to reuse the same transaction.- Specified by:
addAllGroupsToGroup
in interfaceMembershipDao
- Parameters:
directoryId
- the directory to perform the operationchildGroupNames
- the collection of child groups to addgroupName
- name of the group- Returns:
- result containing both successful (membership successfully added) and failed groups (unknown childGroupName, or already existing membership)
- Throws:
GroupNotFoundException
- if the group does not exist
-
addUserToGroups
public BatchResult<String> addUserToGroups(long directoryId, String username, Set<String> groupNames) throws UserNotFoundException Description copied from interface:MembershipDao
Bulk adds the given user to all the given groups. Groups that user is already a direct member of are reported as failures. Group names that cannot be found in the database are also reported as failures. Implementations must make sure that changes in bulk methods such as this are immediately visible to other bulk methods. For example, if this is run in a transaction, either that transaction must be committed when this method returns, or all other bulk method implementations must guarantee to reuse the same transaction.- Specified by:
addUserToGroups
in interfaceMembershipDao
- Parameters:
directoryId
- the id of the directory to which user and groups belongusername
- username of the user to whom we add groupsgroupNames
- names of the group to add to a user. The groups need to exist in the directory- Returns:
- result of the bulk operation containing successful and failed entities
- Throws:
UserNotFoundException
- when user with a givenusername
does not exist in the directory withdirectoryId
id
-
addUserToGroup
public void addUserToGroup(long directoryId, String username, String groupName) throws UserNotFoundException, GroupNotFoundException, MembershipAlreadyExistsException Description copied from interface:MembershipDao
Adds user as a member of group.- Specified by:
addUserToGroup
in interfaceMembershipDao
- Parameters:
directoryId
- the directory to perform the operationusername
- usergroupName
- group- Throws:
UserNotFoundException
- if the user does not existGroupNotFoundException
- if the group does not existMembershipAlreadyExistsException
- if the user is already a direct member of the group
-
findAll
- Parameters:
directories
- directories to search for memberships- Returns:
- all memberships across all directories (used for export).
-
findAllLocal
- Parameters:
directories
- directories to search for memberships- Returns:
- all memberships across all directories (used for export).
-
getPersistentClass
Description copied from class:HibernateDao
All subclasses of HibernateDao must implement this method forHibernateDao.load(Serializable)
to work correctly.- Specified by:
getPersistentClass
in classHibernateDao<InternalMembership>
- Returns:
- the entity class for this DAO
-
isGroupDirectMember
Description copied from interface:MembershipDao
Determines whether the group is a direct member of the (supposedly) parent group.- Specified by:
isGroupDirectMember
in interfaceMembershipDao
- Parameters:
directoryId
- the directory to perform the operationchildGroup
- child groupparentGroup
- parent group- Returns:
- true if the group is a direct member of the (supposedly) parent group
-
isUserDirectMember
Description copied from interface:MembershipDao
Determines whether the user is a direct member of the group.- Specified by:
isUserDirectMember
in interfaceMembershipDao
- Parameters:
directoryId
- the directory to perform the operationusername
- usergroupName
- group- Returns:
- true if the user is a direct member of the group
-
removeAllRelationships
public void removeAllRelationships(long directoryId) Description copied from interface:InternalMembershipDao
Removes all relationships the the given directory identified by directory id.- Specified by:
removeAllRelationships
in interfaceInternalMembershipDao
- Parameters:
directoryId
- Directory id.
-
removeAllUserRelationships
public void removeAllUserRelationships(long directoryId) Description copied from interface:InternalMembershipDao
Removes all user relationships the the given directory identified by directory id.- Specified by:
removeAllUserRelationships
in interfaceInternalMembershipDao
- Parameters:
directoryId
- Directory id.
-
removeGroupFromGroup
public void removeGroupFromGroup(long directoryId, String childGroup, String parentGroup) throws MembershipNotFoundException Description copied from interface:MembershipDao
Removes group from the parent group.- Specified by:
removeGroupFromGroup
in interfaceMembershipDao
- Parameters:
directoryId
- the directory to perform the operationchildGroup
- child groupparentGroup
- parent group- Throws:
MembershipNotFoundException
- if the membership relationship between the child and parent group does not exist
-
removeGroupsFromGroup
public BatchResult<String> removeGroupsFromGroup(long directoryId, Collection<String> childGroupNames, String groupName) throws GroupNotFoundException Description copied from interface:MembershipDao
Bulk remove all the given child groups from the given group. Child groups that are not direct members of the group are reported as failures. childGroupNames that cannot be found in the database are also reported as failures. Implementations must make sure that changes in bulk methods such as this are immediately visible to other bulk methods. For example, if this is run in a transaction, either that transaction must be committed when this method returns, or all other bulk method implementations must guarantee to reuse the same transaction.- Specified by:
removeGroupsFromGroup
in interfaceMembershipDao
- Parameters:
directoryId
- the directory to perform the operationchildGroupNames
- the collection of child groupsgroupName
- name of the parent group- Returns:
- result containing both successful (membership successfully removed) and failed groups (unknown childGroupName, or no existing membership)
- Throws:
GroupNotFoundException
- if the parent group does not exist
-
removeGroupMembers
Description copied from interface:InternalMembershipDao
Removes all members of the given group name.- Specified by:
removeGroupMembers
in interfaceInternalMembershipDao
- Parameters:
directoryId
- Directory id.groupName
- Group name.
-
removeGroupMemberships
Description copied from interface:InternalMembershipDao
Removes all relationships from parent groups to the given group name.- Specified by:
removeGroupMemberships
in interfaceInternalMembershipDao
- Parameters:
directoryId
- Directory id.groupName
- Group name.
-
removeUserFromGroup
public void removeUserFromGroup(long directoryId, String username, String groupName) throws UserNotFoundException, GroupNotFoundException, MembershipNotFoundException Description copied from interface:MembershipDao
Removes user as a member of the given group.- Specified by:
removeUserFromGroup
in interfaceMembershipDao
- Parameters:
directoryId
- the directory to perform the operationusername
- usergroupName
- group- Throws:
UserNotFoundException
- if the user does not existGroupNotFoundException
- if the group does not existMembershipNotFoundException
- if the user is not a member of the said group
-
removeUsersFromGroup
public BatchResult<String> removeUsersFromGroup(long directoryId, Collection<String> usernames, String groupName) throws GroupNotFoundException Description copied from interface:MembershipDao
Bulk remove all the given users into the given group. Users that are not direct members of the group are reported as failures. Usernames that cannot be found in the database are also reported as failures. Implementations must make sure that changes in bulk methods such as this are immediately visible to other bulk methods. For example, if this is run in a transaction, either that transaction must be committed when this method returns, or all other bulk method implementations must guarantee to reuse the same transaction.- Specified by:
removeUsersFromGroup
in interfaceMembershipDao
- Parameters:
directoryId
- the directory to perform the operationusernames
- the collection of usersgroupName
- name of the group- Returns:
- result containing both successful (membership successfully removed) and failed users (unknown username, or no existing membership)
- Throws:
GroupNotFoundException
- if the group does not exist
-
removeUserMemberships
Description copied from interface:InternalMembershipDao
Removes allMembershipType.GROUP_USER
relationships from parent groups to the given username.- Specified by:
removeUserMemberships
in interfaceInternalMembershipDao
- Parameters:
directoryId
- Directory id.username
- Username.
-
renameGroupRelationships
Description copied from interface:InternalMembershipDao
Renames group name in all relationships.- Specified by:
renameGroupRelationships
in interfaceInternalMembershipDao
- Parameters:
directoryId
- Directory id.oldName
- Old group name.newName
- New group name.
-
renameUserRelationships
Description copied from interface:InternalMembershipDao
Renames username in all relationships.- Specified by:
renameUserRelationships
in interfaceInternalMembershipDao
- Parameters:
directoryId
- Directory id.oldName
- Old username.newName
- New username.
-
countDirectMembersOfGroup
public BoundedCount countDirectMembersOfGroup(long directoryId, String groupName, int potentialMaxCount) Description copied from interface:MembershipDao
Count the direct members of a group with a recommended upper bound on the count.
The upper bound is there so that, in directories that do not support efficient counting of memberships, less work may be performed.
Important: Please note that any directory wishing to implement this method should make it as efficient as possible. Such that an administrator could land on a page that showed ~20 groups, run this method once per group, and it would still return results as efficiently as possible.
- Specified by:
countDirectMembersOfGroup
in interfaceMembershipDao
- Parameters:
directoryId
- the directory to perform the operationgroupName
- the name of the group to search forpotentialMaxCount
- a suggested minimum number of elements for the implementation to count. The implementation will only use this number if it can get efficiency benefits; otherwise this number may be ignored.- Returns:
- A bounded count of the number of memberships in the given group for the provided directory. If the group does not exist
then
BoundedCount.exactly(long)
0 will be returned.
-
search
Description copied from interface:MembershipDao
Search for memberships by the given criteria.- Specified by:
search
in interfaceMembershipDao
- Parameters:
directoryId
- the directory to perform the operationquery
- criteria- Returns:
- List (can be empty but never null) of memberships which match the given criteria. Results are ordered by entity name, case-insensitive.
-
searchGroupedByName
Description copied from interface:MembershipDao
Search for memberships by the given criteria. Groups results byMembershipQuery.getEntityNamesToMatch()
.- Specified by:
searchGroupedByName
in interfaceMembershipDao
- Parameters:
directoryId
- the directory to perform the operationquery
- criteria- Returns:
- List (can be empty but never null) of memberships which match the given criteria. Results are ordered by entity name, case-insensitive.
-
setGroupDao
-
setHqlQueryTranslater
-
setUserDao
-
setAuditProcessor
@Autowired public void setAuditProcessor(@Qualifier("membershipAuditProcessor") MembershipAuditProcessor auditProcessor)
-