1
0
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:
Weimin Yu
2024-09-20 11:16:52 -04:00
committed by GitHub
parent e167b4b753
commit 4ba0f4a2cd
9 changed files with 31 additions and 29 deletions

View File

@@ -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();

View File

@@ -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) {

View File

@@ -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() {

View File

@@ -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)

View File

@@ -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)));
}
/**

View File

@@ -172,8 +172,6 @@ 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(
@@ -184,7 +182,6 @@ public class RegistrarPocBase extends ImmutableObject implements Jsonifiable, Un
.executeUpdate();
tm().putAll(contacts);
});
}
public String getName() {

View File

@@ -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),

View File

@@ -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));
}
/**

View File

@@ -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,6 +50,8 @@ class RegistrarPocCommandTest extends CommandTestCase<RegistrarPocCommand> {
@Test
void testList() throws Exception {
Registrar registrar = loadRegistrar("NewRegistrar");
tm().transact(
() ->
RegistrarPoc.updateContacts(
registrar,
ImmutableSet.of(
@@ -58,7 +61,7 @@ class RegistrarPocCommandTest extends CommandTestCase<RegistrarPocCommand> {
.setEmailAddress("john.doe@example.com")
.setTypes(ImmutableSet.of(ADMIN))
.setVisibleInWhoisAsAdmin(true)
.build()));
.build())));
runCommandForced("--mode=LIST", "--output=" + output, "NewRegistrar");
assertThat(Files.readAllLines(Paths.get(output), UTF_8))
.containsExactly(