Class GroupsUpdate
- java.lang.Object
-
- com.google.gerrit.server.group.GroupsUpdate
-
public class GroupsUpdate extends Object
A database accessor for write calls related to groups.All calls which write group related details to the database (either ReviewDb or NoteDb) are gathered here. Other classes should always use this class instead of accessing the database directly. There are a few exceptions though: schema classes, wrapper classes, and classes executed during init. The latter ones should use
GroupsOnInit
instead.If not explicitly stated, all methods of this class refer to internal groups.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
GroupsUpdate.Factory
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addGroup(ReviewDb db, AccountGroup group, Set<Account.Id> memberIds)
Adds/Creates the specified group for the specified members (accounts).void
addGroupMember(ReviewDb db, AccountGroup.UUID groupUuid, Account.Id accountId)
Adds an account as member to a group.void
addGroupMembers(ReviewDb db, AccountGroup.UUID groupUuid, Set<Account.Id> accountIds)
Adds several accounts as members to a group.static void
addNewGroup(ReviewDb db, AccountGroup group)
Adds the specified group.void
addSubgroups(ReviewDb db, AccountGroup.UUID parentGroupUuid, Set<AccountGroup.UUID> subgroupUuids)
Adds several groups as subgroups to a group.void
removeGroupMembers(ReviewDb db, AccountGroup.UUID groupUuid, Set<Account.Id> accountIds)
Removes several members (accounts) from a group.void
removeSubgroups(ReviewDb db, AccountGroup.UUID parentGroupUuid, Set<AccountGroup.UUID> subgroupUuids)
Removes several subgroups from a parent group.void
renameGroup(ReviewDb db, AccountGroup.UUID groupUuid, AccountGroup.NameKey newName)
Renames the specified group.void
updateGroup(ReviewDb db, AccountGroup.UUID groupUuid, Consumer<AccountGroup> groupConsumer)
Updates the specified group.AccountGroup
updateGroupInDb(ReviewDb db, AccountGroup.UUID groupUuid, Consumer<AccountGroup> groupConsumer)
-
-
-
Method Detail
-
addGroup
public void addGroup(ReviewDb db, AccountGroup group, Set<Account.Id> memberIds) throws com.google.gwtorm.server.OrmException, IOException
Adds/Creates the specified group for the specified members (accounts).- Parameters:
db
- theReviewDb
instance to updategroup
- the group to addmemberIds
- the IDs of the accounts which should be members of the created group- Throws:
com.google.gwtorm.server.OrmException
- if an error occurs while reading/writing from/to ReviewDbIOException
- if the cache entry of one of the new members couldn't be invalidated, or the new group couldn't be indexed
-
addNewGroup
public static void addNewGroup(ReviewDb db, AccountGroup group) throws com.google.gwtorm.server.OrmException
Adds the specified group.Note: This method doesn't update the index! It just adds the group to the database. Use this method with care.
- Parameters:
db
- theReviewDb
instance to updategroup
- the group to add- Throws:
com.google.gwtorm.server.OrmException
- if an error occurs while reading/writing from/to ReviewDb
-
updateGroup
public void updateGroup(ReviewDb db, AccountGroup.UUID groupUuid, Consumer<AccountGroup> groupConsumer) throws com.google.gwtorm.server.OrmException, IOException, NoSuchGroupException
Updates the specified group.- Parameters:
db
- theReviewDb
instance to updategroupUuid
- the UUID of the group to updategroupConsumer
- aConsumer
which performs the desired updates on the group- Throws:
com.google.gwtorm.server.OrmException
- if an error occurs while reading/writing from/to ReviewDbIOException
- if the cache entry for the group couldn't be invalidatedNoSuchGroupException
- if the specified group doesn't exist
-
updateGroupInDb
public AccountGroup updateGroupInDb(ReviewDb db, AccountGroup.UUID groupUuid, Consumer<AccountGroup> groupConsumer) throws com.google.gwtorm.server.OrmException, NoSuchGroupException
- Throws:
com.google.gwtorm.server.OrmException
NoSuchGroupException
-
renameGroup
public void renameGroup(ReviewDb db, AccountGroup.UUID groupUuid, AccountGroup.NameKey newName) throws com.google.gwtorm.server.OrmException, IOException, NameAlreadyUsedException, NoSuchGroupException
Renames the specified group.- Parameters:
db
- theReviewDb
instance to updategroupUuid
- the UUID of the group to renamenewName
- the new name of the group- Throws:
com.google.gwtorm.server.OrmException
- if an error occurs while reading/writing from/to ReviewDbIOException
- if the cache entry for the group couldn't be invalidatedNoSuchGroupException
- if the specified group doesn't existNameAlreadyUsedException
- if another group has the namenewName
-
addGroupMember
public void addGroupMember(ReviewDb db, AccountGroup.UUID groupUuid, Account.Id accountId) throws com.google.gwtorm.server.OrmException, IOException, NoSuchGroupException
Adds an account as member to a group. The account is only added as a new member if it isn't already a member of the group.Note: This method doesn't check whether the account exists!
- Parameters:
db
- theReviewDb
instance to updategroupUuid
- the UUID of the groupaccountId
- the ID of the account to add- Throws:
com.google.gwtorm.server.OrmException
- if an error occurs while reading/writing from/to ReviewDbIOException
- if the cache entry of the new member couldn't be invalidatedNoSuchGroupException
- if the specified group doesn't exist
-
addGroupMembers
public void addGroupMembers(ReviewDb db, AccountGroup.UUID groupUuid, Set<Account.Id> accountIds) throws com.google.gwtorm.server.OrmException, IOException, NoSuchGroupException
Adds several accounts as members to a group. Only accounts which currently aren't members of the group are added.Note: This method doesn't check whether the accounts exist!
- Parameters:
db
- theReviewDb
instance to updategroupUuid
- the UUID of the groupaccountIds
- a set of IDs of accounts to add- Throws:
com.google.gwtorm.server.OrmException
- if an error occurs while reading/writing from/to ReviewDbIOException
- if the group or one of the new members couldn't be indexedNoSuchGroupException
- if the specified group doesn't exist
-
removeGroupMembers
public void removeGroupMembers(ReviewDb db, AccountGroup.UUID groupUuid, Set<Account.Id> accountIds) throws com.google.gwtorm.server.OrmException, IOException, NoSuchGroupException
Removes several members (accounts) from a group. Only accounts which currently are members of the group are removed.- Parameters:
db
- theReviewDb
instance to updategroupUuid
- the UUID of the groupaccountIds
- a set of IDs of accounts to remove- Throws:
com.google.gwtorm.server.OrmException
- if an error occurs while reading/writing from/to ReviewDbIOException
- if the group or one of the removed members couldn't be indexedNoSuchGroupException
- if the specified group doesn't exist
-
addSubgroups
public void addSubgroups(ReviewDb db, AccountGroup.UUID parentGroupUuid, Set<AccountGroup.UUID> subgroupUuids) throws com.google.gwtorm.server.OrmException, NoSuchGroupException, IOException
Adds several groups as subgroups to a group. Only groups which currently aren't subgroups of the group are added.The parent group must be an internal group whereas the subgroups can either be internal or external groups.
Note: This method doesn't check whether the subgroups exist!
- Parameters:
db
- theReviewDb
instance to updateparentGroupUuid
- the UUID of the parent groupsubgroupUuids
- a set of IDs of the groups to add as subgroups- Throws:
com.google.gwtorm.server.OrmException
- if an error occurs while reading/writing from/to ReviewDbIOException
- if the parent group couldn't be indexedNoSuchGroupException
- if the specified parent group doesn't exist
-
removeSubgroups
public void removeSubgroups(ReviewDb db, AccountGroup.UUID parentGroupUuid, Set<AccountGroup.UUID> subgroupUuids) throws com.google.gwtorm.server.OrmException, NoSuchGroupException, IOException
Removes several subgroups from a parent group. Only groups which currently are subgroups of the group are removed.The parent group must be an internal group whereas the subgroups can either be internal or external groups.
- Parameters:
db
- theReviewDb
instance to updateparentGroupUuid
- the UUID of the parent groupsubgroupUuids
- a set of IDs of the subgroups to remove from the parent group- Throws:
com.google.gwtorm.server.OrmException
- if an error occurs while reading/writing from/to ReviewDbIOException
- if the parent group couldn't be indexedNoSuchGroupException
- if the specified parent group doesn't exist
-
-