mirror of
https://github.com/google/nomulus.git
synced 2025-07-20 01:35:59 +02:00
Remove a couple additional ofy() calls (#1171)
* Remove a couple additional ofy() calls
This commit is contained in:
parent
2f2e9dd49f
commit
20a0e4ce3f
3 changed files with 25 additions and 26 deletions
|
@ -16,7 +16,7 @@ package google.registry.model;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||||
|
|
||||||
import google.registry.model.ofy.ObjectifyService;
|
import google.registry.model.ofy.ObjectifyService;
|
||||||
import google.registry.util.TypeUtils.TypeInstantiator;
|
import google.registry.util.TypeUtils.TypeInstantiator;
|
||||||
|
@ -57,8 +57,14 @@ public interface Buildable {
|
||||||
// If this object has a Long or long Objectify @Id field that is not set, set it now.
|
// If this object has a Long or long Objectify @Id field that is not set, set it now.
|
||||||
Field idField = null;
|
Field idField = null;
|
||||||
try {
|
try {
|
||||||
idField = ModelUtils.getAllFields(instance.getClass()).get(
|
idField =
|
||||||
ofy().factory().getMetadata(instance.getClass()).getKeyMetadata().getIdFieldName());
|
ModelUtils.getAllFields(instance.getClass())
|
||||||
|
.get(
|
||||||
|
auditedOfy()
|
||||||
|
.factory()
|
||||||
|
.getMetadata(instance.getClass())
|
||||||
|
.getKeyMetadata()
|
||||||
|
.getIdFieldName());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Expected if the class is not registered with Objectify.
|
// Expected if the class is not registered with Objectify.
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ package google.registry.model.common;
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
|
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
|
||||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
|
||||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||||
|
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
|
@ -210,12 +209,7 @@ public class Cursor extends ImmutableObject implements DatastoreAndSqlEntity {
|
||||||
private static void checkValidCursorTypeForScope(
|
private static void checkValidCursorTypeForScope(
|
||||||
CursorType cursorType, Key<? extends ImmutableObject> scope) {
|
CursorType cursorType, Key<? extends ImmutableObject> scope) {
|
||||||
checkArgument(
|
checkArgument(
|
||||||
cursorType
|
cursorType.getScopeClass().getSimpleName().equals(scope.getKind()),
|
||||||
.getScopeClass()
|
|
||||||
.equals(
|
|
||||||
scope.equals(getCrossTldKey())
|
|
||||||
? EntityGroupRoot.class
|
|
||||||
: ofy().factory().getMetadata(scope).getEntityClass()),
|
|
||||||
"Class required for cursor does not match scope class");
|
"Class required for cursor does not match scope class");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,10 @@
|
||||||
|
|
||||||
package google.registry.model.poll;
|
package google.registry.model.poll;
|
||||||
|
|
||||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
import static com.google.common.collect.ImmutableMap.toImmutableMap;
|
||||||
|
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.collect.ImmutableBiMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.googlecode.objectify.Key;
|
import com.googlecode.objectify.Key;
|
||||||
import google.registry.model.EppResource;
|
import google.registry.model.EppResource;
|
||||||
import google.registry.model.contact.ContactResource;
|
import google.registry.model.contact.ContactResource;
|
||||||
|
@ -26,6 +26,7 @@ import google.registry.model.host.HostResource;
|
||||||
import google.registry.model.reporting.HistoryEntry;
|
import google.registry.model.reporting.HistoryEntry;
|
||||||
import google.registry.persistence.VKey;
|
import google.registry.persistence.VKey;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A converter between external key strings for {@link PollMessage}s (i.e. what registrars use to
|
* A converter between external key strings for {@link PollMessage}s (i.e. what registrars use to
|
||||||
|
@ -49,24 +50,23 @@ public class PollMessageExternalKeyConverter {
|
||||||
/** An exception thrown when an external key cannot be parsed. */
|
/** An exception thrown when an external key cannot be parsed. */
|
||||||
public static class PollMessageExternalKeyParseException extends RuntimeException {}
|
public static class PollMessageExternalKeyParseException extends RuntimeException {}
|
||||||
|
|
||||||
/**
|
/** Maps that detail the correspondence between EppResource classes and external IDs. */
|
||||||
* A map of IDs used in external keys corresponding to which EppResource class the poll message
|
private static final ImmutableMap<Long, Class<? extends EppResource>> ID_TO_CLASS_MAP =
|
||||||
* belongs to.
|
ImmutableMap.of(
|
||||||
*/
|
1L, DomainBase.class,
|
||||||
public static final ImmutableBiMap<Class<? extends EppResource>, Long> EXTERNAL_KEY_CLASS_ID_MAP =
|
2L, ContactResource.class,
|
||||||
ImmutableBiMap.of(
|
3L, HostResource.class);
|
||||||
DomainBase.class, 1L,
|
|
||||||
ContactResource.class, 2L,
|
private static final ImmutableMap<String, Long> KEY_KIND_TO_ID_MAP =
|
||||||
HostResource.class, 3L);
|
ID_TO_CLASS_MAP.entrySet().stream()
|
||||||
|
.collect(toImmutableMap(entry -> entry.getValue().getSimpleName(), Map.Entry::getKey));
|
||||||
|
|
||||||
/** Returns an external poll message ID for the given poll message. */
|
/** Returns an external poll message ID for the given poll message. */
|
||||||
public static String makePollMessageExternalId(PollMessage pollMessage) {
|
public static String makePollMessageExternalId(PollMessage pollMessage) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Key<EppResource> ancestorResource =
|
Key<EppResource> ancestorResource =
|
||||||
(Key<EppResource>) (Key<?>) pollMessage.getParentKey().getParent();
|
(Key<EppResource>) (Key<?>) pollMessage.getParentKey().getParent();
|
||||||
long externalKeyClassId =
|
long externalKeyClassId = KEY_KIND_TO_ID_MAP.get(ancestorResource.getKind());
|
||||||
EXTERNAL_KEY_CLASS_ID_MAP.get(
|
|
||||||
ofy().factory().getMetadata(ancestorResource.getKind()).getEntityClass());
|
|
||||||
return String.format(
|
return String.format(
|
||||||
"%d-%s-%d-%d-%d",
|
"%d-%s-%d-%d-%d",
|
||||||
externalKeyClassId,
|
externalKeyClassId,
|
||||||
|
@ -92,8 +92,7 @@ public class PollMessageExternalKeyConverter {
|
||||||
throw new PollMessageExternalKeyParseException();
|
throw new PollMessageExternalKeyParseException();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Class<?> resourceClazz =
|
Class<?> resourceClazz = ID_TO_CLASS_MAP.get(Long.parseLong(idComponents.get(0)));
|
||||||
EXTERNAL_KEY_CLASS_ID_MAP.inverse().get(Long.parseLong(idComponents.get(0)));
|
|
||||||
if (resourceClazz == null) {
|
if (resourceClazz == null) {
|
||||||
throw new PollMessageExternalKeyParseException();
|
throw new PollMessageExternalKeyParseException();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue