mirror of
https://github.com/google/nomulus.git
synced 2025-07-21 18:26:12 +02:00
Refactor Guava functional methods to use lambdas
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=177027488
This commit is contained in:
parent
2ae496bfce
commit
bbe2584da4
47 changed files with 478 additions and 647 deletions
|
@ -32,7 +32,6 @@ import com.google.common.collect.ImmutableMap;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.google.common.net.InternetDomainName;
|
||||
import com.googlecode.objectify.Work;
|
||||
import google.registry.model.registry.Registry.TldType;
|
||||
import java.util.Optional;
|
||||
|
||||
|
@ -55,17 +54,14 @@ public final class Registries {
|
|||
() ->
|
||||
ofy()
|
||||
.doTransactionless(
|
||||
new Work<ImmutableMap<String, TldType>>() {
|
||||
@Override
|
||||
public ImmutableMap<String, TldType> run() {
|
||||
ImmutableMap.Builder<String, TldType> builder =
|
||||
new ImmutableMap.Builder<>();
|
||||
for (Registry registry :
|
||||
ofy().load().type(Registry.class).ancestor(getCrossTldKey())) {
|
||||
builder.put(registry.getTldStr(), registry.getTldType());
|
||||
}
|
||||
return builder.build();
|
||||
() -> {
|
||||
ImmutableMap.Builder<String, TldType> builder =
|
||||
new ImmutableMap.Builder<>();
|
||||
for (Registry registry :
|
||||
ofy().load().type(Registry.class).ancestor(getCrossTldKey())) {
|
||||
builder.put(registry.getTldStr(), registry.getTldType());
|
||||
}
|
||||
return builder.build();
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,6 @@ import com.google.common.collect.Ordering;
|
|||
import com.google.common.collect.Range;
|
||||
import com.google.common.net.InternetDomainName;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.Work;
|
||||
import com.googlecode.objectify.annotation.Embed;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.Id;
|
||||
|
@ -245,15 +244,10 @@ public class Registry extends ImmutableObject implements Buildable {
|
|||
return Optional.ofNullable(
|
||||
ofy()
|
||||
.doTransactionless(
|
||||
new Work<Registry>() {
|
||||
@Override
|
||||
public Registry run() {
|
||||
return ofy()
|
||||
.load()
|
||||
.key(Key.create(getCrossTldKey(), Registry.class, tld))
|
||||
.now();
|
||||
}
|
||||
}));
|
||||
() -> ofy()
|
||||
.load()
|
||||
.key(Key.create(getCrossTldKey(), Registry.class, tld))
|
||||
.now()));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -37,7 +37,6 @@ import com.google.common.collect.ImmutableSet;
|
|||
import com.google.common.collect.Streams;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import com.googlecode.objectify.Work;
|
||||
import google.registry.model.registry.Registry;
|
||||
import google.registry.model.registry.label.DomainLabelMetrics.PremiumListCheckOutcome;
|
||||
import google.registry.model.registry.label.PremiumList.PremiumListEntry;
|
||||
|
@ -162,28 +161,26 @@ public final class PremiumListUtils {
|
|||
}
|
||||
|
||||
// Save the new PremiumList and revision itself.
|
||||
PremiumList updated = ofy().transactNew(new Work<PremiumList>() {
|
||||
@Override
|
||||
public PremiumList run() {
|
||||
DateTime now = ofy().getTransactionTime();
|
||||
// Assert that the premium list hasn't been changed since we started this process.
|
||||
PremiumList existing = ofy().load()
|
||||
.type(PremiumList.class)
|
||||
.parent(getCrossTldKey())
|
||||
.id(premiumList.getName())
|
||||
.now();
|
||||
checkState(
|
||||
Objects.equals(existing, oldPremiumList.orElse(null)),
|
||||
"PremiumList was concurrently edited");
|
||||
PremiumList newList = premiumList.asBuilder()
|
||||
.setLastUpdateTime(now)
|
||||
.setCreationTime(
|
||||
oldPremiumList.isPresent() ? oldPremiumList.get().creationTime : now)
|
||||
.setRevision(newRevisionKey)
|
||||
.build();
|
||||
ofy().save().entities(newList, newRevision);
|
||||
return newList;
|
||||
}});
|
||||
PremiumList updated = ofy().transactNew(() -> {
|
||||
DateTime now = ofy().getTransactionTime();
|
||||
// Assert that the premium list hasn't been changed since we started this process.
|
||||
PremiumList existing = ofy().load()
|
||||
.type(PremiumList.class)
|
||||
.parent(getCrossTldKey())
|
||||
.id(premiumList.getName())
|
||||
.now();
|
||||
checkState(
|
||||
Objects.equals(existing, oldPremiumList.orElse(null)),
|
||||
"PremiumList was concurrently edited");
|
||||
PremiumList newList = premiumList.asBuilder()
|
||||
.setLastUpdateTime(now)
|
||||
.setCreationTime(
|
||||
oldPremiumList.isPresent() ? oldPremiumList.get().creationTime : now)
|
||||
.setRevision(newRevisionKey)
|
||||
.build();
|
||||
ofy().save().entities(newList, newRevision);
|
||||
return newList;
|
||||
});
|
||||
// Update the cache.
|
||||
cachePremiumLists.put(premiumList.getName(), updated);
|
||||
// Delete the entities under the old PremiumList.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue