Class EppResourceUtils


  • public final class EppResourceUtils
    extends java.lang.Object
    Utilities for working with EppResource.
    • Method Detail

      • createDomainRepoId

        public static java.lang.String createDomainRepoId​(long repoId,
                                                          java.lang.String tld)
        Returns the full domain repoId in the format HEX-TLD for the specified long id and tld.
      • createRepoId

        public static java.lang.String createRepoId​(long repoId,
                                                    java.lang.String roidSuffix)
        Returns the full repoId in the format HEX-TLD for the specified long id and ROID suffix.
      • loadByForeignKey

        public static <T extends EppResource> java.util.Optional<T> loadByForeignKey​(java.lang.Class<T> clazz,
                                                                                     java.lang.String foreignKey,
                                                                                     org.joda.time.DateTime now)
        Loads the last created version of an EppResource from the database by foreign key.

        Returns empty if no resource with this foreign key was ever created, or if the most recently created resource was deleted before time "now".

        Loading an EppResource by itself is not sufficient to know its current state since it may have various expirable conditions and status values that might implicitly change its state as time progresses even if it has not been updated in the database. Rather, the resource must be combined with a timestamp to view its current state. We use a global last updated timestamp on the resource's entity group (which is essentially free since all writes to the entity group must be serialized anyways) to guarantee monotonically increasing write times, and forward our projected time to the greater of this timestamp or "now". This guarantees that we're not projecting into the past.

        Parameters:
        clazz - the resource type to load
        foreignKey - id to match
        now - the current logical time to project resources at
      • loadByForeignKeyCached

        public static <T extends EppResource> java.util.Optional<T> loadByForeignKeyCached​(java.lang.Class<T> clazz,
                                                                                           java.lang.String foreignKey,
                                                                                           org.joda.time.DateTime now)
        Loads the last created version of an EppResource from the database by foreign key, using a cache.

        Returns null if no resource with this foreign key was ever created, or if the most recently created resource was deleted before time "now".

        Loading an EppResource by itself is not sufficient to know its current state since it may have various expirable conditions and status values that might implicitly change its state as time progresses even if it has not been updated in the database. Rather, the resource must be combined with a timestamp to view its current state. We use a global last updated timestamp to guarantee monotonically increasing write times, and forward our projected time to the greater of this timestamp or "now". This guarantees that we're not projecting into the past.

        Do not call this cached version for anything that needs transactional consistency. It should only be used when it's OK if the data is potentially being out of date, e.g. WHOIS.

        Parameters:
        clazz - the resource type to load
        foreignKey - id to match
        now - the current logical time to project resources at
      • checkResourcesExist

        public static <T extends EppResource> com.google.common.collect.ImmutableSet<java.lang.String> checkResourcesExist​(java.lang.Class<T> clazz,
                                                                                                                           java.util.Collection<java.lang.String> uniqueIds,
                                                                                                                           org.joda.time.DateTime now)
        Checks multiple EppResource objects from the database by unique ids.

        There are currently no resources that support checks and do not use foreign keys. If we need to support that case in the future, we can loosen the type to allow any EppResource and add code to do the lookup by id directly.

        Parameters:
        clazz - the resource type to load
        uniqueIds - a list of ids to match
        now - the logical time of the check
      • transformAtTime

        public static <T extends EppResource> java.util.function.Function<T,​T> transformAtTime​(org.joda.time.DateTime now)
        Returns a Function that transforms an EppResource to the given DateTime, suitable for use with Iterables.transform() over a collection of EppResources.
      • isActive

        public static boolean isActive​(EppResource resource,
                                       org.joda.time.DateTime time)
      • isDeleted

        public static boolean isDeleted​(EppResource resource,
                                        org.joda.time.DateTime time)
      • loadAtPointInTime

        public static <T extends EppResource> T loadAtPointInTime​(T resource,
                                                                  org.joda.time.DateTime timestamp)
        Rewinds an EppResource object to a given point in time.

        This method costs nothing if resource is already current. Otherwise, it needs to perform a single fetch operation.

        Warning: A resource can only be rolled backwards in time, not forwards; therefore resource should be whatever's currently in SQL.

        Returns:
        the resource at timestamp or null if resource is deleted or not yet created
      • loadAtPointInTimeAsync

        public static <T extends EppResource> java.util.function.Supplier<T> loadAtPointInTimeAsync​(T resource,
                                                                                                    org.joda.time.DateTime timestamp)
        Rewinds an EppResource object to a given point in time.

        This method costs nothing if resource is already current. Otherwise, it returns an async operation that performs a single fetch operation.

        Returns:
        an asynchronous operation returning resource at timestamp or null if resource is deleted or not yet created
        See Also:
        loadAtPointInTime(EppResource, DateTime)
      • getLinkedDomainKeys

        public static com.google.common.collect.ImmutableSet<VKey<Domain>> getLinkedDomainKeys​(VKey<? extends EppResource> key,
                                                                                               org.joda.time.DateTime now,
                                                                                               @Nullable
                                                                                               java.lang.Integer limit)
        Returns a set of VKey for domains that reference a specified contact or host.

        This is an eventually consistent query if used for the database.

        Parameters:
        key - the referent key
        now - the logical time of the check
        limit - the maximum number of returned keys, unlimited if null
      • isLinked

        public static boolean isLinked​(VKey<? extends EppResource> key,
                                       org.joda.time.DateTime now)
        Returns whether the given contact or host is linked to (that is, referenced by) a domain.

        This is an eventually consistent query.

        Parameters:
        key - the referent key
        now - the logical time of the check