mirror of
https://github.com/google/nomulus
synced 2026-09-09 17:46:18 +00:00
Use the replica jpaTm in FKI and EppResource cache methods (#1503)
The cached methods are only used in situations where we don't really care about being 100% synchronously up to date (e.g. whois), and they're not used frequently anyway, so it's safe to use the replica in these locations.
This commit is contained in:
+3
@@ -217,11 +217,14 @@ abstract class JpaTransactionManagerExtension implements BeforeEachCallback, Aft
|
||||
JpaTransactionManagerImpl txnManager = new JpaTransactionManagerImpl(emf, clock);
|
||||
cachedTm = TransactionManagerFactory.jpaTm();
|
||||
TransactionManagerFactory.setJpaTm(Suppliers.ofInstance(txnManager));
|
||||
TransactionManagerFactory.setReplicaJpaTm(
|
||||
Suppliers.ofInstance(new ReplicaSimulatingJpaTransactionManager(txnManager)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterEach(ExtensionContext context) {
|
||||
TransactionManagerFactory.setJpaTm(Suppliers.ofInstance(cachedTm));
|
||||
TransactionManagerFactory.setReplicaJpaTm(Suppliers.ofInstance(cachedTm));
|
||||
// Even though we didn't set this, reset it to make sure no other tests are affected
|
||||
JpaTransactionManagerImpl.removeReplaySqlToDsOverrideForTest();
|
||||
cachedTm = null;
|
||||
|
||||
+7
-1
@@ -91,9 +91,15 @@ public class ReplicaSimulatingJpaTransactionManager implements JpaTransactionMan
|
||||
|
||||
@Override
|
||||
public <T> T transact(Supplier<T> work) {
|
||||
if (delegate.inTransaction()) {
|
||||
return work.get();
|
||||
}
|
||||
return delegate.transact(
|
||||
() -> {
|
||||
delegate.getEntityManager().createQuery("SET TRANSACTION READ ONLY").executeUpdate();
|
||||
delegate
|
||||
.getEntityManager()
|
||||
.createNativeQuery("SET TRANSACTION READ ONLY")
|
||||
.executeUpdate();
|
||||
return work.get();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user