Fix optional access for VKey nested keys (#539)

* Fix optional access for VKey nested keys

We should have used ofNullable() instead of of() for key creation.  Also add a
unit test.
This commit is contained in:
Michael Muller
2020-03-30 11:01:25 -04:00
committed by GitHub
parent fa9134328a
commit 7880aab386
2 changed files with 47 additions and 7 deletions
@@ -41,11 +41,6 @@ public class VKey<T> extends ImmutableObject {
this.primaryKey = primaryKey;
}
public static <T> VKey<T> create(
Class<? extends T> kind, com.googlecode.objectify.Key<T> ofyKey, Object primaryKey) {
return new VKey(kind, ofyKey, primaryKey);
}
public static <T> VKey<T> createSql(Class<? extends T> kind, Object primaryKey) {
return new VKey(kind, null, primaryKey);
}
@@ -72,7 +67,7 @@ public class VKey<T> extends ImmutableObject {
/** Returns the SQL primary key if it exists. */
public Optional<Object> maybeGetSqlKey() {
return Optional.of(this.primaryKey);
return Optional.ofNullable(this.primaryKey);
}
/** Returns the objectify key. */
@@ -83,6 +78,6 @@ public class VKey<T> extends ImmutableObject {
/** Returns the objectify key if it exists. */
public Optional<com.googlecode.objectify.Key<T>> maybeGetOfyKey() {
return Optional.of(this.ofyKey);
return Optional.ofNullable(this.ofyKey);
}
}