mirror of
https://github.com/google/nomulus
synced 2025-12-23 06:15:42 +00:00
Change nested transact calls to retransact (#2563)
This commit is contained in:
@@ -177,8 +177,9 @@ public class AllocationTokenFlowUtils {
|
||||
return maybeTokenEntity.get();
|
||||
}
|
||||
|
||||
// TODO(b/368069206): `reTransact` needed by tests only.
|
||||
maybeTokenEntity =
|
||||
tm().transact(() -> tm().loadByKeyIfPresent(VKey.create(AllocationToken.class, token)));
|
||||
tm().reTransact(() -> tm().loadByKeyIfPresent(VKey.create(AllocationToken.class, token)));
|
||||
|
||||
if (maybeTokenEntity.isEmpty()) {
|
||||
throw new InvalidAllocationTokenException();
|
||||
|
||||
@@ -345,7 +345,7 @@ public final class EppResourceUtils {
|
||||
"key must be either VKey<Contact> or VKey<Host>, but it is %s",
|
||||
key);
|
||||
boolean isContactKey = key.getKind().equals(Contact.class);
|
||||
return tm().transact(
|
||||
return tm().reTransact(
|
||||
() -> {
|
||||
Query query;
|
||||
if (isContactKey) {
|
||||
|
||||
@@ -82,7 +82,7 @@ public class FeatureFlag extends ImmutableObject implements Buildable {
|
||||
TimedTransitionProperty.withInitialValue(FeatureStatus.INACTIVE);
|
||||
|
||||
public static Optional<FeatureFlag> getUncached(FeatureName featureName) {
|
||||
return tm().transact(() -> tm().loadByKeyIfPresent(createVKey(featureName)));
|
||||
return tm().reTransact(() -> tm().loadByKeyIfPresent(createVKey(featureName)));
|
||||
}
|
||||
|
||||
public static ImmutableList<FeatureFlag> getAllUncached() {
|
||||
|
||||
@@ -579,7 +579,7 @@ public class DomainBase extends EppResource
|
||||
|
||||
/** Loads and returns the fully qualified host names of all linked nameservers. */
|
||||
public ImmutableSortedSet<String> loadNameserverHostNames() {
|
||||
return tm().transact(
|
||||
return tm().reTransact(
|
||||
() ->
|
||||
tm().loadByKeys(getNameservers()).values().stream()
|
||||
.map(Host::getHostName)
|
||||
|
||||
@@ -1014,7 +1014,7 @@ public class RegistrarBase extends UpdateAutoTimestampEntity implements Buildabl
|
||||
/** Loads and returns a registrar entity by its id directly from the database. */
|
||||
public static Optional<Registrar> loadByRegistrarId(String registrarId) {
|
||||
checkArgument(!Strings.isNullOrEmpty(registrarId), "registrarId must be specified");
|
||||
return tm().transact(() -> tm().loadByKeyIfPresent(createVKey(registrarId)));
|
||||
return tm().reTransact(() -> tm().loadByKeyIfPresent(createVKey(registrarId)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -172,19 +172,16 @@ public class RegistrarPocBase extends ImmutableObject implements Jsonifiable, Un
|
||||
*/
|
||||
public static void updateContacts(
|
||||
final Registrar registrar, final ImmutableSet<RegistrarPoc> contacts) {
|
||||
tm().transact(
|
||||
() -> {
|
||||
ImmutableSet<String> emailAddressesToKeep =
|
||||
contacts.stream().map(RegistrarPoc::getEmailAddress).collect(toImmutableSet());
|
||||
tm().query(
|
||||
"DELETE FROM RegistrarPoc WHERE registrarId = :registrarId AND "
|
||||
+ "emailAddress NOT IN :emailAddressesToKeep")
|
||||
.setParameter("registrarId", registrar.getRegistrarId())
|
||||
.setParameter("emailAddressesToKeep", emailAddressesToKeep)
|
||||
.executeUpdate();
|
||||
ImmutableSet<String> emailAddressesToKeep =
|
||||
contacts.stream().map(RegistrarPoc::getEmailAddress).collect(toImmutableSet());
|
||||
tm().query(
|
||||
"DELETE FROM RegistrarPoc WHERE registrarId = :registrarId AND "
|
||||
+ "emailAddress NOT IN :emailAddressesToKeep")
|
||||
.setParameter("registrarId", registrar.getRegistrarId())
|
||||
.setParameter("emailAddressesToKeep", emailAddressesToKeep)
|
||||
.executeUpdate();
|
||||
|
||||
tm().putAll(contacts);
|
||||
});
|
||||
tm().putAll(contacts);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
||||
@@ -118,7 +118,7 @@ public class HistoryEntryDao {
|
||||
/** Loads all history objects from all time from the given registrars. */
|
||||
public static Iterable<HistoryEntry> loadHistoryObjectsByRegistrars(
|
||||
ImmutableCollection<String> registrarIds) {
|
||||
return tm().transact(
|
||||
return tm().reTransact(
|
||||
() ->
|
||||
Streams.concat(
|
||||
loadHistoryObjectByRegistrarsInternal(ContactHistory.class, registrarIds),
|
||||
|
||||
@@ -39,7 +39,8 @@ public final class TmchCrl extends CrossTldSingleton {
|
||||
|
||||
/** Returns the singleton instance of this entity, without memoization. */
|
||||
public static Optional<TmchCrl> get() {
|
||||
return tm().transact(() -> tm().loadSingleton(TmchCrl.class));
|
||||
// TODO(b/368069206): move transaction up to `TmchCertificateAuthority#updateCrl`
|
||||
return tm().reTransact(() -> tm().loadSingleton(TmchCrl.class));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,6 +19,7 @@ import static google.registry.model.registrar.RegistrarPocBase.Type.ABUSE;
|
||||
import static google.registry.model.registrar.RegistrarPocBase.Type.ADMIN;
|
||||
import static google.registry.model.registrar.RegistrarPocBase.Type.TECH;
|
||||
import static google.registry.model.registrar.RegistrarPocBase.Type.WHOIS;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static google.registry.testing.DatabaseHelper.loadRegistrar;
|
||||
import static google.registry.testing.DatabaseHelper.persistResource;
|
||||
import static google.registry.testing.DatabaseHelper.persistSimpleResource;
|
||||
@@ -49,16 +50,18 @@ class RegistrarPocCommandTest extends CommandTestCase<RegistrarPocCommand> {
|
||||
@Test
|
||||
void testList() throws Exception {
|
||||
Registrar registrar = loadRegistrar("NewRegistrar");
|
||||
RegistrarPoc.updateContacts(
|
||||
registrar,
|
||||
ImmutableSet.of(
|
||||
new RegistrarPoc.Builder()
|
||||
.setRegistrar(registrar)
|
||||
.setName("John Doe")
|
||||
.setEmailAddress("john.doe@example.com")
|
||||
.setTypes(ImmutableSet.of(ADMIN))
|
||||
.setVisibleInWhoisAsAdmin(true)
|
||||
.build()));
|
||||
tm().transact(
|
||||
() ->
|
||||
RegistrarPoc.updateContacts(
|
||||
registrar,
|
||||
ImmutableSet.of(
|
||||
new RegistrarPoc.Builder()
|
||||
.setRegistrar(registrar)
|
||||
.setName("John Doe")
|
||||
.setEmailAddress("john.doe@example.com")
|
||||
.setTypes(ImmutableSet.of(ADMIN))
|
||||
.setVisibleInWhoisAsAdmin(true)
|
||||
.build())));
|
||||
runCommandForced("--mode=LIST", "--output=" + output, "NewRegistrar");
|
||||
assertThat(Files.readAllLines(Paths.get(output), UTF_8))
|
||||
.containsExactly(
|
||||
|
||||
Reference in New Issue
Block a user