GroupBundle.Factory#fromReviewDb: Require UUID as input instead of ID
This will make it easier to use this method from the schema migration
that implements the migration of Gerrit groups to NoteDb.
Change-Id: Ic15d54c240998796bb5e8ad91a8b8144674c8af0
Signed-off-by: Edwin Kempin <ekempin@google.com>
diff --git a/java/com/google/gerrit/server/group/db/GroupBundle.java b/java/com/google/gerrit/server/group/db/GroupBundle.java
index 2710ccb..6480dad 100644
--- a/java/com/google/gerrit/server/group/db/GroupBundle.java
+++ b/java/com/google/gerrit/server/group/db/GroupBundle.java
@@ -154,10 +154,11 @@
auditLogReader.getSubgroupsAudit(repo, uuid));
}
- public static GroupBundle fromReviewDb(ReviewDb db, AccountGroup.Id groupId)
+ public static GroupBundle fromReviewDb(ReviewDb db, AccountGroup.UUID groupUuid)
throws OrmException {
JdbcSchema jdbcSchema = ReviewDbWrapper.unwrapJbdcSchema(db);
- AccountGroup group = readAccountGroupFromReviewDb(jdbcSchema, groupId);
+ AccountGroup group = readAccountGroupFromReviewDb(jdbcSchema, groupUuid);
+ AccountGroup.Id groupId = group.getId();
return create(
Source.REVIEW_DB,
@@ -169,25 +170,25 @@
}
private static AccountGroup readAccountGroupFromReviewDb(
- JdbcSchema jdbcSchema, AccountGroup.Id groupId) throws OrmException {
+ JdbcSchema jdbcSchema, AccountGroup.UUID groupUuid) throws OrmException {
try (Statement stmt = jdbcSchema.getConnection().createStatement();
ResultSet rs =
stmt.executeQuery(
- "SELECT group_uuid,"
+ "SELECT group_id,"
+ " name,"
+ " created_on,"
+ " description,"
+ " owner_group_uuid,"
+ " visible_to_all"
+ " FROM account_groups"
- + " WHERE group_id = '"
- + groupId.get()
+ + " WHERE group_uuid = '"
+ + groupUuid.get()
+ "'")) {
if (!rs.next()) {
- throw new OrmException(String.format("Group %s not found", groupId));
+ throw new OrmException(String.format("Group %s not found", groupUuid));
}
- AccountGroup.UUID groupUuid = new AccountGroup.UUID(rs.getString(1));
+ AccountGroup.Id groupId = new AccountGroup.Id(rs.getInt(1));
AccountGroup.NameKey groupName = new AccountGroup.NameKey(rs.getString(2));
Timestamp createdOn = rs.getTimestamp(3);
String description = rs.getString(4);
@@ -206,7 +207,7 @@
return group;
} catch (SQLException e) {
throw new OrmException(
- String.format("Failed to read account group %s from ReviewDb", groupId.get()), e);
+ String.format("Failed to read account group %s from ReviewDb", groupUuid.get()), e);
}
}
diff --git a/javatests/com/google/gerrit/acceptance/api/group/GroupRebuilderIT.java b/javatests/com/google/gerrit/acceptance/api/group/GroupRebuilderIT.java
index 57225a8..1477428 100644
--- a/javatests/com/google/gerrit/acceptance/api/group/GroupRebuilderIT.java
+++ b/javatests/com/google/gerrit/acceptance/api/group/GroupRebuilderIT.java
@@ -86,7 +86,7 @@
public void basicGroupProperties() throws Exception {
GroupInfo createdGroup = gApi.groups().create(name("group")).get();
GroupBundle reviewDbBundle =
- GroupBundle.Factory.fromReviewDb(db, new AccountGroup.Id(createdGroup.groupId));
+ GroupBundle.Factory.fromReviewDb(db, new AccountGroup.UUID(createdGroup.id));
deleteGroupRefs(reviewDbBundle);
assertMigratedCleanly(rebuild(reviewDbBundle), reviewDbBundle);
@@ -108,7 +108,7 @@
}
GroupBundle reviewDbBundle =
- GroupBundle.Factory.fromReviewDb(db, new AccountGroup.Id(group1.groupId));
+ GroupBundle.Factory.fromReviewDb(db, new AccountGroup.UUID(group1.id));
deleteGroupRefs(reviewDbBundle);
GroupBundle noteDbBundle = rebuild(reviewDbBundle);
@@ -170,7 +170,7 @@
db.accountGroupByIdAud().insert(Collections.singleton(audit));
GroupBundle reviewDbBundle =
- GroupBundle.Factory.fromReviewDb(db, new AccountGroup.Id(group.groupId));
+ GroupBundle.Factory.fromReviewDb(db, new AccountGroup.UUID(group.id));
deleteGroupRefs(reviewDbBundle);
GroupBundle noteDbBundle = rebuild(reviewDbBundle);