Add support for set() method to Key, and use fromString() for URLs

This way we have a consistent URL encoding for any entity key.

Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2008-12-29 09:52:42 -08:00
parent 2e3b5190b2
commit 1371e9c561
21 changed files with 168 additions and 44 deletions

View File

@@ -37,6 +37,18 @@ public final class Account {
public int get() {
return id;
}
@Override
protected void set(int newValue) {
id = newValue;
}
/** Parse an Account.Id out of a string representation. */
public static Id parse(final String str) {
final Id r = new Id();
r.fromString(str);
return r;
}
}
@Column

View File

@@ -44,6 +44,11 @@ public final class AccountExternalId {
public String get() {
return externalId;
}
@Override
protected void set(String newValue) {
externalId = newValue;
}
}
@Column(name = Column.NONE)

View File

@@ -37,6 +37,11 @@ public final class AccountGroup {
public String get() {
return name;
}
@Override
protected void set(String newValue) {
name = newValue;
}
}
/** Synthetic key to link to within the database */
@@ -55,6 +60,11 @@ public final class AccountGroup {
public int get() {
return id;
}
@Override
protected void set(int newValue) {
id = newValue;
}
}
@Column

View File

@@ -46,6 +46,11 @@ public final class AccountSshKey {
public int get() {
return seq;
}
@Override
protected void set(int newValue) {
seq = newValue;
}
}
@Column(name = Column.NONE)

View File

@@ -35,6 +35,11 @@ public final class ApprovalCategory {
public String get() {
return id;
}
@Override
protected void set(String newValue) {
id = newValue;
}
}
@Column

View File

@@ -44,6 +44,11 @@ public final class ApprovalCategoryValue {
public short get() {
return value;
}
@Override
protected void set(short newValue) {
value = newValue;
}
}
@Column(name = Column.NONE)

View File

@@ -42,6 +42,11 @@ public final class Branch {
return branchName;
}
@Override
protected void set(String newValue) {
branchName = newValue;
}
@Override
public Project.NameKey getParentKey() {
return projectName;
@@ -76,6 +81,11 @@ public final class Branch {
public int get() {
return id;
}
@Override
protected void set(int newValue) {
id = newValue;
}
}
@Column(name = Column.NONE)

View File

@@ -38,9 +38,16 @@ public final class Change {
return id;
}
@Override
protected void set(int newValue) {
id = newValue;
}
/** Parse a Change.Id out of a string representation. */
public static Id fromString(final String str) {
return new Id(Integer.parseInt(str));
public static Id parse(final String str) {
final Id r = new Id();
r.fromString(str);
return r;
}
}

View File

@@ -46,6 +46,11 @@ public final class ChangeMessage {
public String get() {
return uuid;
}
@Override
protected void set(String newValue) {
uuid = newValue;
}
}
@Column(name = Column.NONE)

View File

@@ -38,6 +38,11 @@ public final class ContributorAgreement {
public int get() {
return id;
}
@Override
protected void set(int newValue) {
id = newValue;
}
}
@Column

View File

@@ -44,6 +44,18 @@ public final class Patch {
public String get() {
return fileName;
}
@Override
protected void set(String newValue) {
fileName = newValue;
}
/** Parse a Patch.Id out of a string representation. */
public static Id parse(final String str) {
final Id r = new Id();
r.fromString(str);
return r;
}
}
public static enum ChangeType {

View File

@@ -46,6 +46,10 @@ public final class PatchContent {
return KeyUtil.encode(sha1);
}
public void fromString(final String in) {
sha1 = KeyUtil.decode(in);
}
public com.google.gwtorm.client.Key<?> getParentKey() {
return null;
}

View File

@@ -46,6 +46,11 @@ public final class PatchLineComment {
public String get() {
return uuid;
}
@Override
protected void set(String newValue) {
uuid = newValue;
}
}
protected static final char STATUS_DRAFT = 'd';

View File

@@ -44,6 +44,18 @@ public final class PatchSet {
public int get() {
return patchSetId;
}
@Override
protected void set(int newValue) {
patchSetId = newValue;
}
/** Parse a PatchSet.Id out of a string representation. */
public static Id parse(final String str) {
final Id r = new Id();
r.fromString(str);
return r;
}
}
@Column(name = Column.NONE)

View File

@@ -44,6 +44,11 @@ public final class PatchSetAncestor {
public int get() {
return position;
}
@Override
protected void set(int newValue) {
position = newValue;
}
}
@Column(name = Column.NONE)

View File

@@ -37,6 +37,11 @@ public final class Project {
public String get() {
return name;
}
@Override
protected void set(String newValue) {
name = newValue;
}
}
/** Synthetic key to link to within the database */
@@ -55,6 +60,11 @@ public final class Project {
public int get() {
return id;
}
@Override
protected void set(int newValue) {
id = newValue;
}
}
@Column

View File

@@ -34,6 +34,11 @@ public final class SystemConfig {
public String get() {
return VALUE;
}
@Override
protected void set(final String newValue) {
assert get().equals(newValue);
}
}
public static SystemConfig create() {