GroupBundle: Check columns like we do for ChangeBundle
Change-Id: I76efb02924efd873a576acda113ec6382cb64cc6
This commit is contained in:
		@@ -14,8 +14,16 @@
 | 
			
		||||
 | 
			
		||||
package com.google.gerrit.reviewdb.server;
 | 
			
		||||
 | 
			
		||||
import static com.google.common.base.Preconditions.checkState;
 | 
			
		||||
 | 
			
		||||
import com.google.common.collect.Ordering;
 | 
			
		||||
import com.google.common.collect.Sets;
 | 
			
		||||
import com.google.gwtorm.client.Column;
 | 
			
		||||
import com.google.gwtorm.client.IntKey;
 | 
			
		||||
import java.lang.reflect.Field;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
import java.util.TreeSet;
 | 
			
		||||
 | 
			
		||||
/** Static utilities for ReviewDb types. */
 | 
			
		||||
public class ReviewDbUtil {
 | 
			
		||||
@@ -48,5 +56,22 @@ public class ReviewDbUtil {
 | 
			
		||||
    return db;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public static void checkColumns(Class<?> clazz, Integer... expected) {
 | 
			
		||||
    Set<Integer> ids = new TreeSet<>();
 | 
			
		||||
    for (Field f : clazz.getDeclaredFields()) {
 | 
			
		||||
      Column col = f.getAnnotation(Column.class);
 | 
			
		||||
      if (col != null) {
 | 
			
		||||
        ids.add(col.id());
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    Set<Integer> expectedIds = Sets.newTreeSet(Arrays.asList(expected));
 | 
			
		||||
    checkState(
 | 
			
		||||
        ids.equals(expectedIds),
 | 
			
		||||
        "Unexpected column set for %s: %s != %s",
 | 
			
		||||
        clazz.getSimpleName(),
 | 
			
		||||
        ids,
 | 
			
		||||
        expectedIds);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private ReviewDbUtil() {}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,7 @@ package com.google.gerrit.server.group.db;
 | 
			
		||||
 | 
			
		||||
import static com.google.common.collect.ImmutableList.toImmutableList;
 | 
			
		||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
 | 
			
		||||
import static com.google.gerrit.reviewdb.server.ReviewDbUtil.checkColumns;
 | 
			
		||||
 | 
			
		||||
import com.google.auto.value.AutoValue;
 | 
			
		||||
import com.google.common.collect.ImmutableList;
 | 
			
		||||
@@ -37,6 +38,27 @@ import com.google.gwtorm.server.OrmException;
 | 
			
		||||
 */
 | 
			
		||||
@AutoValue
 | 
			
		||||
public abstract class GroupBundle {
 | 
			
		||||
  static {
 | 
			
		||||
    // Initialization-time checks that the column set hasn't changed since the
 | 
			
		||||
    // last time this file was updated.
 | 
			
		||||
    checkColumns(AccountGroup.NameKey.class, 1);
 | 
			
		||||
    checkColumns(AccountGroup.UUID.class, 1);
 | 
			
		||||
    checkColumns(AccountGroup.Id.class, 1);
 | 
			
		||||
    checkColumns(AccountGroup.class, 1, 2, 4, 7, 9, 10, 11);
 | 
			
		||||
 | 
			
		||||
    checkColumns(AccountGroupById.Key.class, 1, 2);
 | 
			
		||||
    checkColumns(AccountGroupById.class, 1);
 | 
			
		||||
 | 
			
		||||
    checkColumns(AccountGroupByIdAud.Key.class, 1, 2, 3);
 | 
			
		||||
    checkColumns(AccountGroupByIdAud.class, 1, 2, 3, 4);
 | 
			
		||||
 | 
			
		||||
    checkColumns(AccountGroupMember.Key.class, 1, 2);
 | 
			
		||||
    checkColumns(AccountGroupMember.class, 1);
 | 
			
		||||
 | 
			
		||||
    checkColumns(AccountGroupMemberAudit.Key.class, 1, 2, 3);
 | 
			
		||||
    checkColumns(AccountGroupMemberAudit.class, 1, 2, 3, 4);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public static GroupBundle fromReviewDb(ReviewDb db, AccountGroup.Id id) throws OrmException {
 | 
			
		||||
    AccountGroup group = db.accountGroups().get(id);
 | 
			
		||||
    if (group == null) {
 | 
			
		||||
 
 | 
			
		||||
@@ -17,8 +17,8 @@ package com.google.gerrit.server.notedb;
 | 
			
		||||
import static com.google.common.base.MoreObjects.firstNonNull;
 | 
			
		||||
import static com.google.common.base.Preconditions.checkArgument;
 | 
			
		||||
import static com.google.common.base.Preconditions.checkNotNull;
 | 
			
		||||
import static com.google.common.base.Preconditions.checkState;
 | 
			
		||||
import static com.google.gerrit.common.TimeUtil.roundToSecond;
 | 
			
		||||
import static com.google.gerrit.reviewdb.server.ReviewDbUtil.checkColumns;
 | 
			
		||||
import static com.google.gerrit.reviewdb.server.ReviewDbUtil.intKeyOrdering;
 | 
			
		||||
import static com.google.gerrit.server.notedb.ChangeBundle.Source.NOTE_DB;
 | 
			
		||||
import static com.google.gerrit.server.notedb.ChangeBundle.Source.REVIEW_DB;
 | 
			
		||||
@@ -71,7 +71,6 @@ import java.util.Objects;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
import java.util.TreeMap;
 | 
			
		||||
import java.util.TreeSet;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A bundle of all entities rooted at a single {@link Change} entity.
 | 
			
		||||
@@ -212,23 +211,6 @@ public class ChangeBundle {
 | 
			
		||||
        .compare(a.get(), b.get());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static void checkColumns(Class<?> clazz, Integer... expected) {
 | 
			
		||||
    Set<Integer> ids = new TreeSet<>();
 | 
			
		||||
    for (Field f : clazz.getDeclaredFields()) {
 | 
			
		||||
      Column col = f.getAnnotation(Column.class);
 | 
			
		||||
      if (col != null) {
 | 
			
		||||
        ids.add(col.id());
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    Set<Integer> expectedIds = Sets.newTreeSet(Arrays.asList(expected));
 | 
			
		||||
    checkState(
 | 
			
		||||
        ids.equals(expectedIds),
 | 
			
		||||
        "Unexpected column set for %s: %s != %s",
 | 
			
		||||
        clazz.getSimpleName(),
 | 
			
		||||
        ids,
 | 
			
		||||
        expectedIds);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static {
 | 
			
		||||
    // Initialization-time checks that the column set hasn't changed since the
 | 
			
		||||
    // last time this file was updated.
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user