mirror of
https://github.com/google/nomulus.git
synced 2025-07-07 03:33:28 +02:00
Add a jpaTm().query(...) convenience method (#1023)
* Add a jpaTm().query(...) convenience method This replaces the more ungainly jpaTm().getEntityManager().createQuery(...). Note that this is in JpaTransactionManager, not the parent TransactionManager, because this is not an operation that Datastore can support. Once we finish migrating away from Datastore this won't matter anyway because JpaTransactionManager will be merged into TransactionManager and then deleted. In the process of writing this PR I discovered several other methods available on the EntityManager that may merit their own convenience methods if we start using them enough. The more commonly used ones will be addressed in subsequent PRs. They are: jpaTm().getEntityManager().getMetamodel().entity(...).getName() jpaTm().getEntityManager().getCriteriaBuilder().createQuery(...) jpaTm().getEntityManager().createNativeQuery(...) jpaTm().getEntityManager().find(...) This PR also addresses some existing callsites that were calling getEntityManager() rather than using extant convenience methods, such as jpa().insert(...).
This commit is contained in:
parent
de09994b36
commit
3159e663dc
57 changed files with 166 additions and 177 deletions
|
@ -71,8 +71,7 @@ public class ReservedListSqlDaoTest {
|
|||
() -> {
|
||||
ReservedList persistedList =
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery("FROM ReservedList WHERE name = :name", ReservedList.class)
|
||||
.query("FROM ReservedList WHERE name = :name", ReservedList.class)
|
||||
.setParameter("name", "testlist")
|
||||
.getSingleResult();
|
||||
assertThat(persistedList.getReservedListEntries())
|
||||
|
|
|
@ -74,8 +74,7 @@ public class ServerSecretTest extends EntityTestCase {
|
|||
.transact(
|
||||
() ->
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery("FROM ServerSecret", ServerSecret.class)
|
||||
.query("FROM ServerSecret", ServerSecret.class)
|
||||
.setMaxResults(1)
|
||||
.getResultStream()
|
||||
.findFirst()
|
||||
|
|
|
@ -149,10 +149,7 @@ public class SignedMarkRevocationListTest {
|
|||
}
|
||||
jpaTm()
|
||||
.transact(
|
||||
() ->
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.persist(SignedMarkRevocationList.create(clock.nowUtc(), revokes.build())));
|
||||
() -> jpaTm().insert(SignedMarkRevocationList.create(clock.nowUtc(), revokes.build())));
|
||||
RuntimeException thrown =
|
||||
assertThrows(RuntimeException.class, () -> SignedMarkRevocationList.get());
|
||||
assertThat(thrown).hasMessageThat().contains("Unequal SignedMarkRevocationList detected:");
|
||||
|
|
|
@ -57,10 +57,7 @@ public class TmchCrlTest extends EntityTestCase {
|
|||
.transact(
|
||||
() ->
|
||||
assertThat(
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery("SELECT COUNT(*) FROM TmchCrl", Long.class)
|
||||
.getSingleResult())
|
||||
jpaTm().query("SELECT COUNT(*) FROM TmchCrl", Long.class).getSingleResult())
|
||||
.isEqualTo(1L));
|
||||
}
|
||||
|
||||
|
@ -69,8 +66,7 @@ public class TmchCrlTest extends EntityTestCase {
|
|||
.transact(
|
||||
() ->
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery("FROM TmchCrl", TmchCrl.class)
|
||||
.query("FROM TmchCrl", TmchCrl.class)
|
||||
.setMaxResults(1)
|
||||
.getResultStream()
|
||||
.findFirst()
|
||||
|
|
|
@ -74,7 +74,7 @@ class EntityCallbacksListenerTest {
|
|||
.transact(
|
||||
() -> {
|
||||
TestEntity removed = jpaTm().loadByKey(VKey.createSql(TestEntity.class, "id"));
|
||||
jpaTm().getEntityManager().remove(removed);
|
||||
jpaTm().delete(removed);
|
||||
return removed;
|
||||
});
|
||||
checkAll(testRemove, 0, 0, 1, 1);
|
||||
|
|
|
@ -59,7 +59,7 @@ public class AllocationTokenStatusTransitionConverterTest {
|
|||
TimedTransitionProperty.fromValueMap(values, TokenStatusTransition.class);
|
||||
AllocationTokenStatusTransitionConverterTestEntity testEntity =
|
||||
new AllocationTokenStatusTransitionConverterTestEntity(timedTransitionProperty);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
AllocationTokenStatusTransitionConverterTestEntity persisted =
|
||||
jpaTm()
|
||||
.transact(
|
||||
|
|
|
@ -54,7 +54,7 @@ public class BillingCostTransitionConverterTest {
|
|||
TimedTransitionProperty<Money, BillingCostTransition> timedTransitionProperty =
|
||||
TimedTransitionProperty.fromValueMap(values, BillingCostTransition.class);
|
||||
TestEntity testEntity = new TestEntity(timedTransitionProperty);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.timedTransitionProperty).containsExactlyEntriesIn(timedTransitionProperty);
|
||||
|
|
|
@ -41,7 +41,7 @@ class BloomFilterConverterTest {
|
|||
BloomFilter<String> bloomFilter = BloomFilter.create(stringFunnel(US_ASCII), 3);
|
||||
ImmutableSet.of("foo", "bar", "baz").forEach(bloomFilter::put);
|
||||
TestEntity entity = new TestEntity(bloomFilter);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(entity));
|
||||
jpaTm().transact(() -> jpaTm().insert(entity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.bloomFilter).isEqualTo(bloomFilter);
|
||||
|
|
|
@ -45,7 +45,7 @@ public class CidrAddressBlockListConverterTest {
|
|||
CidrAddressBlock.create("8000::/1"),
|
||||
CidrAddressBlock.create("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128"));
|
||||
TestEntity testEntity = new TestEntity(addresses);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.addresses).isEqualTo(addresses);
|
||||
|
|
|
@ -45,7 +45,7 @@ public class CreateAutoTimestampConverterTest {
|
|||
CreateAutoTimestamp ts = CreateAutoTimestamp.create(DateTime.parse("2019-09-9T11:39:00Z"));
|
||||
TestEntity ent = new TestEntity("myinst", ts);
|
||||
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(ent));
|
||||
jpaTm().transact(() -> jpaTm().insert(ent));
|
||||
TestEntity result =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "myinst"));
|
||||
assertThat(result).isEqualTo(new TestEntity("myinst", ts));
|
||||
|
@ -56,7 +56,7 @@ public class CreateAutoTimestampConverterTest {
|
|||
CreateAutoTimestamp ts = CreateAutoTimestamp.create(null);
|
||||
TestEntity ent = new TestEntity("autoinit", ts);
|
||||
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(ent));
|
||||
jpaTm().transact(() -> jpaTm().insert(ent));
|
||||
|
||||
TestEntity result =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "autoinit"));
|
||||
|
|
|
@ -48,7 +48,7 @@ public class CurrencyToBillingConverterTest {
|
|||
CurrencyUnit.of("CNY"),
|
||||
new BillingAccountEntry(CurrencyUnit.of("CNY"), "accountId2"));
|
||||
TestEntity testEntity = new TestEntity(currencyToBilling);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.currencyToBilling).containsExactlyEntriesIn(currencyToBilling);
|
||||
|
|
|
@ -39,7 +39,7 @@ public class CurrencyUnitConverterTest {
|
|||
@Test
|
||||
void roundTripConversion() {
|
||||
TestEntity entity = new TestEntity(CurrencyUnit.EUR);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(entity));
|
||||
jpaTm().transact(() -> jpaTm().insert(entity));
|
||||
assertThat(
|
||||
jpaTm()
|
||||
.transact(
|
||||
|
|
|
@ -69,7 +69,7 @@ public class DateTimeConverterTest {
|
|||
void converter_generatesTimestampWithNormalizedZone() {
|
||||
DateTime dt = parseDateTime("2019-09-01T01:01:01Z");
|
||||
TestEntity entity = new TestEntity("normalized_utc_time", dt);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(entity));
|
||||
jpaTm().transact(() -> jpaTm().insert(entity));
|
||||
TestEntity retrievedEntity =
|
||||
jpaTm()
|
||||
.transact(
|
||||
|
@ -82,7 +82,7 @@ public class DateTimeConverterTest {
|
|||
DateTime dt = parseDateTime("2019-09-01T01:01:01-05:00");
|
||||
TestEntity entity = new TestEntity("new_york_time", dt);
|
||||
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(entity));
|
||||
jpaTm().transact(() -> jpaTm().insert(entity));
|
||||
TestEntity retrievedEntity =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "new_york_time"));
|
||||
assertThat(retrievedEntity.dt.toString()).isEqualTo("2019-09-01T06:01:01.000Z");
|
||||
|
|
|
@ -71,7 +71,7 @@ public class JodaMoneyConverterTest {
|
|||
void roundTripConversion() {
|
||||
Money money = Money.of(CurrencyUnit.USD, 100);
|
||||
TestEntity entity = new TestEntity(money);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(entity));
|
||||
jpaTm().transact(() -> jpaTm().insert(entity));
|
||||
List<?> result =
|
||||
jpaTm()
|
||||
.transact(
|
||||
|
@ -101,7 +101,7 @@ public class JodaMoneyConverterTest {
|
|||
"dos", Money.ofMajor(CurrencyUnit.JPY, 2000),
|
||||
"tres", Money.of(CurrencyUnit.GBP, 20));
|
||||
ComplexTestEntity entity = new ComplexTestEntity(moneyMap, myMoney, yourMoney);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(entity));
|
||||
jpaTm().transact(() -> jpaTm().insert(entity));
|
||||
List<?> result =
|
||||
jpaTm()
|
||||
.transact(
|
||||
|
|
|
@ -46,7 +46,7 @@ public class LongVKeyConverterTest {
|
|||
new TestLongEntity(
|
||||
VKey.createSql(TestLongEntity.class, 10L),
|
||||
VKey.createSql(CompositeKeyTestLongEntity.class, 20L));
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(original));
|
||||
jpaTm().transact(() -> jpaTm().insert(original));
|
||||
|
||||
TestLongEntity retrieved =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestLongEntity.class, "id"));
|
||||
|
|
|
@ -67,7 +67,7 @@ class PremiumListKeyConverterTest {
|
|||
void testRoundTrip() {
|
||||
Key<PremiumList> key = Key.create(getCrossTldKey(), PremiumList.class, "test");
|
||||
PremiumListEntity testEntity = new PremiumListEntity(key);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
PremiumListEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(PremiumListEntity.class, "test"));
|
||||
assertThat(persisted.premiumList).isEqualTo(key);
|
||||
|
|
|
@ -47,7 +47,7 @@ class ReservedListKeySetConverterTest {
|
|||
|
||||
Set<Key<ReservedList>> reservedLists = ImmutableSet.of(key1, key2, key3);
|
||||
ReservedListSetEntity testEntity = new ReservedListSetEntity(reservedLists);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
ReservedListSetEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(ReservedListSetEntity.class, "id"));
|
||||
assertThat(persisted.reservedList).containsExactly(key1, key2, key3);
|
||||
|
@ -56,7 +56,7 @@ class ReservedListKeySetConverterTest {
|
|||
@Test
|
||||
void testNullValue_writesAndReadsNullSuccessfully() {
|
||||
ReservedListSetEntity testEntity = new ReservedListSetEntity(null);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
ReservedListSetEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(ReservedListSetEntity.class, "id"));
|
||||
assertThat(persisted.reservedList).isNull();
|
||||
|
@ -65,7 +65,7 @@ class ReservedListKeySetConverterTest {
|
|||
@Test
|
||||
void testEmptyCollection_writesAndReadsEmptyCollectionSuccessfully() {
|
||||
ReservedListSetEntity testEntity = new ReservedListSetEntity(ImmutableSet.of());
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
ReservedListSetEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(ReservedListSetEntity.class, "id"));
|
||||
assertThat(persisted.reservedList).isEmpty();
|
||||
|
|
|
@ -39,7 +39,7 @@ public class StatusValueSetConverterTest {
|
|||
Set<StatusValue> enums = ImmutableSet.of(StatusValue.INACTIVE, StatusValue.PENDING_DELETE);
|
||||
TestEntity obj = new TestEntity("foo", enums);
|
||||
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(obj));
|
||||
jpaTm().transact(() -> jpaTm().insert(obj));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "foo"));
|
||||
assertThat(persisted.data).isEqualTo(enums);
|
||||
|
|
|
@ -40,7 +40,7 @@ public class StringListConverterTest {
|
|||
void roundTripConversion_returnsSameStringList() {
|
||||
List<String> tlds = ImmutableList.of("app", "dev", "how");
|
||||
TestEntity testEntity = new TestEntity(tlds);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.tlds).containsExactly("app", "dev", "how");
|
||||
|
@ -50,7 +50,7 @@ public class StringListConverterTest {
|
|||
void testMerge_succeeds() {
|
||||
List<String> tlds = ImmutableList.of("app", "dev", "how");
|
||||
TestEntity testEntity = new TestEntity(tlds);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
persisted.tlds = ImmutableList.of("com", "gov");
|
||||
|
@ -63,7 +63,7 @@ public class StringListConverterTest {
|
|||
@Test
|
||||
void testNullValue_writesAndReadsNullSuccessfully() {
|
||||
TestEntity testEntity = new TestEntity(null);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.tlds).isNull();
|
||||
|
@ -72,7 +72,7 @@ public class StringListConverterTest {
|
|||
@Test
|
||||
void testEmptyCollection_writesAndReadsEmptyCollectionSuccessfully() {
|
||||
TestEntity testEntity = new TestEntity(ImmutableList.of());
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.tlds).isEmpty();
|
||||
|
|
|
@ -50,7 +50,7 @@ public class StringMapConverterBaseTest {
|
|||
@Test
|
||||
void roundTripConversion_returnsSameMap() {
|
||||
TestEntity testEntity = new TestEntity(MAP);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.map).containsExactlyEntriesIn(MAP);
|
||||
|
@ -59,7 +59,7 @@ public class StringMapConverterBaseTest {
|
|||
@Test
|
||||
void testUpdateColumn_succeeds() {
|
||||
TestEntity testEntity = new TestEntity(MAP);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.map).containsExactlyEntriesIn(MAP);
|
||||
|
@ -73,7 +73,7 @@ public class StringMapConverterBaseTest {
|
|||
@Test
|
||||
void testNullValue_writesAndReadsNullSuccessfully() {
|
||||
TestEntity testEntity = new TestEntity(null);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.map).isNull();
|
||||
|
@ -82,7 +82,7 @@ public class StringMapConverterBaseTest {
|
|||
@Test
|
||||
void testEmptyMap_writesAndReadsEmptyCollectionSuccessfully() {
|
||||
TestEntity testEntity = new TestEntity(ImmutableMap.of());
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.map).isEmpty();
|
||||
|
|
|
@ -38,7 +38,7 @@ public class StringSetConverterTest {
|
|||
void roundTripConversion_returnsSameStringList() {
|
||||
Set<String> tlds = ImmutableSet.of("app", "dev", "how");
|
||||
TestEntity testEntity = new TestEntity(tlds);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.tlds).containsExactly("app", "dev", "how");
|
||||
|
@ -47,7 +47,7 @@ public class StringSetConverterTest {
|
|||
@Test
|
||||
void testNullValue_writesAndReadsNullSuccessfully() {
|
||||
TestEntity testEntity = new TestEntity(null);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.tlds).isNull();
|
||||
|
@ -56,7 +56,7 @@ public class StringSetConverterTest {
|
|||
@Test
|
||||
void testEmptyCollection_writesAndReadsEmptyCollectionSuccessfully() {
|
||||
TestEntity testEntity = new TestEntity(ImmutableSet.of());
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.tlds).isEmpty();
|
||||
|
|
|
@ -47,7 +47,7 @@ public class StringVKeyConverterTest {
|
|||
"TheRealSpartacus",
|
||||
VKey.createSql(TestStringEntity.class, "ImSpartacus!"),
|
||||
VKey.createSql(CompositeKeyTestStringEntity.class, "NoImSpartacus!"));
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(original));
|
||||
jpaTm().transact(() -> jpaTm().insert(original));
|
||||
|
||||
TestStringEntity retrieved =
|
||||
jpaTm()
|
||||
|
|
|
@ -38,7 +38,7 @@ public class StringValueEnumeratedTest {
|
|||
@Test
|
||||
void roundTripConversion_returnsSameEnum() {
|
||||
TestEntity testEntity = new TestEntity(State.ACTIVE);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.state).isEqualTo(State.ACTIVE);
|
||||
|
@ -47,7 +47,7 @@ public class StringValueEnumeratedTest {
|
|||
@Test
|
||||
void testNativeQuery_succeeds() {
|
||||
TestEntity testEntity = new TestEntity(State.DISABLED);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
|
||||
assertThat(
|
||||
jpaTm()
|
||||
|
|
|
@ -60,7 +60,7 @@ class TimedTransitionPropertyConverterBaseTest {
|
|||
@Test
|
||||
void roundTripConversion_returnsSameTimedTransitionProperty() {
|
||||
TestEntity testEntity = new TestEntity(TIMED_TRANSITION_PROPERTY);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.property).containsExactlyEntriesIn(TIMED_TRANSITION_PROPERTY);
|
||||
|
@ -69,7 +69,7 @@ class TimedTransitionPropertyConverterBaseTest {
|
|||
@Test
|
||||
void testUpdateColumn_succeeds() {
|
||||
TestEntity testEntity = new TestEntity(TIMED_TRANSITION_PROPERTY);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.property).containsExactlyEntriesIn(TIMED_TRANSITION_PROPERTY);
|
||||
|
@ -84,7 +84,7 @@ class TimedTransitionPropertyConverterBaseTest {
|
|||
@Test
|
||||
void testNullValue_writesAndReadsNullSuccessfully() {
|
||||
TestEntity testEntity = new TestEntity(null);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.property).isNull();
|
||||
|
|
|
@ -57,7 +57,7 @@ class TldStateTransitionConverterTest {
|
|||
TimedTransitionProperty<TldState, TldStateTransition> timedTransitionProperty =
|
||||
TimedTransitionProperty.fromValueMap(values, TldStateTransition.class);
|
||||
TestEntity testEntity = new TestEntity(timedTransitionProperty);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.timedTransitionProperty).containsExactlyEntriesIn(timedTransitionProperty);
|
||||
|
|
|
@ -43,7 +43,7 @@ public class UpdateAutoTimestampConverterTest {
|
|||
void testTypeConversion() {
|
||||
TestEntity ent = new TestEntity("myinst", null);
|
||||
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(ent));
|
||||
jpaTm().transact(() -> jpaTm().insert(ent));
|
||||
|
||||
TestEntity result =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "myinst"));
|
||||
|
@ -56,7 +56,7 @@ public class UpdateAutoTimestampConverterTest {
|
|||
void testTimeChangesOnSubsequentTransactions() {
|
||||
TestEntity ent1 = new TestEntity("myinst1", null);
|
||||
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(ent1));
|
||||
jpaTm().transact(() -> jpaTm().insert(ent1));
|
||||
|
||||
TestEntity result1 =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "myinst1"));
|
||||
|
@ -65,7 +65,7 @@ public class UpdateAutoTimestampConverterTest {
|
|||
|
||||
TestEntity ent2 = new TestEntity("myinst2", result1.uat);
|
||||
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(ent2));
|
||||
jpaTm().transact(() -> jpaTm().insert(ent2));
|
||||
|
||||
TestEntity result2 =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "myinst2"));
|
||||
|
|
|
@ -66,7 +66,7 @@ public class ZonedDateTimeConverterTest {
|
|||
void converter_generatesTimestampWithNormalizedZone() {
|
||||
ZonedDateTime zdt = ZonedDateTime.parse("2019-09-01T01:01:01Z");
|
||||
TestEntity entity = new TestEntity("normalized_utc_time", zdt);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(entity));
|
||||
jpaTm().transact(() -> jpaTm().insert(entity));
|
||||
TestEntity retrievedEntity =
|
||||
jpaTm()
|
||||
.transact(
|
||||
|
@ -79,7 +79,7 @@ public class ZonedDateTimeConverterTest {
|
|||
ZonedDateTime zdt = ZonedDateTime.parse("2019-09-01T01:01:01Z[UTC]");
|
||||
TestEntity entity = new TestEntity("non_normalized_utc_time", zdt);
|
||||
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(entity));
|
||||
jpaTm().transact(() -> jpaTm().insert(entity));
|
||||
TestEntity retrievedEntity =
|
||||
jpaTm()
|
||||
.transact(
|
||||
|
@ -92,7 +92,7 @@ public class ZonedDateTimeConverterTest {
|
|||
ZonedDateTime zdt = ZonedDateTime.parse("2019-09-01T01:01:01+05:00");
|
||||
TestEntity entity = new TestEntity("new_york_time", zdt);
|
||||
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(entity));
|
||||
jpaTm().transact(() -> jpaTm().insert(entity));
|
||||
TestEntity retrievedEntity =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "new_york_time"));
|
||||
assertThat(retrievedEntity.zdt.toString()).isEqualTo("2019-08-31T20:01:01Z");
|
||||
|
|
|
@ -106,8 +106,7 @@ public class JpaEntityCoverageExtension implements BeforeEachCallback, AfterEach
|
|||
.transact(
|
||||
() ->
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery(
|
||||
.query(
|
||||
String.format("SELECT e FROM %s e", getJpaEntityName(entityType)),
|
||||
entityType)
|
||||
.setMaxResults(1)
|
||||
|
|
|
@ -66,7 +66,7 @@ public class JpaTransactionManagerRuleTest {
|
|||
// This test verifies that 1) withEntityClass() has registered TestEntity and 2) The table
|
||||
// has been created, implying withProperty(HBM2DDL_AUTO, "update") worked.
|
||||
TestEntity original = new TestEntity("key", "value");
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(original));
|
||||
jpaTm().transact(() -> jpaTm().insert(original));
|
||||
TestEntity retrieved =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "key"));
|
||||
assertThat(retrieved).isEqualTo(original);
|
||||
|
|
|
@ -70,7 +70,8 @@ class IcannReportingStagerTest {
|
|||
}
|
||||
|
||||
private void setUpBigquery() {
|
||||
when(bigquery.query(any(String.class), any(DestinationTable.class))).thenReturn(fakeFuture());
|
||||
when(bigquery.startQuery(any(String.class), any(DestinationTable.class)))
|
||||
.thenReturn(fakeFuture());
|
||||
DestinationTable.Builder tableBuilder =
|
||||
new DestinationTable.Builder()
|
||||
.datasetId("testdataset")
|
||||
|
|
|
@ -53,8 +53,7 @@ public class SqlReplayCheckpointTest extends EntityTestCase {
|
|||
() ->
|
||||
assertThat(
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery("SELECT COUNT(*) FROM SqlReplayCheckpoint", Long.class)
|
||||
.query("SELECT COUNT(*) FROM SqlReplayCheckpoint", Long.class)
|
||||
.getSingleResult())
|
||||
.isEqualTo(1L));
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ import google.registry.model.registry.label.ReservedList.ReservedListEntry;
|
|||
import google.registry.model.registry.label.ReservedListSqlDao;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import javax.persistence.EntityManager;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -118,14 +117,15 @@ abstract class CreateOrUpdateReservedListCommandTestCase<
|
|||
return jpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
EntityManager em = jpaTm().getEntityManager();
|
||||
long revisionId =
|
||||
em.createQuery(
|
||||
jpaTm()
|
||||
.query(
|
||||
"SELECT MAX(rl.revisionId) FROM ReservedList rl WHERE name = :name",
|
||||
Long.class)
|
||||
.setParameter("name", name)
|
||||
.getSingleResult();
|
||||
return em.createQuery(
|
||||
return jpaTm()
|
||||
.query(
|
||||
"FROM ReservedList rl LEFT JOIN FETCH rl.reservedListMap WHERE"
|
||||
+ " rl.revisionId = :revisionId",
|
||||
ReservedList.class)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue