Fix SubmoduleSubscription primary key

The primary key for a subscription should be:

  super-project name
  super-project branch
  super-project path

As this uniquely identifies one location that needs to know the
updated SHA-1 of a submodule. It also permits a super-project to
subscribe to the same submodule multiple times, at different paths
within the super-project.

This is a major schema change that gwtorm cannot upgrade on its
own. If you have trouble getting through this upgrade on, seek
help from the authors/reviewers of commit d15704079c ("Allow
superprojects to subscribe to submodule updates"):

  Author: Goran Lungberg <goeran.lungberg@sonyericsson.com>
  Code-Review+1: Nasser Grainawi <nasser@codeaurora.org>
  Code-Review+2: Martin Fick <mfick@codeaurora.org>
  Verified+1: Martin Fick <mfick@codeaurora.org>

Change-Id: Ibfe09bd8db2e935ca75475d79311fda5b2bff3d1
This commit is contained in:
Shawn O. Pearce
2012-01-17 08:32:15 -08:00
parent 1937ac481d
commit 54428a99fb
2 changed files with 34 additions and 32 deletions

View File

@@ -15,7 +15,7 @@
package com.google.gerrit.reviewdb; package com.google.gerrit.reviewdb;
import com.google.gwtorm.client.Column; import com.google.gwtorm.client.Column;
import com.google.gwtorm.client.CompoundKey; import com.google.gwtorm.client.StringKey;
/** /**
* Defining a project/branch subscription to a project/branch project. * Defining a project/branch subscription to a project/branch project.
@@ -27,7 +27,7 @@ import com.google.gwtorm.client.CompoundKey;
*/ */
public final class SubmoduleSubscription { public final class SubmoduleSubscription {
/** Subscription key */ /** Subscription key */
public static class Key extends CompoundKey<Branch.NameKey> { public static class Key extends StringKey<Branch.NameKey> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
@@ -37,22 +37,16 @@ public final class SubmoduleSubscription {
@Column(id = 1) @Column(id = 1)
protected Branch.NameKey superProject; protected Branch.NameKey superProject;
/**
* Indicates the submodule, aka subscription: the project the subscriber's
* gitlink is pointed to.
*/
@Column(id = 2) @Column(id = 2)
protected Branch.NameKey submodule; protected String submodulePath;
protected Key() { protected Key() {
superProject = new Branch.NameKey(); superProject = new Branch.NameKey();
submodule = new Branch.NameKey();
} }
protected Key(final Branch.NameKey superProject, protected Key(Branch.NameKey superProject, String path) {
final Branch.NameKey submodule) {
this.superProject = superProject; this.superProject = superProject;
this.submodule = submodule; this.submodulePath = path;
} }
@Override @Override
@@ -61,51 +55,53 @@ public final class SubmoduleSubscription {
} }
@Override @Override
public com.google.gwtorm.client.Key<?>[] members() { public String get() {
return new com.google.gwtorm.client.Key<?>[] {submodule}; return submodulePath;
} }
@Override
protected void set(String newValue) {
this.submodulePath = newValue;
}
} }
@Column(id = 1, name = Column.NONE) @Column(id = 1, name = Column.NONE)
protected Key key; protected Key key;
@Column(id = 2) @Column(id = 2)
protected String path; protected Branch.NameKey submodule;
protected SubmoduleSubscription() { protected SubmoduleSubscription() {
} }
public SubmoduleSubscription(final Branch.NameKey superProject, public SubmoduleSubscription(Branch.NameKey superProject,
final Branch.NameKey submodule, final String path) { Branch.NameKey submodule,
key = new Key(superProject, submodule); String path) {
this.path = path; this.key = new Key(superProject, path);
this.submodule = submodule;
} }
@Override public Key getKey() {
public String toString() { return key;
return key.superProject.getParentKey().get() + " " + key.superProject.get()
+ ", " + key.submodule.getParentKey().get() + " "
+ key.submodule.get() + ", " + path;
} }
public Branch.NameKey getSuperProject() { public Branch.NameKey getSuperProject() {
return key.superProject; return key.superProject;
} }
public Branch.NameKey getSubmodule() { public String getPath() {
return key.submodule; return key.get();
} }
public String getPath() { public Branch.NameKey getSubmodule() {
return path; return submodule;
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (o instanceof SubmoduleSubscription) { if (o instanceof SubmoduleSubscription) {
return key.equals(((SubmoduleSubscription) o).key) return key.equals(((SubmoduleSubscription) o).key)
&& path.equals(((SubmoduleSubscription) o).path); && submodule.equals(((SubmoduleSubscription) o).submodule);
} }
return false; return false;
} }
@@ -114,4 +110,13 @@ public final class SubmoduleSubscription {
public int hashCode() { public int hashCode() {
return key.hashCode(); return key.hashCode();
} }
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getSuperProject()).append(':').append(getPath());
sb.append(" follows ");
sb.append(getSubmodule());
return sb.toString();
}
} }

View File

@@ -25,14 +25,11 @@ public interface SubmoduleSubscriptionAccess extends
@PrimaryKey("key") @PrimaryKey("key")
SubmoduleSubscription get(SubmoduleSubscription.Key key) throws OrmException; SubmoduleSubscription get(SubmoduleSubscription.Key key) throws OrmException;
@Query("ORDER BY key.superProject.projectName")
ResultSet<SubmoduleSubscription> all() throws OrmException;
@Query("WHERE key.superProject = ?") @Query("WHERE key.superProject = ?")
ResultSet<SubmoduleSubscription> bySuperProject(Branch.NameKey superProject) ResultSet<SubmoduleSubscription> bySuperProject(Branch.NameKey superProject)
throws OrmException; throws OrmException;
@Query("WHERE key.submodule = ?") @Query("WHERE submodule = ?")
ResultSet<SubmoduleSubscription> bySubmodule(Branch.NameKey submodule) ResultSet<SubmoduleSubscription> bySubmodule(Branch.NameKey submodule)
throws OrmException; throws OrmException;
} }