mirror of
https://github.com/google/nomulus.git
synced 2025-07-10 21:23:22 +02:00
Use merge instead of persist for RegistryLockDao (#310)
* Use merge instead of persist for RegistryLockDao * CR responses
This commit is contained in:
parent
128fde16c3
commit
f98b0f8739
3 changed files with 24 additions and 9 deletions
|
@ -45,8 +45,8 @@ public final class RegistryLockDao {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void save(RegistryLock registryLock) {
|
public static RegistryLock save(RegistryLock registryLock) {
|
||||||
checkNotNull(registryLock, "Null registry lock cannot be saved");
|
checkNotNull(registryLock, "Null registry lock cannot be saved");
|
||||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(registryLock));
|
return jpaTm().transact(() -> jpaTm().getEntityManager().merge(registryLock));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,10 +177,7 @@ public final class RegistryLock extends ImmutableObject implements Buildable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Builder asBuilder() {
|
public Builder asBuilder() {
|
||||||
RegistryLock clone = clone(this);
|
return new Builder(clone(this));
|
||||||
// Revision ID should be different for every object
|
|
||||||
clone.revisionId = null;
|
|
||||||
return new Builder(clone);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Builder for {@link google.registry.schema.domain.RegistryLock}. */
|
/** Builder for {@link google.registry.schema.domain.RegistryLock}. */
|
||||||
|
|
|
@ -22,6 +22,7 @@ import google.registry.model.transaction.JpaTransactionManagerRule;
|
||||||
import google.registry.schema.domain.RegistryLock;
|
import google.registry.schema.domain.RegistryLock;
|
||||||
import google.registry.schema.domain.RegistryLock.Action;
|
import google.registry.schema.domain.RegistryLock.Action;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import javax.persistence.PersistenceException;
|
import javax.persistence.PersistenceException;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
|
@ -71,10 +72,10 @@ public final class RegistryLockDaoTest {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
RegistryLock secondLock =
|
RegistryLock updatedLock =
|
||||||
RegistryLockDao.getByVerificationCode(lock.getVerificationCode());
|
RegistryLockDao.getByVerificationCode(lock.getVerificationCode());
|
||||||
secondLock.setCompletionTimestamp(jpaTmRule.getTxnClock().nowUtc());
|
updatedLock.setCompletionTimestamp(jpaTmRule.getTxnClock().nowUtc());
|
||||||
RegistryLockDao.save(secondLock);
|
RegistryLockDao.save(updatedLock);
|
||||||
});
|
});
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
|
@ -86,6 +87,23 @@ public final class RegistryLockDaoTest {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateLock_usingSamePrimaryKey() {
|
||||||
|
RegistryLock lock = RegistryLockDao.save(createLock());
|
||||||
|
jpaTmRule.getTxnClock().advanceOneMilli();
|
||||||
|
RegistryLock updatedLock =
|
||||||
|
lock.asBuilder().setCompletionTimestamp(jpaTmRule.getTxnClock().nowUtc()).build();
|
||||||
|
jpaTm().transact(() -> RegistryLockDao.save(updatedLock));
|
||||||
|
jpaTm()
|
||||||
|
.transact(
|
||||||
|
() -> {
|
||||||
|
RegistryLock fromDatabase =
|
||||||
|
RegistryLockDao.getByVerificationCode(lock.getVerificationCode());
|
||||||
|
assertThat(fromDatabase.getCompletionTimestamp())
|
||||||
|
.isEqualTo(Optional.of(jpaTmRule.getTxnClock().nowUtc()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_saveNull() {
|
public void testFailure_saveNull() {
|
||||||
assertThrows(NullPointerException.class, () -> RegistryLockDao.save(null));
|
assertThrows(NullPointerException.class, () -> RegistryLockDao.save(null));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue