mirror of
https://github.com/google/nomulus.git
synced 2025-06-24 21:40:57 +02:00
Maintain only one row in the TmchCrl table at all times (#869)
* Maintain only one row in the TmchCrl table at all times
This commit is contained in:
parent
03c246d08d
commit
37df43694f
2 changed files with 27 additions and 1 deletions
|
@ -77,7 +77,16 @@ public final class TmchCrl extends CrossTldSingleton implements DatastoreEntity,
|
||||||
tmchCrl.crl = checkNotNull(crl, "crl");
|
tmchCrl.crl = checkNotNull(crl, "crl");
|
||||||
tmchCrl.url = checkNotNull(url, "url");
|
tmchCrl.url = checkNotNull(url, "url");
|
||||||
ofyTm().transactNew(() -> ofyTm().putWithoutBackup(tmchCrl));
|
ofyTm().transactNew(() -> ofyTm().putWithoutBackup(tmchCrl));
|
||||||
jpaTm().transactNew(() -> jpaTm().putWithoutBackup(tmchCrl));
|
jpaTm()
|
||||||
|
.transactNew(
|
||||||
|
() -> {
|
||||||
|
// Delete the old one and insert the new one
|
||||||
|
jpaTm()
|
||||||
|
.getEntityManager()
|
||||||
|
.createQuery("DELETE FROM TmchCrl")
|
||||||
|
.executeUpdate();
|
||||||
|
jpaTm().putWithoutBackup(tmchCrl);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,23 @@ public class TmchCrlTest extends EntityTestCase {
|
||||||
assertThat(loadFromSql()).isEqualTo(expected);
|
assertThat(loadFromSql()).isEqualTo(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testMultipleWrites() {
|
||||||
|
TmchCrl.set("first", "https://first.cat");
|
||||||
|
assertThat(TmchCrl.get().get().getCrl()).isEqualTo("first");
|
||||||
|
TmchCrl.set("second", "https://second.cat");
|
||||||
|
assertThat(TmchCrl.get().get().getCrl()).isEqualTo("second");
|
||||||
|
jpaTm()
|
||||||
|
.transact(
|
||||||
|
() ->
|
||||||
|
assertThat(
|
||||||
|
jpaTm()
|
||||||
|
.getEntityManager()
|
||||||
|
.createQuery("SELECT COUNT(*) FROM TmchCrl", Long.class)
|
||||||
|
.getSingleResult())
|
||||||
|
.isEqualTo(1L));
|
||||||
|
}
|
||||||
|
|
||||||
private static TmchCrl loadFromSql() {
|
private static TmchCrl loadFromSql() {
|
||||||
return jpaTm()
|
return jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue