mirror of
https://github.com/google/nomulus.git
synced 2025-05-31 01:34:05 +02:00
Break out EppResourceInput subclasses
This frankenclass was starting to get a little cluttered, especially once I add the ChildEntityInput/Reader. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=117266882
This commit is contained in:
parent
57fa57968d
commit
77dd730400
31 changed files with 876 additions and 20 deletions
|
@ -0,0 +1,81 @@
|
|||
// Copyright 2016 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.domain.registry.mapreduce.inputs;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Predicates.not;
|
||||
import static com.google.common.collect.Iterables.all;
|
||||
import static com.google.common.collect.Lists.asList;
|
||||
import static com.google.domain.registry.util.TypeUtils.hasAnnotation;
|
||||
|
||||
import com.google.appengine.tools.mapreduce.Input;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.domain.registry.model.EppResource;
|
||||
import com.google.domain.registry.model.index.EppResourceIndex;
|
||||
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.annotation.EntitySubclass;
|
||||
|
||||
/**
|
||||
* Mapreduce helpers for {@link EppResource} keys and objects.
|
||||
*
|
||||
* <p>The inputs provided by this class are not deletion-aware and do not project the resources
|
||||
* forward in time. That is the responsibility of mappers that use these inputs.
|
||||
*/
|
||||
public final class EppResourceInputs {
|
||||
|
||||
private EppResourceInputs() {}
|
||||
|
||||
/** Returns a MapReduce {@link Input} that loads all {@link EppResourceIndex} objects. */
|
||||
public static <R extends EppResource> Input<EppResourceIndex> createIndexInput() {
|
||||
return new EppResourceIndexInput();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a MapReduce {@link Input} that loads all {@link EppResource} objects of a given type,
|
||||
* including deleted resources.
|
||||
*
|
||||
* <p>Note: Do not concatenate multiple EntityInputs together (this is inefficient as it iterates
|
||||
* through all buckets multiple times). Specify the types in a single input, or load all types by
|
||||
* specifying {@link EppResource} as the class.
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <R extends EppResource> Input<R> createEntityInput(
|
||||
Class<? extends R> resourceClass,
|
||||
Class<? extends R>... moreResourceClasses) {
|
||||
return new EppResourceEntityInput<R>(
|
||||
ImmutableSet.copyOf(asList(resourceClass, moreResourceClasses)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a MapReduce {@link Input} that loads keys to all {@link EppResource} objects of a given
|
||||
* type, including deleted resources.
|
||||
*
|
||||
* <p>Note: Do not concatenate multiple KeyInputs together (this is inefficient as it iterates
|
||||
* through all buckets multiple times). Specify the types in a single input, or load all types by
|
||||
* specifying {@link EppResource} as the class.
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <R extends EppResource> Input<Key<R>> createKeyInput(
|
||||
Class<? extends R> resourceClass,
|
||||
Class<? extends R>... moreResourceClasses) {
|
||||
ImmutableSet<Class<? extends R>> resourceClasses =
|
||||
ImmutableSet.copyOf(asList(resourceClass, moreResourceClasses));
|
||||
checkArgument(
|
||||
all(resourceClasses, not(hasAnnotation(EntitySubclass.class))),
|
||||
"Mapping over keys requires a non-polymorphic Entity");
|
||||
return new EppResourceKeyInput<>(resourceClasses);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue