Merge branch 'stable-3.0' into stable-3.1

* stable-3.0:
  Bump Bazel version to 3.7.0
  Upgrade bazlets to latest stable-3.0 to build with 3.0.13 API

Change-Id: I8de8bd2efc74d22b4ceae7425e4bc6e1cb8fad6d
diff --git a/WORKSPACE b/WORKSPACE
index e0d8d5e..238f038 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -3,7 +3,7 @@
 load("//:bazlets.bzl", "load_bazlets")
 
 load_bazlets(
-    commit = "a010a539824bd467059f414412a47b80101352d7",
+    commit = "3f9dadc615dc4053369a42d9ada37dafd8d4763c",
     #local_path = "/home/<user>/projects/bazlets",
 )
 
diff --git a/external_plugin_deps.bzl b/external_plugin_deps.bzl
index 8d7be89..d574618 100644
--- a/external_plugin_deps.bzl
+++ b/external_plugin_deps.bzl
@@ -1,16 +1,16 @@
 load("//tools/bzl:maven_jar.bzl", "maven_jar")
 
 def external_plugin_deps():
-    AUTO_VALUE_VERSION = "1.6.5"
+    AUTO_VALUE_VERSION = "1.7"
 
     maven_jar(
         name = "auto-value",
         artifact = "com.google.auto.value:auto-value:" + AUTO_VALUE_VERSION,
-        sha1 = "816872c85048f36a67a276ef7a49cc2e4595711c",
+        sha1 = "fe8387764ed19460eda4f106849c664f51c07121",
     )
 
     maven_jar(
         name = "auto-value-annotations",
         artifact = "com.google.auto.value:auto-value-annotations:" + AUTO_VALUE_VERSION,
-        sha1 = "c3dad10377f0e2242c9a4b88e9704eaf79103679",
+        sha1 = "5be124948ebdc7807df68207f35a0f23ce427f29",
     )
diff --git a/pom.xml b/pom.xml
index b1ea7c7..0ef2e07 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,13 +22,13 @@
   <groupId>com.googlesource.gerrit.plugins.batch</groupId>
   <artifactId>batch</artifactId>
   <packaging>jar</packaging>
-  <version>3.0.9</version>
+  <version>3.1.0</version>
   <name>batch</name>
 
   <properties>
     <Gerrit-ApiType>plugin</Gerrit-ApiType>
     <Gerrit-ApiVersion>${project.version}</Gerrit-ApiVersion>
-    <auto-value.version>1.6.5</auto-value.version>
+    <auto-value.version>1.7</auto-value.version>
   </properties>
 
   <build>
diff --git a/src/main/java/com/google/gerrit/entities/FileNameKey.java b/src/main/java/com/google/gerrit/entities/FileNameKey.java
index d415278..63531a5 100644
--- a/src/main/java/com/google/gerrit/entities/FileNameKey.java
+++ b/src/main/java/com/google/gerrit/entities/FileNameKey.java
@@ -15,21 +15,21 @@
 package com.google.gerrit.entities;
 
 import com.google.auto.value.AutoValue;
-import com.google.gerrit.reviewdb.client.Branch;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.entities.BranchNameKey;
+import com.google.gerrit.entities.Project;
 
 /** An immutable reference to a file in gerrit repo. */
 @AutoValue
 public abstract class FileNameKey implements Comparable<FileNameKey> {
-  public static FileNameKey create(Branch.NameKey branch, String file) {
+  public static FileNameKey create(BranchNameKey branch, String file) {
     return new AutoValue_FileNameKey(branch, file);
   }
 
   public static FileNameKey create() {
-    return new AutoValue_FileNameKey(new Branch.NameKey(new Project.NameKey(null), null), null);
+    return new AutoValue_FileNameKey(BranchNameKey.create(Project.nameKey(null), null), null);
   }
 
-  public abstract Branch.NameKey branch();
+  public abstract BranchNameKey branch();
   public abstract String file();
 
   @Override
diff --git a/src/main/java/com/google/gerrit/server/git/meta/GitFile.java b/src/main/java/com/google/gerrit/server/git/meta/GitFile.java
index 4fe617d..2bf5a14 100644
--- a/src/main/java/com/google/gerrit/server/git/meta/GitFile.java
+++ b/src/main/java/com/google/gerrit/server/git/meta/GitFile.java
@@ -14,9 +14,9 @@
 
 package com.google.gerrit.server.git.meta;
 
-import com.google.gerrit.reviewdb.client.Branch;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.entities.BranchNameKey;
 import com.google.gerrit.entities.FileNameKey;
+import com.google.gerrit.entities.Project;
 import com.google.gerrit.server.git.GitRepositoryManager;
 import com.google.gerrit.server.project.NoSuchProjectException;
 import com.google.inject.Inject;
@@ -37,7 +37,7 @@
   protected final MetaDataUpdate.User metaDataUpdateFactory;
   protected final GitRepositoryManager repos;
 
-  protected Branch.NameKey branch;
+  protected BranchNameKey branch;
   protected String file;
 
   public String text;
@@ -54,7 +54,7 @@
   }
 
   public String read() throws ConfigInvalidException, IOException, NoSuchProjectException {
-    Project.NameKey project = branch.getParentKey();
+    Project.NameKey project = branch.project();
     try (Repository repo = repos.openRepository(project)) {
       load(project, repo);
       return text;
@@ -65,7 +65,7 @@
 
   public RevCommit write(String fileContent, String commitMessage)
       throws ConfigInvalidException, IOException, NoSuchProjectException {
-    Project.NameKey project = branch.getParentKey();
+    Project.NameKey project = branch.project();
     try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
       load(md);
       text = fileContent;
@@ -77,7 +77,7 @@
     }
   }
 
-  public void setBranch(Branch.NameKey branch) {
+  public void setBranch(BranchNameKey branch) {
     this.branch = branch;
   }
 
@@ -87,7 +87,7 @@
 
   @Override
   protected String getRefName() {
-    return branch.get();
+    return branch.branch();
   }
 
   @Override
diff --git a/src/main/java/com/google/gerrit/server/util/RefUpdater.java b/src/main/java/com/google/gerrit/server/util/RefUpdater.java
index 818d857..1f4dfd1 100644
--- a/src/main/java/com/google/gerrit/server/util/RefUpdater.java
+++ b/src/main/java/com/google/gerrit/server/util/RefUpdater.java
@@ -14,8 +14,8 @@
 package com.google.gerrit.server.util;
 
 import com.google.common.flogger.FluentLogger;
-import com.google.gerrit.reviewdb.client.Branch;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.entities.BranchNameKey;
+import com.google.gerrit.entities.Project;
 import com.google.gerrit.server.CurrentUser;
 import com.google.gerrit.server.GerritPersonIdent;
 import com.google.gerrit.server.IdentifiedUser;
@@ -38,14 +38,14 @@
   private static final FluentLogger log = FluentLogger.forEnclosingClass();
 
   public class Args {
-    public final Branch.NameKey branch;
+    public final BranchNameKey branch;
     public ObjectId expectedOldObjectId;
     public ObjectId newObjectId;
     public boolean isForceUpdate;
     public PersonIdent refLogIdent;
     public String refLogMessage;
 
-    public Args(Branch.NameKey branch) {
+    public Args(BranchNameKey branch) {
       this.branch = branch;
       CurrentUser user = userProvider.get();
       if (user instanceof IdentifiedUser) {
@@ -79,13 +79,13 @@
     this.gitRefUpdated = gitRefUpdated;
   }
 
-  public void update(Branch.NameKey branch, ObjectId oldRefId, ObjectId newRefId)
+  public void update(BranchNameKey branch, ObjectId oldRefId, ObjectId newRefId)
       throws IOException, NoSuchProjectException {
     this.update(branch, oldRefId, newRefId, null);
   }
 
   public void update(
-      Branch.NameKey branch, ObjectId oldRefId, ObjectId newRefId, String refLogMessage)
+      BranchNameKey branch, ObjectId oldRefId, ObjectId newRefId, String refLogMessage)
       throws IOException, NoSuchProjectException {
     Args args = new Args(branch);
     args.expectedOldObjectId = oldRefId;
@@ -94,12 +94,12 @@
     this.update(args);
   }
 
-  public void forceUpdate(Branch.NameKey branch, ObjectId newRefId)
+  public void forceUpdate(BranchNameKey branch, ObjectId newRefId)
       throws IOException, NoSuchProjectException {
     this.forceUpdate(branch, newRefId, null);
   }
 
-  public void forceUpdate(Branch.NameKey branch, ObjectId newRefId, String refLogMessage)
+  public void forceUpdate(BranchNameKey branch, ObjectId newRefId, String refLogMessage)
       throws IOException, NoSuchProjectException {
     Args args = new Args(branch);
     args.newObjectId = newRefId;
@@ -108,7 +108,7 @@
     update(args);
   }
 
-  public void delete(Branch.NameKey branch) throws IOException, NoSuchProjectException {
+  public void delete(BranchNameKey branch) throws IOException, NoSuchProjectException {
     Args args = new Args(branch);
     args.newObjectId = ObjectId.zeroId();
     args.isForceUpdate = true;
@@ -123,14 +123,14 @@
     protected Repository repo;
     protected Args args;
     protected RefUpdate update;
-    protected Branch.NameKey branch;
+    protected BranchNameKey branch;
     protected Project.NameKey project;
     protected boolean delete;
 
     protected Update(Args args) {
       this.args = args;
       branch = args.branch;
-      project = branch.getParentKey();
+      project = branch.project();
       delete = args.newObjectId.equals(ObjectId.zeroId());
     }
 
@@ -142,7 +142,7 @@
           handleResult(runUpdate());
         } catch (IOException err) {
           log.atSevere().withCause(err).log(
-              "RefUpdate failed: branch not updated: %s", branch.get());
+              "RefUpdate failed: branch not updated: %s", branch.branch());
           throw err;
         } finally {
           repo.close();
@@ -154,7 +154,7 @@
     }
 
     protected void initUpdate() throws IOException {
-      update = repo.updateRef(branch.get());
+      update = repo.updateRef(branch.branch());
       update.setExpectedOldObjectId(args.expectedOldObjectId);
       update.setNewObjectId(args.newObjectId);
       update.setRefLogIdent(args.refLogIdent);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/batch/Batch.java b/src/main/java/com/googlesource/gerrit/plugins/batch/Batch.java
index 79c1d36..cb5af67 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/batch/Batch.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/batch/Batch.java
@@ -13,9 +13,9 @@
 // limitations under the License.
 package com.googlesource.gerrit.plugins.batch;
 
-import com.google.gerrit.reviewdb.client.Account;
-import com.google.gerrit.reviewdb.client.Branch;
-import com.google.gerrit.reviewdb.client.PatchSet;
+import com.google.gerrit.entities.Account;
+import com.google.gerrit.entities.BranchNameKey;
+import com.google.gerrit.entities.PatchSet;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
@@ -35,12 +35,12 @@
     int patchSet;
 
     Change(PatchSet.Id psId) {
-      number = psId.getParentKey().get();
+      number = psId.changeId().get();
       patchSet = psId.get();
     }
 
     public PatchSet.Id toPatchSetId() {
-      return new PatchSet.Id(new com.google.gerrit.reviewdb.client.Change.Id(number), patchSet);
+      return PatchSet.id(com.google.gerrit.entities.Change.id(number), patchSet);
     }
   }
 
@@ -86,26 +86,26 @@
     return destinations;
   }
 
-  public Destination getDestination(Branch.NameKey branch) {
+  public Destination getDestination(BranchNameKey branch) {
     if (destinations == null) {
       destinations = new ArrayList<>();
     }
     Destination dest = getExistingDestination(branch);
     if (dest == null) {
       dest = new Destination();
-      dest.project = branch.getParentKey().get();
-      dest.ref = branch.get();
+      dest.project = branch.project().get();
+      dest.ref = branch.branch();
       destinations.add(dest);
     }
     return dest;
   }
 
-  protected Destination getExistingDestination(Branch.NameKey branch) {
+  protected Destination getExistingDestination(BranchNameKey branch) {
     if (destinations == null) {
       destinations = new ArrayList<>();
     }
     for (Destination dest : destinations) {
-      if (dest.project.equals(branch.getParentKey().get()) && dest.ref.equals(branch.get())) {
+      if (dest.project.equals(branch.project().get()) && dest.ref.equals(branch.branch())) {
         return dest;
       }
     }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/batch/BatchCloser.java b/src/main/java/com/googlesource/gerrit/plugins/batch/BatchCloser.java
index a528d2f..e66ba76 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/batch/BatchCloser.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/batch/BatchCloser.java
@@ -13,8 +13,8 @@
 // limitations under the License.
 package com.googlesource.gerrit.plugins.batch;
 
-import com.google.gerrit.reviewdb.client.Branch;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.entities.BranchNameKey;
+import com.google.gerrit.entities.Project;
 import com.google.gerrit.server.IdentifiedUser;
 import com.google.gerrit.server.project.NoSuchProjectException;
 import com.google.gerrit.server.util.RefUpdater;
@@ -47,8 +47,8 @@
   protected void createDownloadRefs(Batch batch) throws IOException, NoSuchProjectException {
     for (Batch.Destination dest : batch.listDestinations()) {
       dest.downloadRef = getBatchRef(batch, dest);
-      Project.NameKey project = new Project.NameKey(dest.project);
-      Branch.NameKey branch = new Branch.NameKey(project, dest.downloadRef);
+      Project.NameKey project = Project.nameKey(dest.project);
+      BranchNameKey branch = BranchNameKey.create(project, dest.downloadRef);
       ObjectId id = ObjectId.fromString(dest.sha1);
       refUpdater.update(branch, ObjectId.zeroId(), id);
     }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/batch/BatchRemover.java b/src/main/java/com/googlesource/gerrit/plugins/batch/BatchRemover.java
index ffb7b41..ac52e2a 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/batch/BatchRemover.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/batch/BatchRemover.java
@@ -14,8 +14,8 @@
 
 package com.googlesource.gerrit.plugins.batch;
 
-import com.google.gerrit.reviewdb.client.Branch;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.entities.BranchNameKey;
+import com.google.gerrit.entities.Project;
 import com.google.gerrit.server.project.NoSuchProjectException;
 import com.google.gerrit.server.util.RefUpdater;
 import com.google.inject.Inject;
@@ -55,8 +55,8 @@
   protected void removeDownloadRefs(Batch batch)
       throws IOException, RepositoryNotFoundException, NoSuchProjectException {
     for (Batch.Destination dest : batch.listDestinations()) {
-      Project.NameKey project = new Project.NameKey(dest.project);
-      Branch.NameKey branch = new Branch.NameKey(project, dest.downloadRef);
+      Project.NameKey project = Project.nameKey(dest.project);
+      BranchNameKey branch = BranchNameKey.create(project, dest.downloadRef);
       refUpdater.delete(branch);
     }
   }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/batch/BatchStore.java b/src/main/java/com/googlesource/gerrit/plugins/batch/BatchStore.java
index 7290148..7ce10a6 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/batch/BatchStore.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/batch/BatchStore.java
@@ -13,18 +13,28 @@
 // limitations under the License.
 package com.googlesource.gerrit.plugins.batch;
 
-import com.google.gerrit.reviewdb.client.Branch;
+import com.google.gerrit.entities.Account;
+import com.google.gerrit.entities.BranchNameKey;
 import com.google.gerrit.entities.FileNameKey;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.entities.Project;
 import com.google.gerrit.server.config.AllProjectsName;
 import com.google.gerrit.server.git.GitRepositoryManager;
 import com.google.gerrit.server.git.meta.GitFile;
 import com.google.gerrit.server.project.NoSuchProjectException;
 import com.google.gerrit.server.util.RefUpdater;
 import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParseException;
+import com.google.gson.JsonPrimitive;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
 import com.google.inject.Inject;
 import com.googlesource.gerrit.plugins.batch.exception.NoSuchBatchException;
 import java.io.IOException;
+import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.ConcurrentModificationException;
 import java.util.Date;
@@ -39,11 +49,32 @@
   public static final String BATCHES_REF = "refs/meta/batch/batches/";
   public static final String FILE_NAME = "batch.json";
 
+  public static class AccountIdDeserializer
+      implements JsonDeserializer<Account.Id>, JsonSerializer<Account.Id> {
+
+    @Override
+    public Account.Id deserialize(
+        JsonElement json, Type typeOfT, JsonDeserializationContext context)
+        throws JsonParseException {
+      if (json.isJsonNull() || !json.isJsonPrimitive() || !json.getAsJsonPrimitive().isNumber()) {
+        throw new JsonParseException("Expected int for account.id type");
+      }
+      JsonPrimitive p = (JsonPrimitive) json;
+      return Account.id(p.getAsInt());
+    }
+
+    @Override
+    public JsonElement serialize(Account.Id id, Type typeOfSrc, JsonSerializationContext context) {
+      return new JsonPrimitive(id.get());
+    }
+  }
+
   protected final GitRepositoryManager repoManager;
   protected final Project.NameKey project;
   protected final GitFile.Factory gitFileFactory;
   protected final RefUpdater refUpdater;
-  protected final Gson gson = new Gson();
+  protected final Gson gson =
+      new GsonBuilder().registerTypeAdapter(Account.Id.class, new AccountIdDeserializer()).create();
 
   @Inject
   public BatchStore(
@@ -110,11 +141,11 @@
     return getFileNameKey(getBranch(id));
   }
 
-  protected Branch.NameKey getBranch(String id) {
-    return new Branch.NameKey(project, BATCHES_REF + id);
+  protected BranchNameKey getBranch(String id) {
+    return BranchNameKey.create(project, BATCHES_REF + id);
   }
 
-  protected FileNameKey getFileNameKey(Branch.NameKey branch) {
+  protected FileNameKey getFileNameKey(BranchNameKey branch) {
     return FileNameKey.create(branch, FILE_NAME);
   }
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/batch/BatchSubmitter.java b/src/main/java/com/googlesource/gerrit/plugins/batch/BatchSubmitter.java
index 018f524..82b944e 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/batch/BatchSubmitter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/batch/BatchSubmitter.java
@@ -15,12 +15,12 @@
 package com.googlesource.gerrit.plugins.batch;
 
 import com.google.common.flogger.FluentLogger;
+import com.google.gerrit.entities.BranchNameKey;
+import com.google.gerrit.entities.Change;
+import com.google.gerrit.entities.PatchSet;
+import com.google.gerrit.entities.Project;
 import com.google.gerrit.extensions.restapi.AuthException;
 import com.google.gerrit.extensions.restapi.RestApiException;
-import com.google.gerrit.reviewdb.client.Branch;
-import com.google.gerrit.reviewdb.client.Change;
-import com.google.gerrit.reviewdb.client.PatchSet;
-import com.google.gerrit.reviewdb.client.Project;
 import com.google.gerrit.server.IdentifiedUser;
 import com.google.gerrit.server.PatchSetUtil;
 import com.google.gerrit.server.git.GitRepositoryManager;
@@ -111,7 +111,7 @@
   private void ensureCanSubmit(Batch.Destination dest)
       throws AuthException, PermissionBackendException {
     PermissionBackend.ForProject permissions =
-        permissionBackend.user(user).project(new Project.NameKey(dest.project));
+        permissionBackend.user(user).project(Project.nameKey(dest.project));
     permissions.ref(dest.ref).check(RefPermission.FORCE_UPDATE);
   }
 
@@ -126,8 +126,8 @@
 
   private void updateRef(Batch.Destination dest)
       throws IOException, NoSuchProjectException, RepositoryNotFoundException {
-    Project.NameKey project = new Project.NameKey(dest.project);
-    Branch.NameKey branch = new Branch.NameKey(project, dest.ref);
+    Project.NameKey project = Project.nameKey(dest.project);
+    BranchNameKey branch = BranchNameKey.create(project, dest.ref);
     refUpdater.forceUpdate(branch, ObjectId.fromString(dest.sha1));
   }
 
@@ -144,7 +144,7 @@
   private void closeChange(PatchSet.Id psId, String sha1)
       throws IOException, RepositoryNotFoundException, RestApiException, UpdateException,
           PermissionBackendException {
-    ChangeNotes changeNotes = notesFactory.createChecked(psId.getParentKey());
+    ChangeNotes changeNotes = notesFactory.createChecked(psId.changeId());
     permissionBackend.user(user).change(changeNotes).check(ChangePermission.READ);
     Change change = changeNotes.getChange();
     PatchSet ps = psUtil.get(changeNotes, psId);
@@ -157,8 +157,8 @@
         || change.getStatus() == Change.Status.ABANDONED) {
       return;
     }
-    Branch.NameKey destination = change.getDest();
-    Project.NameKey project = destination.getParentKey();
+    BranchNameKey destination = change.getDest();
+    Project.NameKey project = destination.project();
 
     try (TraceContext traceContext =
             TraceContext.open()
@@ -171,8 +171,8 @@
       bu.setRepository(repo, walk, ins);
       bu.setRefLogMessage("merged (batch submit)");
       bu.addOp(
-          psId.getParentKey(),
-          mergedByPushOpFactory.create(requestScopePropagator, psId, destination.get(), sha1));
+          psId.changeId(),
+          mergedByPushOpFactory.create(requestScopePropagator, psId, destination.branch(), sha1));
       bu.execute();
     }
   }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/batch/cli/PatchSetArgument.java b/src/main/java/com/googlesource/gerrit/plugins/batch/cli/PatchSetArgument.java
index 4feb2fa..78d173a 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/batch/cli/PatchSetArgument.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/batch/cli/PatchSetArgument.java
@@ -13,9 +13,9 @@
 // limitations under the License.
 package com.googlesource.gerrit.plugins.batch.cli;
 
+import com.google.gerrit.entities.Change;
+import com.google.gerrit.entities.PatchSet;
 import com.google.gerrit.extensions.restapi.AuthException;
-import com.google.gerrit.reviewdb.client.Change;
-import com.google.gerrit.reviewdb.client.PatchSet;
 import com.google.gerrit.server.CurrentUser;
 import com.google.gerrit.server.PatchSetUtil;
 import com.google.gerrit.server.notedb.ChangeNotes;
@@ -47,7 +47,7 @@
     public PatchSetArgument createForArgument(String token) {
       try {
         PatchSet.Id patchSetId = parsePatchSet(token);
-        ChangeNotes changeNotes = notesFactory.createChecked(patchSetId.getParentKey());
+        ChangeNotes changeNotes = notesFactory.createChecked(patchSetId.changeId());
         permissionBackend.user(user).change(changeNotes).check(ChangePermission.READ);
         return new PatchSetArgument(changeNotes.getChange(), psUtil.get(changeNotes, patchSetId));
       } catch (PermissionBackendException | AuthException e) {
@@ -87,7 +87,7 @@
   }
 
   public void ensureLatest() {
-    if (!change.currentPatchSetId().equals(patchSet.getId())) {
+    if (!change.currentPatchSetId().equals(patchSet.id())) {
       throw new IllegalArgumentException(patchSet + " is not the latest patch set");
     }
   }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/batch/ssh/ListCommand.java b/src/main/java/com/googlesource/gerrit/plugins/batch/ssh/ListCommand.java
index 8adf607..6f78ecb 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/batch/ssh/ListCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/batch/ssh/ListCommand.java
@@ -20,6 +20,7 @@
 import com.google.inject.Inject;
 import com.googlesource.gerrit.plugins.batch.ListBatches;
 import org.apache.sshd.server.Environment;
+import org.apache.sshd.server.channel.ChannelSession;
 
 @CommandMetaData(name = "ls-batches", description = "List batches visible to caller")
 public class ListCommand extends BaseCommand {
@@ -31,7 +32,7 @@
   }
 
   @Override
-  public void start(final Environment env) {
+  public void start(ChannelSession channel, final Environment env) {
     startThread(
         new CommandRunnable() {
           @Override
diff --git a/src/main/java/com/googlesource/gerrit/plugins/batch/ssh/MergeChangeCommand.java b/src/main/java/com/googlesource/gerrit/plugins/batch/ssh/MergeChangeCommand.java
index 64ccacc..10d8b65 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/batch/ssh/MergeChangeCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/batch/ssh/MergeChangeCommand.java
@@ -13,11 +13,11 @@
 // limitations under the License.
 package com.googlesource.gerrit.plugins.batch.ssh;
 
+import com.google.gerrit.entities.BranchNameKey;
+import com.google.gerrit.entities.Change;
+import com.google.gerrit.entities.PatchSet;
+import com.google.gerrit.entities.Project;
 import com.google.gerrit.json.OutputFormat;
-import com.google.gerrit.reviewdb.client.Branch;
-import com.google.gerrit.reviewdb.client.Change;
-import com.google.gerrit.reviewdb.client.PatchSet;
-import com.google.gerrit.reviewdb.client.Project;
 import com.google.gerrit.server.git.GitRepositoryManager;
 import com.google.gerrit.server.project.NoSuchRefException;
 import com.google.gerrit.sshd.CommandMetaData;
@@ -77,7 +77,7 @@
   protected void addPatchSetId(final String token) {
     PatchSetArgument psa = patchSetArgumentFactory.createForArgument(token);
     psa.ensureLatest();
-    patchSetArgumentsByPatchSet.put(psa.patchSet.getId(), psa);
+    patchSetArgumentsByPatchSet.put(psa.patchSet.id(), psa);
   }
 
   @Inject protected PatchSetArgument.Factory patchSetArgumentFactory;
@@ -130,7 +130,7 @@
       return true;
     }
     for (ObjectId parent : parents) {
-      Project.NameKey project = psarg.change.getDest().getParentKey();
+      Project.NameKey project = psarg.change.getDest().project();
       if (isMergedInto(project, parent, sha1)) {
         return true;
       }
@@ -146,10 +146,10 @@
     }
   }
 
-  protected ObjectId getTip(Branch.NameKey branch)
+  protected ObjectId getTip(BranchNameKey branch)
       throws IOException, NoSuchRefException, RepositoryNotFoundException {
-    try (Repository repo = repoManager.openRepository(branch.getParentKey())) {
-      Ref ref = repo.getRefDatabase().exactRef(branch.get());
+    try (Repository repo = repoManager.openRepository(branch.project())) {
+      Ref ref = repo.getRefDatabase().exactRef(branch.branch());
       if (ref == null) {
         throw new NoSuchRefException(branch.toString());
       }
@@ -159,20 +159,20 @@
 
   protected void merge(Batch batch, Change change, PatchSet ps)
       throws Exception, IOException, NoSuchRefException, UnloggedFailure {
-    Branch.NameKey branch = change.getDest();
+    BranchNameKey branch = change.getDest();
     Batch.Destination dest = batch.getDestination(branch);
     dest.sha1 =
         mergeBranchFactory
             .create(
                 branch,
                 dest.sha1,
-                ps.getRefName(),
+                ps.refName(),
                 strategy.getMergeStrategy(),
                 fastForward.getFastForwardMode(),
                 message)
             .call()
             .getName();
-    dest.add(ps.getId());
+    dest.add(ps.id());
   }
 
   /* A Resolver which ensures that changes are eligible to merge before
@@ -197,12 +197,12 @@
       List<PatchSetArgument> remaining = new ArrayList<>();
       Set<ObjectId> sources = new HashSet<>();
 
-      Destination(Branch.NameKey branch) throws IOException, NoSuchRefException {
+      Destination(BranchNameKey branch) throws IOException, NoSuchRefException {
         sources.add(getTip(branch));
       }
     }
 
-    protected Map<Branch.NameKey, Destination> destinationsByBranches = new HashMap<>();
+    protected Map<BranchNameKey, Destination> destinationsByBranches = new HashMap<>();
     protected List<PatchSetArgument> resolved = new ArrayList<>();
 
     protected Resolver(Iterable<PatchSetArgument> psargs)
@@ -236,7 +236,7 @@
         if (isParentMergedInto(psarg, dest.sources)) {
           found = true;
           resolved.add(psarg);
-          dest.sources.add(ObjectId.fromString(psarg.patchSet.getRevision().get()));
+          dest.sources.add(psarg.patchSet.commitId());
         }
       }
       dest.remaining.removeAll(resolved);
@@ -250,12 +250,12 @@
     }
 
     protected void add(PatchSetArgument psarg) throws IOException, NoSuchRefException {
-      Branch.NameKey branch = psarg.change.getDest();
+      BranchNameKey branch = psarg.change.getDest();
       Destination dest = getDestination(branch);
       dest.remaining.add(psarg);
     }
 
-    protected Destination getDestination(Branch.NameKey b) throws IOException, NoSuchRefException {
+    protected Destination getDestination(BranchNameKey b) throws IOException, NoSuchRefException {
       Destination dest = destinationsByBranches.get(b);
       if (dest == null) {
         dest = new Destination(b);
@@ -266,7 +266,7 @@
   }
 
   protected List<ObjectId> getParents(PatchSetArgument psarg) throws IOException {
-    PatchSet.Id id = psarg.patchSet.getId();
+    PatchSet.Id id = psarg.patchSet.id();
     List<ObjectId> parents = parentsByPsarg.get(id);
     if (parents == null) {
       parents = loadParents(psarg);
@@ -279,7 +279,7 @@
     try (Repository repo = repoManager.openRepository(psarg.change.getProject());
         RevWalk revWalk = new RevWalk(repo)) {
       List<ObjectId> parents = new ArrayList<>();
-      ObjectId id = ObjectId.fromString(psarg.patchSet.getRevision().get());
+      ObjectId id = psarg.patchSet.commitId();
       RevCommit c = revWalk.parseCommit(id);
       for (RevCommit parent : c.getParents()) {
         parents.add(parent);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/batch/util/MergeBranch.java b/src/main/java/com/googlesource/gerrit/plugins/batch/util/MergeBranch.java
index bcec3a7..02831e6 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/batch/util/MergeBranch.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/batch/util/MergeBranch.java
@@ -14,11 +14,11 @@
 package com.googlesource.gerrit.plugins.batch.util;
 
 import com.google.gerrit.common.Nullable;
+import com.google.gerrit.entities.BooleanProjectConfig;
+import com.google.gerrit.entities.BranchNameKey;
+import com.google.gerrit.entities.Project;
+import com.google.gerrit.entities.RefNames;
 import com.google.gerrit.extensions.restapi.BadRequestException;
-import com.google.gerrit.reviewdb.client.BooleanProjectConfig;
-import com.google.gerrit.reviewdb.client.Branch;
-import com.google.gerrit.reviewdb.client.Project;
-import com.google.gerrit.reviewdb.client.RefNames;
 import com.google.gerrit.server.git.GitRepositoryManager;
 import com.google.gerrit.server.project.NoSuchRefException;
 import com.google.gerrit.server.project.ProjectCache;
@@ -38,7 +38,7 @@
 public class MergeBranch implements Callable<ObjectId> {
   public interface Factory {
     MergeBranch create(
-        @Assisted Branch.NameKey destBranch,
+        @Assisted BranchNameKey destBranch,
         @Assisted("destSha") @Nullable String destSha,
         @Assisted("sourceRef") String srcName,
         @Assisted MergeStrategy strategy,
@@ -62,7 +62,7 @@
       GitRepositoryManager repoManager,
       ProjectCache projectCache,
       MergeBuilder.Factory builderFactory,
-      @Assisted Branch.NameKey destBranch,
+      @Assisted BranchNameKey destBranch,
       @Assisted("destSha") @Nullable String destSha,
       @Assisted("sourceRef") String srcName,
       @Assisted("message") @Nullable String message,
@@ -71,8 +71,8 @@
     this.projectCache = projectCache;
     this.repoManager = repoManager;
     this.builderFactory = builderFactory;
-    this.projectName = destBranch.getParentKey();
-    destName = RefNames.fullName(destBranch.get());
+    this.projectName = destBranch.project();
+    destName = RefNames.fullName(destBranch.branch());
     if (destSha != null) {
       this.destId = ObjectId.fromString(destSha);
     }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/batch/util/MergeBuilder.java b/src/main/java/com/googlesource/gerrit/plugins/batch/util/MergeBuilder.java
index 72bd980..7265604 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/batch/util/MergeBuilder.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/batch/util/MergeBuilder.java
@@ -14,7 +14,7 @@
 package com.googlesource.gerrit.plugins.batch.util;
 
 import com.google.gerrit.common.Nullable;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.entities.Project;
 import com.google.gerrit.server.GerritPersonIdent;
 import com.google.gerrit.server.IdentifiedUser;
 import com.google.gerrit.server.git.GitRepositoryManager;