Fix vkey construction in PollMessage and BillingEvent (#747)

* Fix vkey construction in PollMessage and BillingEvent

* Remove null check
This commit is contained in:
Shicong Huang 2020-08-07 15:38:53 -04:00 committed by GitHub
parent bc8df8f34e
commit 7b2b49dd53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 63 deletions

View file

@ -347,27 +347,11 @@ public abstract class BillingEvent extends ImmutableObject
@Override
public VKey<OneTime> createVKey() {
return VKey.create(
getClass(),
parent.getParent().getName() + "/" + parent.getId() + "/" + getId(),
Key.create(this));
return VKey.create(getClass(), getId(), Key.create(this));
}
public static VKey<OneTime> createVKey(Key<OneTime> key) {
// TODO(b/159207551): As it stands, the SQL key generated here doesn't mesh with the primary
// key type for the table, which is a single long integer.
if (key == null) {
return null;
}
Key parent = key.getParent();
Key grandparent = (parent != null) ? parent.getParent() : null;
String path =
(grandparent != null ? grandparent.getName() : "")
+ "/"
+ (parent != null ? parent.getId() : "")
+ "/"
+ key.getId();
return VKey.create(OneTime.class, path, key);
return VKey.create(OneTime.class, key.getId(), key);
}
@Override
@ -505,21 +489,11 @@ public abstract class BillingEvent extends ImmutableObject
@Override
public VKey<Recurring> createVKey() {
return VKey.create(
getClass(),
parent.getParent().getName() + "/" + parent.getId() + "/" + getId(),
Key.create(this));
return VKey.create(getClass(), getId(), Key.create(this));
}
public static VKey<Recurring> createVKey(Key<Recurring> key) {
// TODO(b/159207551): As it stands, the SQL key generated here doesn't mesh with the primary
// key type for the table, which is a single long integer.
if (key == null) {
return null;
}
String path =
key.getParent().getParent().getName() + "/" + key.getParent().getId() + "/" + key.getId();
return VKey.create(Recurring.class, path, key);
return VKey.create(Recurring.class, key.getId(), key);
}
@Override
@ -639,21 +613,11 @@ public abstract class BillingEvent extends ImmutableObject
@Override
public VKey<Cancellation> createVKey() {
return VKey.create(
getClass(),
parent.getParent().getName() + "/" + parent.getId() + "/" + getId(),
Key.create(this));
return VKey.create(getClass(), getId(), Key.create(this));
}
public static VKey<Cancellation> createVKey(Key<Cancellation> key) {
// TODO(b/159207551): As it stands, the SQL key generated here doesn't mesh with the primary
// key type for the table, which is a single long integer.
if (key == null) {
return null;
}
String path =
key.getParent().getParent().getName() + "/" + key.getParent().getId() + "/" + key.getId();
return VKey.create(Cancellation.class, path, key);
return VKey.create(Cancellation.class, key.getId(), key);
}
@Override
@ -733,21 +697,11 @@ public abstract class BillingEvent extends ImmutableObject
@Override
public VKey<Modification> createVKey() {
return VKey.create(
getClass(),
parent.getParent().getName() + "/" + parent.getId() + "/" + getId(),
Key.create(this));
return VKey.create(getClass(), getId(), Key.create(this));
}
public static VKey<Modification> createVKey(Key<Modification> key) {
// TODO(b/159207551): As it stands, the SQL key generated here doesn't mesh with the primary
// key type for the table, which is a single long integer.
if (key == null) {
return null;
}
String path =
key.getParent().getParent().getName() + "/" + key.getParent().getId() + "/" + key.getId();
return VKey.create(Modification.class, path, key);
return VKey.create(Modification.class, key.getId(), key);
}
/**

View file

@ -155,15 +155,7 @@ public abstract class PollMessage extends ImmutableObject
public abstract VKey<? extends PollMessage> createVKey();
public static VKey<PollMessage> createVKey(Key<PollMessage> key) {
// TODO(b/159207551): As it stands, the SQL key generated here doesn't mesh with the primary key
// type for the table, which is a single long integer. Also note that the class id is not
// correct here and as such the resulting key will not be loadable from SQL.
if (key == null) {
return null;
}
String path =
key.getParent().getParent().getName() + "/" + key.getParent().getId() + key.getId();
return VKey.create(PollMessage.class, path, key);
return VKey.create(PollMessage.class, key.getId(), key);
}
/** Override Buildable.asBuilder() to give this method stronger typing. */