mirror of
https://github.com/google/nomulus.git
synced 2025-07-08 20:23:24 +02:00
Improve naming of TransactionManager methods (#802)
* Improve naming of TransactionManager methods Per internal discussion, convert names of methods as follows: saveNew -> insert saveNewOrUpdate -> put checkExists -> exists Likewise, convert derived names to their corresponding forms, e.g. saveNewOrUpdateAll -> putAll.
This commit is contained in:
parent
3b841bbb5b
commit
933394e8c3
39 changed files with 206 additions and 209 deletions
|
@ -464,7 +464,7 @@ public class DeleteContactsAndHostsAction implements Runnable {
|
||||||
HostResource host = (HostResource) existingResource;
|
HostResource host = (HostResource) existingResource;
|
||||||
if (host.isSubordinate()) {
|
if (host.isSubordinate()) {
|
||||||
dnsQueue.addHostRefreshTask(host.getHostName());
|
dnsQueue.addHostRefreshTask(host.getHostName());
|
||||||
tm().saveNewOrUpdate(
|
tm().put(
|
||||||
tm().load(host.getSuperordinateDomain())
|
tm().load(host.getSuperordinateDomain())
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
.removeSubordinateHost(host.getHostName())
|
.removeSubordinateHost(host.getHostName())
|
||||||
|
|
|
@ -437,7 +437,7 @@ public final class Transforms {
|
||||||
.map(Optional::get)
|
.map(Optional::get)
|
||||||
.map(ofy::toPojo)
|
.map(ofy::toPojo)
|
||||||
.collect(ImmutableList.toImmutableList());
|
.collect(ImmutableList.toImmutableList());
|
||||||
retry(() -> jpaTm().transact(() -> jpaTm().saveNewOrUpdateAll(ofyEntities)));
|
retry(() -> jpaTm().transact(() -> jpaTm().putAll(ofyEntities)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -215,7 +215,7 @@ public class Spec11Pipeline implements Serializable {
|
||||||
.setRegistrarId(subdomain.registrarId())
|
.setRegistrarId(subdomain.registrarId())
|
||||||
.build();
|
.build();
|
||||||
JpaTransactionManager jpaTransactionManager = jpaSupplierFactory.get();
|
JpaTransactionManager jpaTransactionManager = jpaSupplierFactory.get();
|
||||||
jpaTransactionManager.transact(() -> jpaTransactionManager.saveNew(threatMatch));
|
jpaTransactionManager.transact(() -> jpaTransactionManager.insert(threatMatch));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -173,7 +173,7 @@ public final class DomainRestoreRequestFlow implements TransactionalFlow {
|
||||||
existingDomain, newExpirationTime, autorenewEvent, autorenewPollMessage, now, clientId);
|
existingDomain, newExpirationTime, autorenewEvent, autorenewPollMessage, now, clientId);
|
||||||
updateForeignKeyIndexDeletionTime(newDomain);
|
updateForeignKeyIndexDeletionTime(newDomain);
|
||||||
entitiesToSave.add(newDomain, historyEntry, autorenewEvent, autorenewPollMessage);
|
entitiesToSave.add(newDomain, historyEntry, autorenewEvent, autorenewPollMessage);
|
||||||
tm().saveNewOrUpdateAll(entitiesToSave.build());
|
tm().putAll(entitiesToSave.build());
|
||||||
tm().delete(existingDomain.getDeletePollMessage());
|
tm().delete(existingDomain.getDeletePollMessage());
|
||||||
dnsQueue.addDomainRefreshTask(existingDomain.getDomainName());
|
dnsQueue.addDomainRefreshTask(existingDomain.getDomainName());
|
||||||
return responseBuilder
|
return responseBuilder
|
||||||
|
|
|
@ -285,7 +285,7 @@ public final class HostUpdateFlow implements TransactionalFlow {
|
||||||
&& newHost.isSubordinate()
|
&& newHost.isSubordinate()
|
||||||
&& Objects.equals(
|
&& Objects.equals(
|
||||||
existingHost.getSuperordinateDomain(), newHost.getSuperordinateDomain())) {
|
existingHost.getSuperordinateDomain(), newHost.getSuperordinateDomain())) {
|
||||||
tm().saveNewOrUpdate(
|
tm().put(
|
||||||
tm().load(existingHost.getSuperordinateDomain())
|
tm().load(existingHost.getSuperordinateDomain())
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
.removeSubordinateHost(existingHost.getHostName())
|
.removeSubordinateHost(existingHost.getHostName())
|
||||||
|
@ -294,14 +294,14 @@ public final class HostUpdateFlow implements TransactionalFlow {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (existingHost.isSubordinate()) {
|
if (existingHost.isSubordinate()) {
|
||||||
tm().saveNewOrUpdate(
|
tm().put(
|
||||||
tm().load(existingHost.getSuperordinateDomain())
|
tm().load(existingHost.getSuperordinateDomain())
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
.removeSubordinateHost(existingHost.getHostName())
|
.removeSubordinateHost(existingHost.getHostName())
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
if (newHost.isSubordinate()) {
|
if (newHost.isSubordinate()) {
|
||||||
tm().saveNewOrUpdate(
|
tm().put(
|
||||||
tm().load(newHost.getSuperordinateDomain())
|
tm().load(newHost.getSuperordinateDomain())
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
.addSubordinateHost(newHost.getHostName())
|
.addSubordinateHost(newHost.getHostName())
|
||||||
|
|
|
@ -64,7 +64,7 @@ public final class PollFlowUtils {
|
||||||
// and re-save it for future autorenew poll messages to be delivered. Otherwise, this
|
// and re-save it for future autorenew poll messages to be delivered. Otherwise, this
|
||||||
// autorenew poll message has no more events to deliver and should be deleted.
|
// autorenew poll message has no more events to deliver and should be deleted.
|
||||||
if (nextEventTime.isBefore(autorenewPollMessage.getAutorenewEndTime())) {
|
if (nextEventTime.isBefore(autorenewPollMessage.getAutorenewEndTime())) {
|
||||||
tm().saveNewOrUpdate(autorenewPollMessage.asBuilder().setEventTime(nextEventTime).build());
|
tm().put(autorenewPollMessage.asBuilder().setEventTime(nextEventTime).build());
|
||||||
includeAckedMessageInCount = isBeforeOrAt(nextEventTime, tm().getTransactionTime());
|
includeAckedMessageInCount = isBeforeOrAt(nextEventTime, tm().getTransactionTime());
|
||||||
} else {
|
} else {
|
||||||
tm().delete(autorenewPollMessage.createVKey());
|
tm().delete(autorenewPollMessage.createVKey());
|
||||||
|
|
|
@ -101,22 +101,22 @@ public class DatastoreTransactionManager implements TransactionManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveNew(Object entity) {
|
public void insert(Object entity) {
|
||||||
saveEntity(entity);
|
saveEntity(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveAllNew(ImmutableCollection<?> entities) {
|
public void insertAll(ImmutableCollection<?> entities) {
|
||||||
getOfy().save().entities(entities);
|
getOfy().save().entities(entities);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveNewOrUpdate(Object entity) {
|
public void put(Object entity) {
|
||||||
saveEntity(entity);
|
saveEntity(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveNewOrUpdateAll(ImmutableCollection<?> entities) {
|
public void putAll(ImmutableCollection<?> entities) {
|
||||||
getOfy().save().entities(entities);
|
getOfy().save().entities(entities);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,12 +131,12 @@ public class DatastoreTransactionManager implements TransactionManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkExists(Object entity) {
|
public boolean exists(Object entity) {
|
||||||
return getOfy().load().key(Key.create(entity)).now() != null;
|
return getOfy().load().key(Key.create(entity)).now() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> boolean checkExists(VKey<T> key) {
|
public <T> boolean exists(VKey<T> key) {
|
||||||
return loadNullable(key) != null;
|
return loadNullable(key) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class ReservedListDualWriteDao {
|
||||||
|
|
||||||
/** Persist a new reserved list to Cloud SQL. */
|
/** Persist a new reserved list to Cloud SQL. */
|
||||||
public static void save(ReservedList reservedList) {
|
public static void save(ReservedList reservedList) {
|
||||||
ofyTm().transact(() -> ofyTm().saveNewOrUpdate(reservedList));
|
ofyTm().transact(() -> ofyTm().put(reservedList));
|
||||||
try {
|
try {
|
||||||
logger.atInfo().log("Saving reserved list %s to Cloud SQL", reservedList.getName());
|
logger.atInfo().log("Saving reserved list %s to Cloud SQL", reservedList.getName());
|
||||||
ReservedListSqlDao.save(reservedList);
|
ReservedListSqlDao.save(reservedList);
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class ReservedListSqlDao {
|
||||||
/** Persist a new reserved list to Cloud SQL. */
|
/** Persist a new reserved list to Cloud SQL. */
|
||||||
public static void save(ReservedList reservedList) {
|
public static void save(ReservedList reservedList) {
|
||||||
checkArgumentNotNull(reservedList, "Must specify reservedList");
|
checkArgumentNotNull(reservedList, "Must specify reservedList");
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(reservedList));
|
jpaTm().transact(() -> jpaTm().insert(reservedList));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -224,7 +224,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveNew(Object entity) {
|
public void insert(Object entity) {
|
||||||
checkArgumentNotNull(entity, "entity must be specified");
|
checkArgumentNotNull(entity, "entity must be specified");
|
||||||
assertInTransaction();
|
assertInTransaction();
|
||||||
getEntityManager().persist(entity);
|
getEntityManager().persist(entity);
|
||||||
|
@ -232,14 +232,14 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveAllNew(ImmutableCollection<?> entities) {
|
public void insertAll(ImmutableCollection<?> entities) {
|
||||||
checkArgumentNotNull(entities, "entities must be specified");
|
checkArgumentNotNull(entities, "entities must be specified");
|
||||||
assertInTransaction();
|
assertInTransaction();
|
||||||
entities.forEach(this::saveNew);
|
entities.forEach(this::insert);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveNewOrUpdate(Object entity) {
|
public void put(Object entity) {
|
||||||
checkArgumentNotNull(entity, "entity must be specified");
|
checkArgumentNotNull(entity, "entity must be specified");
|
||||||
assertInTransaction();
|
assertInTransaction();
|
||||||
getEntityManager().merge(entity);
|
getEntityManager().merge(entity);
|
||||||
|
@ -247,17 +247,17 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveNewOrUpdateAll(ImmutableCollection<?> entities) {
|
public void putAll(ImmutableCollection<?> entities) {
|
||||||
checkArgumentNotNull(entities, "entities must be specified");
|
checkArgumentNotNull(entities, "entities must be specified");
|
||||||
assertInTransaction();
|
assertInTransaction();
|
||||||
entities.forEach(this::saveNewOrUpdate);
|
entities.forEach(this::put);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Object entity) {
|
public void update(Object entity) {
|
||||||
checkArgumentNotNull(entity, "entity must be specified");
|
checkArgumentNotNull(entity, "entity must be specified");
|
||||||
assertInTransaction();
|
assertInTransaction();
|
||||||
checkArgument(checkExists(entity), "Given entity does not exist");
|
checkArgument(exists(entity), "Given entity does not exist");
|
||||||
getEntityManager().merge(entity);
|
getEntityManager().merge(entity);
|
||||||
transactionInfo.get().addUpdate(entity);
|
transactionInfo.get().addUpdate(entity);
|
||||||
}
|
}
|
||||||
|
@ -270,22 +270,22 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> boolean checkExists(VKey<T> key) {
|
public <T> boolean exists(VKey<T> key) {
|
||||||
checkArgumentNotNull(key, "key must be specified");
|
checkArgumentNotNull(key, "key must be specified");
|
||||||
EntityType<?> entityType = getEntityType(key.getKind());
|
EntityType<?> entityType = getEntityType(key.getKind());
|
||||||
ImmutableSet<EntityId> entityIds = getEntityIdsFromSqlKey(entityType, key.getSqlKey());
|
ImmutableSet<EntityId> entityIds = getEntityIdsFromSqlKey(entityType, key.getSqlKey());
|
||||||
return checkExists(entityType.getName(), entityIds);
|
return exists(entityType.getName(), entityIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkExists(Object entity) {
|
public boolean exists(Object entity) {
|
||||||
checkArgumentNotNull(entity, "entity must be specified");
|
checkArgumentNotNull(entity, "entity must be specified");
|
||||||
EntityType<?> entityType = getEntityType(entity.getClass());
|
EntityType<?> entityType = getEntityType(entity.getClass());
|
||||||
ImmutableSet<EntityId> entityIds = getEntityIdsFromEntity(entityType, entity);
|
ImmutableSet<EntityId> entityIds = getEntityIdsFromEntity(entityType, entity);
|
||||||
return checkExists(entityType.getName(), entityIds);
|
return exists(entityType.getName(), entityIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkExists(String entityName, ImmutableSet<EntityId> entityIds) {
|
private boolean exists(String entityName, ImmutableSet<EntityId> entityIds) {
|
||||||
assertInTransaction();
|
assertInTransaction();
|
||||||
TypedQuery<Integer> query =
|
TypedQuery<Integer> query =
|
||||||
getEntityManager()
|
getEntityManager()
|
||||||
|
|
|
@ -208,7 +208,7 @@ public class Transaction extends ImmutableObject implements Buildable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToDatastore() {
|
public void writeToDatastore() {
|
||||||
ofyTm().saveNewOrUpdate(entity);
|
ofyTm().put(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -86,16 +86,16 @@ public interface TransactionManager {
|
||||||
DateTime getTransactionTime();
|
DateTime getTransactionTime();
|
||||||
|
|
||||||
/** Persists a new entity in the database, throws exception if the entity already exists. */
|
/** Persists a new entity in the database, throws exception if the entity already exists. */
|
||||||
void saveNew(Object entity);
|
void insert(Object entity);
|
||||||
|
|
||||||
/** Persists all new entities in the database, throws exception if any entity already exists. */
|
/** Persists all new entities in the database, throws exception if any entity already exists. */
|
||||||
void saveAllNew(ImmutableCollection<?> entities);
|
void insertAll(ImmutableCollection<?> entities);
|
||||||
|
|
||||||
/** Persists a new entity or update the existing entity in the database. */
|
/** Persists a new entity or update the existing entity in the database. */
|
||||||
void saveNewOrUpdate(Object entity);
|
void put(Object entity);
|
||||||
|
|
||||||
/** Persists all new entities or update the existing entities in the database. */
|
/** Persists all new entities or update the existing entities in the database. */
|
||||||
void saveNewOrUpdateAll(ImmutableCollection<?> entities);
|
void putAll(ImmutableCollection<?> entities);
|
||||||
|
|
||||||
/** Updates an entity in the database, throws exception if the entity does not exist. */
|
/** Updates an entity in the database, throws exception if the entity does not exist. */
|
||||||
void update(Object entity);
|
void update(Object entity);
|
||||||
|
@ -104,10 +104,10 @@ public interface TransactionManager {
|
||||||
void updateAll(ImmutableCollection<?> entities);
|
void updateAll(ImmutableCollection<?> entities);
|
||||||
|
|
||||||
/** Returns whether the given entity with same ID exists. */
|
/** Returns whether the given entity with same ID exists. */
|
||||||
boolean checkExists(Object entity);
|
boolean exists(Object entity);
|
||||||
|
|
||||||
/** Returns whether the entity of given key exists. */
|
/** Returns whether the entity of given key exists. */
|
||||||
<T> boolean checkExists(VKey<T> key);
|
<T> boolean exists(VKey<T> key);
|
||||||
|
|
||||||
/** Loads the entity by its id, returns empty if the entity doesn't exist. */
|
/** Loads the entity by its id, returns empty if the entity doesn't exist. */
|
||||||
<T> Optional<T> maybeLoad(VKey<T> key);
|
<T> Optional<T> maybeLoad(VKey<T> key);
|
||||||
|
|
|
@ -72,7 +72,7 @@ final class CreateRegistrarCommand extends CreateOrUpdateRegistrarCommand
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void saveToCloudSql(Registrar registrar) {
|
void saveToCloudSql(Registrar registrar) {
|
||||||
jpaTm().saveNew(registrar);
|
jpaTm().insert(registrar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
|
@ -85,7 +85,7 @@ class WriteToSqlTest implements Serializable {
|
||||||
// Required for contacts created below.
|
// Required for contacts created below.
|
||||||
Registrar ofyRegistrar = AppEngineExtension.makeRegistrar2();
|
Registrar ofyRegistrar = AppEngineExtension.makeRegistrar2();
|
||||||
store.insertOrUpdate(ofyRegistrar);
|
store.insertOrUpdate(ofyRegistrar);
|
||||||
jpaTm().transact(() -> jpaTm().saveNewOrUpdate(store.loadAsOfyEntity(ofyRegistrar)));
|
jpaTm().transact(() -> jpaTm().put(store.loadAsOfyEntity(ofyRegistrar)));
|
||||||
|
|
||||||
ImmutableList.Builder<Entity> builder = new ImmutableList.Builder<>();
|
ImmutableList.Builder<Entity> builder = new ImmutableList.Builder<>();
|
||||||
|
|
||||||
|
|
|
@ -285,7 +285,7 @@ class Spec11PipelineTest {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
verify(mockJpaTm).transact(any(Runnable.class));
|
verify(mockJpaTm).transact(any(Runnable.class));
|
||||||
verify(mockJpaTm).saveNew(expected);
|
verify(mockJpaTm).insert(expected);
|
||||||
verifyNoMoreInteractions(mockJpaTm);
|
verifyNoMoreInteractions(mockJpaTm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -180,7 +180,7 @@ public class BillingEventTest extends EntityTestCase {
|
||||||
|
|
||||||
private void saveNewBillingEvent(BillingEvent billingEvent) {
|
private void saveNewBillingEvent(BillingEvent billingEvent) {
|
||||||
billingEvent.id = null;
|
billingEvent.id = null;
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(billingEvent));
|
jpaTm().transact(() -> jpaTm().insert(billingEvent));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -124,7 +124,7 @@ public class ContactResourceTest extends EntityTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCloudSqlPersistence_failWhenViolateForeignKeyConstraint() {
|
void testCloudSqlPersistence_failWhenViolateForeignKeyConstraint() {
|
||||||
assertThrowForeignKeyViolation(() -> jpaTm().transact(() -> jpaTm().saveNew(originalContact)));
|
assertThrowForeignKeyViolation(() -> jpaTm().transact(() -> jpaTm().insert(originalContact)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -134,7 +134,7 @@ public class ContactResourceTest extends EntityTestCase {
|
||||||
saveRegistrar("registrar3");
|
saveRegistrar("registrar3");
|
||||||
saveRegistrar("gaining");
|
saveRegistrar("gaining");
|
||||||
saveRegistrar("losing");
|
saveRegistrar("losing");
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(originalContact));
|
jpaTm().transact(() -> jpaTm().insert(originalContact));
|
||||||
ContactResource persisted =
|
ContactResource persisted =
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
|
|
|
@ -139,9 +139,9 @@ public class DomainBaseSqlTest {
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
// Persist the domain without the associated host object.
|
// Persist the domain without the associated host object.
|
||||||
jpaTm().saveNew(contact);
|
jpaTm().insert(contact);
|
||||||
jpaTm().saveNew(contact2);
|
jpaTm().insert(contact2);
|
||||||
jpaTm().saveNew(domain);
|
jpaTm().insert(domain);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,8 +153,8 @@ public class DomainBaseSqlTest {
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
// Persist the domain without the associated contact objects.
|
// Persist the domain without the associated contact objects.
|
||||||
jpaTm().saveNew(domain);
|
jpaTm().insert(domain);
|
||||||
jpaTm().saveNew(host);
|
jpaTm().insert(host);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ public class DomainBaseSqlTest {
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
DomainBase persisted = jpaTm().load(domain.createVKey());
|
DomainBase persisted = jpaTm().load(domain.createVKey());
|
||||||
jpaTm().saveNewOrUpdate(persisted.asBuilder().build());
|
jpaTm().put(persisted.asBuilder().build());
|
||||||
});
|
});
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
|
@ -185,7 +185,7 @@ public class DomainBaseSqlTest {
|
||||||
DomainBase persisted = jpaTm().load(domain.createVKey());
|
DomainBase persisted = jpaTm().load(domain.createVKey());
|
||||||
DomainBase modified =
|
DomainBase modified =
|
||||||
persisted.asBuilder().setGracePeriods(ImmutableSet.of()).build();
|
persisted.asBuilder().setGracePeriods(ImmutableSet.of()).build();
|
||||||
jpaTm().saveNewOrUpdate(modified);
|
jpaTm().put(modified);
|
||||||
});
|
});
|
||||||
|
|
||||||
jpaTm()
|
jpaTm()
|
||||||
|
@ -204,7 +204,7 @@ public class DomainBaseSqlTest {
|
||||||
() -> {
|
() -> {
|
||||||
DomainBase persisted = jpaTm().load(domain.createVKey());
|
DomainBase persisted = jpaTm().load(domain.createVKey());
|
||||||
DomainBase modified = persisted.asBuilder().setGracePeriods(null).build();
|
DomainBase modified = persisted.asBuilder().setGracePeriods(null).build();
|
||||||
jpaTm().saveNewOrUpdate(modified);
|
jpaTm().put(modified);
|
||||||
});
|
});
|
||||||
|
|
||||||
jpaTm()
|
jpaTm()
|
||||||
|
@ -229,7 +229,7 @@ public class DomainBaseSqlTest {
|
||||||
GracePeriod.create(
|
GracePeriod.create(
|
||||||
GracePeriodStatus.RENEW, "4-COM", END_OF_TIME, "registrar1", null))
|
GracePeriodStatus.RENEW, "4-COM", END_OF_TIME, "registrar1", null))
|
||||||
.build();
|
.build();
|
||||||
jpaTm().saveNewOrUpdate(modified);
|
jpaTm().put(modified);
|
||||||
});
|
});
|
||||||
|
|
||||||
jpaTm()
|
jpaTm()
|
||||||
|
@ -281,7 +281,7 @@ public class DomainBaseSqlTest {
|
||||||
builder.removeGracePeriod(gracePeriod);
|
builder.removeGracePeriod(gracePeriod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jpaTm().saveNewOrUpdate(builder.build());
|
jpaTm().put(builder.build());
|
||||||
});
|
});
|
||||||
|
|
||||||
jpaTm()
|
jpaTm()
|
||||||
|
@ -301,7 +301,7 @@ public class DomainBaseSqlTest {
|
||||||
DomainBase persisted = jpaTm().load(domain.createVKey());
|
DomainBase persisted = jpaTm().load(domain.createVKey());
|
||||||
DomainBase modified =
|
DomainBase modified =
|
||||||
persisted.asBuilder().setGracePeriods(ImmutableSet.of()).build();
|
persisted.asBuilder().setGracePeriods(ImmutableSet.of()).build();
|
||||||
jpaTm().saveNewOrUpdate(modified);
|
jpaTm().put(modified);
|
||||||
});
|
});
|
||||||
|
|
||||||
jpaTm()
|
jpaTm()
|
||||||
|
@ -316,7 +316,7 @@ public class DomainBaseSqlTest {
|
||||||
GracePeriod.create(
|
GracePeriod.create(
|
||||||
GracePeriodStatus.ADD, "4-COM", END_OF_TIME, "registrar1", null))
|
GracePeriodStatus.ADD, "4-COM", END_OF_TIME, "registrar1", null))
|
||||||
.build();
|
.build();
|
||||||
jpaTm().saveNewOrUpdate(modified);
|
jpaTm().put(modified);
|
||||||
});
|
});
|
||||||
|
|
||||||
jpaTm()
|
jpaTm()
|
||||||
|
@ -339,13 +339,13 @@ public class DomainBaseSqlTest {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
jpaTm().saveNew(contact);
|
jpaTm().insert(contact);
|
||||||
jpaTm().saveNew(contact2);
|
jpaTm().insert(contact2);
|
||||||
jpaTm().saveNew(domain);
|
jpaTm().insert(domain);
|
||||||
jpaTm().saveNew(host);
|
jpaTm().insert(host);
|
||||||
});
|
});
|
||||||
domain = domain.asBuilder().setNameservers(ImmutableSet.of()).build();
|
domain = domain.asBuilder().setNameservers(ImmutableSet.of()).build();
|
||||||
jpaTm().transact(() -> jpaTm().saveNewOrUpdate(domain));
|
jpaTm().transact(() -> jpaTm().put(domain));
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
|
@ -382,16 +382,16 @@ public class DomainBaseSqlTest {
|
||||||
// Persist the contacts. Note that these need to be persisted before the domain
|
// Persist the contacts. Note that these need to be persisted before the domain
|
||||||
// otherwise we get a foreign key constraint error. If we ever decide to defer the
|
// otherwise we get a foreign key constraint error. If we ever decide to defer the
|
||||||
// relevant foreign key checks to commit time, then the order would not matter.
|
// relevant foreign key checks to commit time, then the order would not matter.
|
||||||
jpaTm().saveNew(contact);
|
jpaTm().insert(contact);
|
||||||
jpaTm().saveNew(contact2);
|
jpaTm().insert(contact2);
|
||||||
|
|
||||||
// Persist the domain.
|
// Persist the domain.
|
||||||
jpaTm().saveNew(domain);
|
jpaTm().insert(domain);
|
||||||
|
|
||||||
// Persist the host. This does _not_ need to be persisted before the domain,
|
// Persist the host. This does _not_ need to be persisted before the domain,
|
||||||
// because only the row in the join table (DomainHost) is subject to foreign key
|
// because only the row in the join table (DomainHost) is subject to foreign key
|
||||||
// constraints, and Hibernate knows to insert it after domain and host.
|
// constraints, and Hibernate knows to insert it after domain and host.
|
||||||
jpaTm().saveNew(host);
|
jpaTm().insert(host);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,8 +95,8 @@ public class AllocationTokenTest extends EntityTestCase {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
jpaTm().saveNew(unlimitedUseToken);
|
jpaTm().insert(unlimitedUseToken);
|
||||||
jpaTm().saveNew(singleUseToken);
|
jpaTm().insert(singleUseToken);
|
||||||
});
|
});
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
|
|
|
@ -44,12 +44,12 @@ public class ContactHistoryTest extends EntityTestCase {
|
||||||
saveRegistrar("TheRegistrar");
|
saveRegistrar("TheRegistrar");
|
||||||
|
|
||||||
ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
|
ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(contact));
|
jpaTm().transact(() -> jpaTm().insert(contact));
|
||||||
VKey<ContactResource> contactVKey = contact.createVKey();
|
VKey<ContactResource> contactVKey = contact.createVKey();
|
||||||
ContactResource contactFromDb = jpaTm().transact(() -> jpaTm().load(contactVKey));
|
ContactResource contactFromDb = jpaTm().transact(() -> jpaTm().load(contactVKey));
|
||||||
ContactHistory contactHistory = createContactHistory(contactFromDb, contactVKey);
|
ContactHistory contactHistory = createContactHistory(contactFromDb, contactVKey);
|
||||||
contactHistory.id = null;
|
contactHistory.id = null;
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(contactHistory));
|
jpaTm().transact(() -> jpaTm().insert(contactHistory));
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
|
@ -65,12 +65,12 @@ public class ContactHistoryTest extends EntityTestCase {
|
||||||
saveRegistrar("TheRegistrar");
|
saveRegistrar("TheRegistrar");
|
||||||
|
|
||||||
ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
|
ContactResource contact = newContactResourceWithRoid("contactId", "contact1");
|
||||||
tm().transact(() -> tm().saveNew(contact));
|
tm().transact(() -> tm().insert(contact));
|
||||||
VKey<ContactResource> contactVKey = contact.createVKey();
|
VKey<ContactResource> contactVKey = contact.createVKey();
|
||||||
ContactResource contactFromDb = tm().transact(() -> tm().load(contactVKey));
|
ContactResource contactFromDb = tm().transact(() -> tm().load(contactVKey));
|
||||||
fakeClock.advanceOneMilli();
|
fakeClock.advanceOneMilli();
|
||||||
ContactHistory contactHistory = createContactHistory(contactFromDb, contactVKey);
|
ContactHistory contactHistory = createContactHistory(contactFromDb, contactVKey);
|
||||||
tm().transact(() -> tm().saveNew(contactHistory));
|
tm().transact(() -> tm().insert(contactHistory));
|
||||||
|
|
||||||
// retrieving a HistoryEntry or a ContactHistory with the same key should return the same object
|
// retrieving a HistoryEntry or a ContactHistory with the same key should return the same object
|
||||||
// note: due to the @EntitySubclass annotation. all Keys for ContactHistory objects will have
|
// note: due to the @EntitySubclass annotation. all Keys for ContactHistory objects will have
|
||||||
|
|
|
@ -59,8 +59,8 @@ public class DomainHistoryTest extends EntityTestCase {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
jpaTm().saveNew(host);
|
jpaTm().insert(host);
|
||||||
jpaTm().saveNew(contact);
|
jpaTm().insert(contact);
|
||||||
});
|
});
|
||||||
|
|
||||||
DomainBase domain =
|
DomainBase domain =
|
||||||
|
@ -68,11 +68,11 @@ public class DomainHistoryTest extends EntityTestCase {
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
.setNameservers(host.createVKey())
|
.setNameservers(host.createVKey())
|
||||||
.build();
|
.build();
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(domain));
|
jpaTm().transact(() -> jpaTm().insert(domain));
|
||||||
|
|
||||||
DomainHistory domainHistory = createDomainHistory(domain);
|
DomainHistory domainHistory = createDomainHistory(domain);
|
||||||
domainHistory.id = null;
|
domainHistory.id = null;
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(domainHistory));
|
jpaTm().transact(() -> jpaTm().insert(domainHistory));
|
||||||
|
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
|
@ -98,8 +98,8 @@ public class DomainHistoryTest extends EntityTestCase {
|
||||||
|
|
||||||
tm().transact(
|
tm().transact(
|
||||||
() -> {
|
() -> {
|
||||||
tm().saveNew(host);
|
tm().insert(host);
|
||||||
tm().saveNew(contact);
|
tm().insert(contact);
|
||||||
});
|
});
|
||||||
fakeClock.advanceOneMilli();
|
fakeClock.advanceOneMilli();
|
||||||
|
|
||||||
|
@ -108,11 +108,11 @@ public class DomainHistoryTest extends EntityTestCase {
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
.setNameservers(host.createVKey())
|
.setNameservers(host.createVKey())
|
||||||
.build();
|
.build();
|
||||||
tm().transact(() -> tm().saveNew(domain));
|
tm().transact(() -> tm().insert(domain));
|
||||||
|
|
||||||
fakeClock.advanceOneMilli();
|
fakeClock.advanceOneMilli();
|
||||||
DomainHistory domainHistory = createDomainHistory(domain);
|
DomainHistory domainHistory = createDomainHistory(domain);
|
||||||
tm().transact(() -> tm().saveNew(domainHistory));
|
tm().transact(() -> tm().insert(domainHistory));
|
||||||
|
|
||||||
// retrieving a HistoryEntry or a DomainHistory with the same key should return the same object
|
// retrieving a HistoryEntry or a DomainHistory with the same key should return the same object
|
||||||
// note: due to the @EntitySubclass annotation. all Keys for ContactHistory objects will have
|
// note: due to the @EntitySubclass annotation. all Keys for ContactHistory objects will have
|
||||||
|
|
|
@ -44,12 +44,12 @@ public class HostHistoryTest extends EntityTestCase {
|
||||||
saveRegistrar("TheRegistrar");
|
saveRegistrar("TheRegistrar");
|
||||||
|
|
||||||
HostResource host = newHostResourceWithRoid("ns1.example.com", "host1");
|
HostResource host = newHostResourceWithRoid("ns1.example.com", "host1");
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(host));
|
jpaTm().transact(() -> jpaTm().insert(host));
|
||||||
VKey<HostResource> hostVKey = VKey.createSql(HostResource.class, "host1");
|
VKey<HostResource> hostVKey = VKey.createSql(HostResource.class, "host1");
|
||||||
HostResource hostFromDb = jpaTm().transact(() -> jpaTm().load(hostVKey));
|
HostResource hostFromDb = jpaTm().transact(() -> jpaTm().load(hostVKey));
|
||||||
HostHistory hostHistory = createHostHistory(hostFromDb, hostVKey);
|
HostHistory hostHistory = createHostHistory(hostFromDb, hostVKey);
|
||||||
hostHistory.id = null;
|
hostHistory.id = null;
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(hostHistory));
|
jpaTm().transact(() -> jpaTm().insert(hostHistory));
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
|
@ -66,12 +66,12 @@ public class HostHistoryTest extends EntityTestCase {
|
||||||
saveRegistrar("registrar1");
|
saveRegistrar("registrar1");
|
||||||
|
|
||||||
HostResource host = newHostResourceWithRoid("ns1.example.com", "host1");
|
HostResource host = newHostResourceWithRoid("ns1.example.com", "host1");
|
||||||
tm().transact(() -> tm().saveNew(host));
|
tm().transact(() -> tm().insert(host));
|
||||||
VKey<HostResource> hostVKey = VKey.create(HostResource.class, "host1", Key.create(host));
|
VKey<HostResource> hostVKey = VKey.create(HostResource.class, "host1", Key.create(host));
|
||||||
HostResource hostFromDb = tm().transact(() -> tm().load(hostVKey));
|
HostResource hostFromDb = tm().transact(() -> tm().load(hostVKey));
|
||||||
HostHistory hostHistory = createHostHistory(hostFromDb, hostVKey);
|
HostHistory hostHistory = createHostHistory(hostFromDb, hostVKey);
|
||||||
fakeClock.advanceOneMilli();
|
fakeClock.advanceOneMilli();
|
||||||
tm().transact(() -> tm().saveNew(hostHistory));
|
tm().transact(() -> tm().insert(hostHistory));
|
||||||
|
|
||||||
// retrieving a HistoryEntry or a HostHistory with the same key should return the same object
|
// retrieving a HistoryEntry or a HostHistory with the same key should return the same object
|
||||||
// note: due to the @EntitySubclass annotation. all Keys for ContactHistory objects will have
|
// note: due to the @EntitySubclass annotation. all Keys for ContactHistory objects will have
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class PollMessageTest extends EntityTestCase {
|
||||||
@Test
|
@Test
|
||||||
void testCloudSqlPersistenceOneTime() {
|
void testCloudSqlPersistenceOneTime() {
|
||||||
saveRegistrar("TheRegistrar");
|
saveRegistrar("TheRegistrar");
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(oneTime));
|
jpaTm().transact(() -> jpaTm().insert(oneTime));
|
||||||
PollMessage.OneTime persisted =
|
PollMessage.OneTime persisted =
|
||||||
jpaTm().transact(() -> jpaTm().load(VKey.createSql(PollMessage.OneTime.class, oneTime.id)));
|
jpaTm().transact(() -> jpaTm().load(VKey.createSql(PollMessage.OneTime.class, oneTime.id)));
|
||||||
persisted.parent = oneTime.parent;
|
persisted.parent = oneTime.parent;
|
||||||
|
@ -94,7 +94,7 @@ public class PollMessageTest extends EntityTestCase {
|
||||||
@Test
|
@Test
|
||||||
void testCloudSqlPersistenceAutorenew() {
|
void testCloudSqlPersistenceAutorenew() {
|
||||||
saveRegistrar("TheRegistrar");
|
saveRegistrar("TheRegistrar");
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(autoRenew));
|
jpaTm().transact(() -> jpaTm().insert(autoRenew));
|
||||||
PollMessage.Autorenew persisted =
|
PollMessage.Autorenew persisted =
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
|
@ -107,14 +107,14 @@ public class PollMessageTest extends EntityTestCase {
|
||||||
void testCloudSqlSupportForPolymorphicVKey() {
|
void testCloudSqlSupportForPolymorphicVKey() {
|
||||||
saveRegistrar("TheRegistrar");
|
saveRegistrar("TheRegistrar");
|
||||||
|
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(oneTime));
|
jpaTm().transact(() -> jpaTm().insert(oneTime));
|
||||||
PollMessage persistedOneTime =
|
PollMessage persistedOneTime =
|
||||||
jpaTm().transact(() -> jpaTm().load(VKey.createSql(PollMessage.class, oneTime.getId())));
|
jpaTm().transact(() -> jpaTm().load(VKey.createSql(PollMessage.class, oneTime.getId())));
|
||||||
assertThat(persistedOneTime).isInstanceOf(PollMessage.OneTime.class);
|
assertThat(persistedOneTime).isInstanceOf(PollMessage.OneTime.class);
|
||||||
persistedOneTime.parent = oneTime.parent;
|
persistedOneTime.parent = oneTime.parent;
|
||||||
assertThat(persistedOneTime).isEqualTo(oneTime);
|
assertThat(persistedOneTime).isEqualTo(oneTime);
|
||||||
|
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(autoRenew));
|
jpaTm().transact(() -> jpaTm().insert(autoRenew));
|
||||||
PollMessage persistedAutoRenew =
|
PollMessage persistedAutoRenew =
|
||||||
jpaTm().transact(() -> jpaTm().load(VKey.createSql(PollMessage.class, autoRenew.getId())));
|
jpaTm().transact(() -> jpaTm().load(VKey.createSql(PollMessage.class, autoRenew.getId())));
|
||||||
assertThat(persistedAutoRenew).isInstanceOf(PollMessage.Autorenew.class);
|
assertThat(persistedAutoRenew).isInstanceOf(PollMessage.Autorenew.class);
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
PremiumList pl = persistPremiumList("tld2", "lol,USD 50", "cat,USD 700");
|
PremiumList pl = persistPremiumList("tld2", "lol,USD 50", "cat,USD 700");
|
||||||
Registry registry =
|
Registry registry =
|
||||||
Registry.get("tld").asBuilder().setReservedLists(rl15).setPremiumList(pl).build();
|
Registry.get("tld").asBuilder().setReservedLists(rl15).setPremiumList(pl).build();
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(registry));
|
jpaTm().transact(() -> jpaTm().insert(registry));
|
||||||
Registry persisted =
|
Registry persisted =
|
||||||
jpaTm().transact(() -> jpaTm().load(VKey.createSql(Registry.class, registry.tldStrId)));
|
jpaTm().transact(() -> jpaTm().load(VKey.createSql(Registry.class, registry.tldStrId)));
|
||||||
assertThat(persisted).isEqualTo(registry);
|
assertThat(persisted).isEqualTo(registry);
|
||||||
|
|
|
@ -37,8 +37,8 @@ public class Spec11ThreatMatchDaoTest extends EntityTestCase {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
jpaTm().saveAllNew(getThreatMatchesToday());
|
jpaTm().insertAll(getThreatMatchesToday());
|
||||||
jpaTm().saveAllNew(getThreatMatchesYesterday());
|
jpaTm().insertAll(getThreatMatchesYesterday());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,10 +107,10 @@ public class Spec11ThreatMatchTest extends EntityTestCase {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
jpaTm().saveNew(registrantContact);
|
jpaTm().insert(registrantContact);
|
||||||
jpaTm().saveNew(domain);
|
jpaTm().insert(domain);
|
||||||
jpaTm().saveNew(host);
|
jpaTm().insert(host);
|
||||||
jpaTm().saveNew(threat);
|
jpaTm().insert(threat);
|
||||||
});
|
});
|
||||||
|
|
||||||
VKey<Spec11ThreatMatch> threatVKey = VKey.createSql(Spec11ThreatMatch.class, threat.getId());
|
VKey<Spec11ThreatMatch> threatVKey = VKey.createSql(Spec11ThreatMatch.class, threat.getId());
|
||||||
|
@ -130,10 +130,10 @@ public class Spec11ThreatMatchTest extends EntityTestCase {
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
// Persist the threat without the associated registrar.
|
// Persist the threat without the associated registrar.
|
||||||
jpaTm().saveNew(host);
|
jpaTm().insert(host);
|
||||||
jpaTm().saveNew(registrantContact);
|
jpaTm().insert(registrantContact);
|
||||||
jpaTm().saveNew(domain);
|
jpaTm().insert(domain);
|
||||||
jpaTm().saveNew(threat);
|
jpaTm().insert(threat);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -145,9 +145,9 @@ public class Spec11ThreatMatchTest extends EntityTestCase {
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
// Persist the threat without the associated domain.
|
// Persist the threat without the associated domain.
|
||||||
jpaTm().saveNew(registrantContact);
|
jpaTm().insert(registrantContact);
|
||||||
jpaTm().saveNew(host);
|
jpaTm().insert(host);
|
||||||
jpaTm().saveNew(threat);
|
jpaTm().insert(threat);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ class EntityCallbacksListenerTest {
|
||||||
@Test
|
@Test
|
||||||
void verifyAllCallbacks_executedExpectedTimes() {
|
void verifyAllCallbacks_executedExpectedTimes() {
|
||||||
TestEntity testPersist = new TestEntity();
|
TestEntity testPersist = new TestEntity();
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(testPersist));
|
jpaTm().transact(() -> jpaTm().insert(testPersist));
|
||||||
checkAll(testPersist, 1, 0, 0, 0);
|
checkAll(testPersist, 1, 0, 0, 0);
|
||||||
|
|
||||||
TestEntity testUpdate = new TestEntity();
|
TestEntity testUpdate = new TestEntity();
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class DurationConverterTest {
|
||||||
|
|
||||||
private void assertPersistedEntityHasSameDuration(Duration duration) {
|
private void assertPersistedEntityHasSameDuration(Duration duration) {
|
||||||
DurationTestEntity entity = new DurationTestEntity(duration);
|
DurationTestEntity entity = new DurationTestEntity(duration);
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(entity));
|
jpaTm().transact(() -> jpaTm().insert(entity));
|
||||||
DurationTestEntity persisted =
|
DurationTestEntity persisted =
|
||||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(DurationTestEntity.class, "id"));
|
jpaTm().transact(() -> jpaTm().getEntityManager().find(DurationTestEntity.class, "id"));
|
||||||
assertThat(persisted.duration.getMillis()).isEqualTo(duration.getMillis());
|
assertThat(persisted.duration.getMillis()).isEqualTo(duration.getMillis());
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class InetAddressSetConverterTest {
|
||||||
|
|
||||||
private void verifySaveAndLoad(@Nullable Set<InetAddress> inetAddresses) {
|
private void verifySaveAndLoad(@Nullable Set<InetAddress> inetAddresses) {
|
||||||
InetAddressSetTestEntity testEntity = new InetAddressSetTestEntity(inetAddresses);
|
InetAddressSetTestEntity testEntity = new InetAddressSetTestEntity(inetAddresses);
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(testEntity));
|
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||||
InetAddressSetTestEntity persisted =
|
InetAddressSetTestEntity persisted =
|
||||||
jpaTm().transact(() -> jpaTm().load(VKey.createSql(InetAddressSetTestEntity.class, "id")));
|
jpaTm().transact(() -> jpaTm().load(VKey.createSql(InetAddressSetTestEntity.class, "id")));
|
||||||
assertThat(persisted.addresses).isEqualTo(inetAddresses);
|
assertThat(persisted.addresses).isEqualTo(inetAddresses);
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class LocalDateConverterTest {
|
||||||
|
|
||||||
private LocalDateConverterTestEntity persistAndLoadTestEntity(LocalDate date) {
|
private LocalDateConverterTestEntity persistAndLoadTestEntity(LocalDate date) {
|
||||||
LocalDateConverterTestEntity entity = new LocalDateConverterTestEntity(date);
|
LocalDateConverterTestEntity entity = new LocalDateConverterTestEntity(date);
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(entity));
|
jpaTm().transact(() -> jpaTm().insert(entity));
|
||||||
LocalDateConverterTestEntity retrievedEntity =
|
LocalDateConverterTestEntity retrievedEntity =
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(() -> jpaTm().load(VKey.createSql(LocalDateConverterTestEntity.class, "id")));
|
.transact(() -> jpaTm().load(VKey.createSql(LocalDateConverterTestEntity.class, "id")));
|
||||||
|
|
|
@ -132,10 +132,10 @@ class JpaTransactionManagerImplTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void saveNew_succeeds() {
|
void insert_succeeds() {
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(theEntity));
|
jpaTm().transact(() -> jpaTm().insert(theEntity));
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isTrue();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isTrue();
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().load(theEntityKey))).isEqualTo(theEntity);
|
assertThat(jpaTm().transact(() -> jpaTm().load(theEntityKey))).isEqualTo(theEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ class JpaTransactionManagerImplTest {
|
||||||
void transact_retriesOptimisticLockExceptions() {
|
void transact_retriesOptimisticLockExceptions() {
|
||||||
JpaTransactionManager spyJpaTm = spy(jpaTm());
|
JpaTransactionManager spyJpaTm = spy(jpaTm());
|
||||||
doThrow(OptimisticLockException.class).when(spyJpaTm).delete(any(VKey.class));
|
doThrow(OptimisticLockException.class).when(spyJpaTm).delete(any(VKey.class));
|
||||||
spyJpaTm.transact(() -> spyJpaTm.saveNew(theEntity));
|
spyJpaTm.transact(() -> spyJpaTm.insert(theEntity));
|
||||||
assertThrows(
|
assertThrows(
|
||||||
OptimisticLockException.class,
|
OptimisticLockException.class,
|
||||||
() -> spyJpaTm.transact(() -> spyJpaTm.delete(theEntityKey)));
|
() -> spyJpaTm.transact(() -> spyJpaTm.delete(theEntityKey)));
|
||||||
|
@ -162,7 +162,7 @@ class JpaTransactionManagerImplTest {
|
||||||
void transactNoRetry_doesNotRetryOptimisticLockException() {
|
void transactNoRetry_doesNotRetryOptimisticLockException() {
|
||||||
JpaTransactionManager spyJpaTm = spy(jpaTm());
|
JpaTransactionManager spyJpaTm = spy(jpaTm());
|
||||||
doThrow(OptimisticLockException.class).when(spyJpaTm).delete(any(VKey.class));
|
doThrow(OptimisticLockException.class).when(spyJpaTm).delete(any(VKey.class));
|
||||||
spyJpaTm.transactNoRetry(() -> spyJpaTm.saveNew(theEntity));
|
spyJpaTm.transactNoRetry(() -> spyJpaTm.insert(theEntity));
|
||||||
assertThrows(
|
assertThrows(
|
||||||
OptimisticLockException.class,
|
OptimisticLockException.class,
|
||||||
() -> spyJpaTm.transactNoRetry(() -> spyJpaTm.delete(theEntityKey)));
|
() -> spyJpaTm.transactNoRetry(() -> spyJpaTm.delete(theEntityKey)));
|
||||||
|
@ -183,7 +183,7 @@ class JpaTransactionManagerImplTest {
|
||||||
doThrow(new RuntimeException().initCause(new OptimisticLockException()))
|
doThrow(new RuntimeException().initCause(new OptimisticLockException()))
|
||||||
.when(spyJpaTm)
|
.when(spyJpaTm)
|
||||||
.delete(any(VKey.class));
|
.delete(any(VKey.class));
|
||||||
spyJpaTm.transact(() -> spyJpaTm.saveNew(theEntity));
|
spyJpaTm.transact(() -> spyJpaTm.insert(theEntity));
|
||||||
assertThrows(
|
assertThrows(
|
||||||
RuntimeException.class, () -> spyJpaTm.transact(() -> spyJpaTm.delete(theEntityKey)));
|
RuntimeException.class, () -> spyJpaTm.transact(() -> spyJpaTm.delete(theEntityKey)));
|
||||||
verify(spyJpaTm, times(3)).delete(theEntityKey);
|
verify(spyJpaTm, times(3)).delete(theEntityKey);
|
||||||
|
@ -201,7 +201,7 @@ class JpaTransactionManagerImplTest {
|
||||||
void transactNewReadOnly_retriesJdbcConnectionExceptions() {
|
void transactNewReadOnly_retriesJdbcConnectionExceptions() {
|
||||||
JpaTransactionManager spyJpaTm = spy(jpaTm());
|
JpaTransactionManager spyJpaTm = spy(jpaTm());
|
||||||
doThrow(JDBCConnectionException.class).when(spyJpaTm).load(any(VKey.class));
|
doThrow(JDBCConnectionException.class).when(spyJpaTm).load(any(VKey.class));
|
||||||
spyJpaTm.transact(() -> spyJpaTm.saveNew(theEntity));
|
spyJpaTm.transact(() -> spyJpaTm.insert(theEntity));
|
||||||
assertThrows(
|
assertThrows(
|
||||||
JDBCConnectionException.class,
|
JDBCConnectionException.class,
|
||||||
() -> spyJpaTm.transactNewReadOnly(() -> spyJpaTm.load(theEntityKey)));
|
() -> spyJpaTm.transactNewReadOnly(() -> spyJpaTm.load(theEntityKey)));
|
||||||
|
@ -224,7 +224,7 @@ class JpaTransactionManagerImplTest {
|
||||||
.initCause(new JDBCConnectionException("connection exception", new SQLException())))
|
.initCause(new JDBCConnectionException("connection exception", new SQLException())))
|
||||||
.when(spyJpaTm)
|
.when(spyJpaTm)
|
||||||
.load(any(VKey.class));
|
.load(any(VKey.class));
|
||||||
spyJpaTm.transact(() -> spyJpaTm.saveNew(theEntity));
|
spyJpaTm.transact(() -> spyJpaTm.insert(theEntity));
|
||||||
assertThrows(
|
assertThrows(
|
||||||
RuntimeException.class,
|
RuntimeException.class,
|
||||||
() -> spyJpaTm.transactNewReadOnly(() -> spyJpaTm.load(theEntityKey)));
|
() -> spyJpaTm.transactNewReadOnly(() -> spyJpaTm.load(theEntityKey)));
|
||||||
|
@ -243,7 +243,7 @@ class JpaTransactionManagerImplTest {
|
||||||
void doTransactionless_retriesJdbcConnectionExceptions() {
|
void doTransactionless_retriesJdbcConnectionExceptions() {
|
||||||
JpaTransactionManager spyJpaTm = spy(jpaTm());
|
JpaTransactionManager spyJpaTm = spy(jpaTm());
|
||||||
doThrow(JDBCConnectionException.class).when(spyJpaTm).load(any(VKey.class));
|
doThrow(JDBCConnectionException.class).when(spyJpaTm).load(any(VKey.class));
|
||||||
spyJpaTm.transact(() -> spyJpaTm.saveNew(theEntity));
|
spyJpaTm.transact(() -> spyJpaTm.insert(theEntity));
|
||||||
assertThrows(
|
assertThrows(
|
||||||
RuntimeException.class,
|
RuntimeException.class,
|
||||||
() -> spyJpaTm.doTransactionless(() -> spyJpaTm.load(theEntityKey)));
|
() -> spyJpaTm.doTransactionless(() -> spyJpaTm.load(theEntityKey)));
|
||||||
|
@ -251,19 +251,19 @@ class JpaTransactionManagerImplTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void saveNew_throwsExceptionIfEntityExists() {
|
void insert_throwsExceptionIfEntityExists() {
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(theEntity));
|
jpaTm().transact(() -> jpaTm().insert(theEntity));
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isTrue();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isTrue();
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().load(theEntityKey))).isEqualTo(theEntity);
|
assertThat(jpaTm().transact(() -> jpaTm().load(theEntityKey))).isEqualTo(theEntity);
|
||||||
assertThrows(RollbackException.class, () -> jpaTm().transact(() -> jpaTm().saveNew(theEntity)));
|
assertThrows(RollbackException.class, () -> jpaTm().transact(() -> jpaTm().insert(theEntity)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createCompoundIdEntity_succeeds() {
|
void createCompoundIdEntity_succeeds() {
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(compoundIdEntity))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isFalse();
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(compoundIdEntity));
|
jpaTm().transact(() -> jpaTm().insert(compoundIdEntity));
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(compoundIdEntity))).isTrue();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isTrue();
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().load(compoundIdEntityKey)))
|
assertThat(jpaTm().transact(() -> jpaTm().load(compoundIdEntityKey)))
|
||||||
.isEqualTo(compoundIdEntity);
|
.isEqualTo(compoundIdEntity);
|
||||||
}
|
}
|
||||||
|
@ -271,10 +271,10 @@ class JpaTransactionManagerImplTest {
|
||||||
@Test
|
@Test
|
||||||
void saveAllNew_succeeds() {
|
void saveAllNew_succeeds() {
|
||||||
moreEntities.forEach(
|
moreEntities.forEach(
|
||||||
entity -> assertThat(jpaTm().transact(() -> jpaTm().checkExists(entity))).isFalse());
|
entity -> assertThat(jpaTm().transact(() -> jpaTm().exists(entity))).isFalse());
|
||||||
jpaTm().transact(() -> jpaTm().saveAllNew(moreEntities));
|
jpaTm().transact(() -> jpaTm().insertAll(moreEntities));
|
||||||
moreEntities.forEach(
|
moreEntities.forEach(
|
||||||
entity -> assertThat(jpaTm().transact(() -> jpaTm().checkExists(entity))).isTrue());
|
entity -> assertThat(jpaTm().transact(() -> jpaTm().exists(entity))).isTrue());
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().loadAll(TestEntity.class)))
|
assertThat(jpaTm().transact(() -> jpaTm().loadAll(TestEntity.class)))
|
||||||
.containsExactlyElementsIn(moreEntities);
|
.containsExactlyElementsIn(moreEntities);
|
||||||
}
|
}
|
||||||
|
@ -282,48 +282,48 @@ class JpaTransactionManagerImplTest {
|
||||||
@Test
|
@Test
|
||||||
void saveAllNew_rollsBackWhenFailure() {
|
void saveAllNew_rollsBackWhenFailure() {
|
||||||
moreEntities.forEach(
|
moreEntities.forEach(
|
||||||
entity -> assertThat(jpaTm().transact(() -> jpaTm().checkExists(entity))).isFalse());
|
entity -> assertThat(jpaTm().transact(() -> jpaTm().exists(entity))).isFalse());
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(moreEntities.get(0)));
|
jpaTm().transact(() -> jpaTm().insert(moreEntities.get(0)));
|
||||||
assertThrows(
|
assertThrows(
|
||||||
RollbackException.class, () -> jpaTm().transact(() -> jpaTm().saveAllNew(moreEntities)));
|
RollbackException.class, () -> jpaTm().transact(() -> jpaTm().insertAll(moreEntities)));
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(moreEntities.get(0)))).isTrue();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(moreEntities.get(0)))).isTrue();
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(moreEntities.get(1)))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(moreEntities.get(1)))).isFalse();
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(moreEntities.get(2)))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(moreEntities.get(2)))).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void saveNewOrUpdate_persistsNewEntity() {
|
void put_persistsNewEntity() {
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
|
||||||
jpaTm().transact(() -> jpaTm().saveNewOrUpdate(theEntity));
|
jpaTm().transact(() -> jpaTm().put(theEntity));
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isTrue();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isTrue();
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().load(theEntityKey))).isEqualTo(theEntity);
|
assertThat(jpaTm().transact(() -> jpaTm().load(theEntityKey))).isEqualTo(theEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void saveNewOrUpdate_updatesExistingEntity() {
|
void put_updatesExistingEntity() {
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(theEntity));
|
jpaTm().transact(() -> jpaTm().insert(theEntity));
|
||||||
TestEntity persisted = jpaTm().transact(() -> jpaTm().load(theEntityKey));
|
TestEntity persisted = jpaTm().transact(() -> jpaTm().load(theEntityKey));
|
||||||
assertThat(persisted.data).isEqualTo("foo");
|
assertThat(persisted.data).isEqualTo("foo");
|
||||||
theEntity.data = "bar";
|
theEntity.data = "bar";
|
||||||
jpaTm().transact(() -> jpaTm().saveNewOrUpdate(theEntity));
|
jpaTm().transact(() -> jpaTm().put(theEntity));
|
||||||
persisted = jpaTm().transact(() -> jpaTm().load(theEntityKey));
|
persisted = jpaTm().transact(() -> jpaTm().load(theEntityKey));
|
||||||
assertThat(persisted.data).isEqualTo("bar");
|
assertThat(persisted.data).isEqualTo("bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void saveNewOrUpdateAll_succeeds() {
|
void putAll_succeeds() {
|
||||||
moreEntities.forEach(
|
moreEntities.forEach(
|
||||||
entity -> assertThat(jpaTm().transact(() -> jpaTm().checkExists(entity))).isFalse());
|
entity -> assertThat(jpaTm().transact(() -> jpaTm().exists(entity))).isFalse());
|
||||||
jpaTm().transact(() -> jpaTm().saveNewOrUpdateAll(moreEntities));
|
jpaTm().transact(() -> jpaTm().putAll(moreEntities));
|
||||||
moreEntities.forEach(
|
moreEntities.forEach(
|
||||||
entity -> assertThat(jpaTm().transact(() -> jpaTm().checkExists(entity))).isTrue());
|
entity -> assertThat(jpaTm().transact(() -> jpaTm().exists(entity))).isTrue());
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().loadAll(TestEntity.class)))
|
assertThat(jpaTm().transact(() -> jpaTm().loadAll(TestEntity.class)))
|
||||||
.containsExactlyElementsIn(moreEntities);
|
.containsExactlyElementsIn(moreEntities);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void update_succeeds() {
|
void update_succeeds() {
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(theEntity));
|
jpaTm().transact(() -> jpaTm().insert(theEntity));
|
||||||
TestEntity persisted =
|
TestEntity persisted =
|
||||||
jpaTm().transact(() -> jpaTm().load(VKey.createSql(TestEntity.class, "theEntity")));
|
jpaTm().transact(() -> jpaTm().load(VKey.createSql(TestEntity.class, "theEntity")));
|
||||||
assertThat(persisted.data).isEqualTo("foo");
|
assertThat(persisted.data).isEqualTo("foo");
|
||||||
|
@ -335,7 +335,7 @@ class JpaTransactionManagerImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void updateCompoundIdEntity_succeeds() {
|
void updateCompoundIdEntity_succeeds() {
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(compoundIdEntity));
|
jpaTm().transact(() -> jpaTm().insert(compoundIdEntity));
|
||||||
TestCompoundIdEntity persisted = jpaTm().transact(() -> jpaTm().load(compoundIdEntityKey));
|
TestCompoundIdEntity persisted = jpaTm().transact(() -> jpaTm().load(compoundIdEntityKey));
|
||||||
assertThat(persisted.data).isEqualTo("foo");
|
assertThat(persisted.data).isEqualTo("foo");
|
||||||
compoundIdEntity.data = "bar";
|
compoundIdEntity.data = "bar";
|
||||||
|
@ -346,15 +346,15 @@ class JpaTransactionManagerImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void update_throwsExceptionWhenEntityDoesNotExist() {
|
void update_throwsExceptionWhenEntityDoesNotExist() {
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class, () -> jpaTm().transact(() -> jpaTm().update(theEntity)));
|
IllegalArgumentException.class, () -> jpaTm().transact(() -> jpaTm().update(theEntity)));
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void updateAll_succeeds() {
|
void updateAll_succeeds() {
|
||||||
jpaTm().transact(() -> jpaTm().saveAllNew(moreEntities));
|
jpaTm().transact(() -> jpaTm().insertAll(moreEntities));
|
||||||
ImmutableList<TestEntity> updated =
|
ImmutableList<TestEntity> updated =
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
new TestEntity("entity1", "foo_updated"),
|
new TestEntity("entity1", "foo_updated"),
|
||||||
|
@ -367,7 +367,7 @@ class JpaTransactionManagerImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void updateAll_rollsBackWhenFailure() {
|
void updateAll_rollsBackWhenFailure() {
|
||||||
jpaTm().transact(() -> jpaTm().saveAllNew(moreEntities));
|
jpaTm().transact(() -> jpaTm().insertAll(moreEntities));
|
||||||
ImmutableList<TestEntity> updated =
|
ImmutableList<TestEntity> updated =
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
new TestEntity("entity1", "foo_updated"),
|
new TestEntity("entity1", "foo_updated"),
|
||||||
|
@ -382,8 +382,8 @@ class JpaTransactionManagerImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void load_succeeds() {
|
void load_succeeds() {
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(theEntity));
|
jpaTm().transact(() -> jpaTm().insert(theEntity));
|
||||||
TestEntity persisted = jpaTm().transact(() -> jpaTm().load(theEntityKey));
|
TestEntity persisted = jpaTm().transact(() -> jpaTm().load(theEntityKey));
|
||||||
assertThat(persisted.name).isEqualTo("theEntity");
|
assertThat(persisted.name).isEqualTo("theEntity");
|
||||||
assertThat(persisted.data).isEqualTo("foo");
|
assertThat(persisted.data).isEqualTo("foo");
|
||||||
|
@ -391,15 +391,15 @@ class JpaTransactionManagerImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void load_throwsOnMissingElement() {
|
void load_throwsOnMissingElement() {
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
|
||||||
assertThrows(
|
assertThrows(
|
||||||
NoSuchElementException.class, () -> jpaTm().transact(() -> jpaTm().load(theEntityKey)));
|
NoSuchElementException.class, () -> jpaTm().transact(() -> jpaTm().load(theEntityKey)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void maybeLoad_succeeds() {
|
void maybeLoad_succeeds() {
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(theEntity));
|
jpaTm().transact(() -> jpaTm().insert(theEntity));
|
||||||
TestEntity persisted = jpaTm().transact(() -> jpaTm().maybeLoad(theEntityKey).get());
|
TestEntity persisted = jpaTm().transact(() -> jpaTm().maybeLoad(theEntityKey).get());
|
||||||
assertThat(persisted.name).isEqualTo("theEntity");
|
assertThat(persisted.name).isEqualTo("theEntity");
|
||||||
assertThat(persisted.data).isEqualTo("foo");
|
assertThat(persisted.data).isEqualTo("foo");
|
||||||
|
@ -407,14 +407,14 @@ class JpaTransactionManagerImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void maybeLoad_nonExistentObject() {
|
void maybeLoad_nonExistentObject() {
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().maybeLoad(theEntityKey)).isPresent()).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().maybeLoad(theEntityKey)).isPresent()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void loadCompoundIdEntity_succeeds() {
|
void loadCompoundIdEntity_succeeds() {
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(compoundIdEntity))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isFalse();
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(compoundIdEntity));
|
jpaTm().transact(() -> jpaTm().insert(compoundIdEntity));
|
||||||
TestCompoundIdEntity persisted = jpaTm().transact(() -> jpaTm().load(compoundIdEntityKey));
|
TestCompoundIdEntity persisted = jpaTm().transact(() -> jpaTm().load(compoundIdEntityKey));
|
||||||
assertThat(persisted.name).isEqualTo("compoundIdEntity");
|
assertThat(persisted.name).isEqualTo("compoundIdEntity");
|
||||||
assertThat(persisted.age).isEqualTo(10);
|
assertThat(persisted.age).isEqualTo(10);
|
||||||
|
@ -423,37 +423,37 @@ class JpaTransactionManagerImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void loadAll_succeeds() {
|
void loadAll_succeeds() {
|
||||||
jpaTm().transact(() -> jpaTm().saveAllNew(moreEntities));
|
jpaTm().transact(() -> jpaTm().insertAll(moreEntities));
|
||||||
ImmutableList<TestEntity> persisted = jpaTm().transact(() -> jpaTm().loadAll(TestEntity.class));
|
ImmutableList<TestEntity> persisted = jpaTm().transact(() -> jpaTm().loadAll(TestEntity.class));
|
||||||
assertThat(persisted).containsExactlyElementsIn(moreEntities);
|
assertThat(persisted).containsExactlyElementsIn(moreEntities);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void delete_succeeds() {
|
void delete_succeeds() {
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(theEntity));
|
jpaTm().transact(() -> jpaTm().insert(theEntity));
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isTrue();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isTrue();
|
||||||
jpaTm().transact(() -> jpaTm().delete(theEntityKey));
|
jpaTm().transact(() -> jpaTm().delete(theEntityKey));
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void delete_returnsZeroWhenNoEntity() {
|
void delete_returnsZeroWhenNoEntity() {
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
|
||||||
jpaTm().transact(() -> jpaTm().delete(theEntityKey));
|
jpaTm().transact(() -> jpaTm().delete(theEntityKey));
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void deleteCompoundIdEntity_succeeds() {
|
void deleteCompoundIdEntity_succeeds() {
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(compoundIdEntity));
|
jpaTm().transact(() -> jpaTm().insert(compoundIdEntity));
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(compoundIdEntity))).isTrue();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isTrue();
|
||||||
jpaTm().transact(() -> jpaTm().delete(compoundIdEntityKey));
|
jpaTm().transact(() -> jpaTm().delete(compoundIdEntityKey));
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(compoundIdEntity))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(compoundIdEntity))).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void assertDelete_throwsExceptionWhenEntityNotDeleted() {
|
void assertDelete_throwsExceptionWhenEntityNotDeleted() {
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(theEntity))).isFalse();
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() -> jpaTm().transact(() -> jpaTm().assertDelete(theEntityKey)));
|
() -> jpaTm().transact(() -> jpaTm().assertDelete(theEntityKey)));
|
||||||
|
|
|
@ -107,7 +107,7 @@ public class TransactionManagerTest {
|
||||||
() ->
|
() ->
|
||||||
tm().transact(
|
tm().transact(
|
||||||
() -> {
|
() -> {
|
||||||
tm().saveNew(theEntity);
|
tm().insert(theEntity);
|
||||||
throw new RuntimeException();
|
throw new RuntimeException();
|
||||||
}));
|
}));
|
||||||
assertEntityNotExist(theEntity);
|
assertEntityNotExist(theEntity);
|
||||||
|
@ -116,21 +116,21 @@ public class TransactionManagerTest {
|
||||||
@TestTemplate
|
@TestTemplate
|
||||||
void transact_reusesExistingTransaction() {
|
void transact_reusesExistingTransaction() {
|
||||||
assertEntityNotExist(theEntity);
|
assertEntityNotExist(theEntity);
|
||||||
tm().transact(() -> tm().transact(() -> tm().saveNew(theEntity)));
|
tm().transact(() -> tm().transact(() -> tm().insert(theEntity)));
|
||||||
assertEntityExists(theEntity);
|
assertEntityExists(theEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestTemplate
|
@TestTemplate
|
||||||
void transactNew_succeeds() {
|
void transactNew_succeeds() {
|
||||||
assertEntityNotExist(theEntity);
|
assertEntityNotExist(theEntity);
|
||||||
tm().transactNew(() -> tm().saveNew(theEntity));
|
tm().transactNew(() -> tm().insert(theEntity));
|
||||||
assertEntityExists(theEntity);
|
assertEntityExists(theEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestTemplate
|
@TestTemplate
|
||||||
void transactNewReadOnly_succeeds() {
|
void transactNewReadOnly_succeeds() {
|
||||||
assertEntityNotExist(theEntity);
|
assertEntityNotExist(theEntity);
|
||||||
tm().transact(() -> tm().saveNew(theEntity));
|
tm().transact(() -> tm().insert(theEntity));
|
||||||
assertEntityExists(theEntity);
|
assertEntityExists(theEntity);
|
||||||
TestEntity persisted = tm().transactNewReadOnly(() -> tm().load(theEntity.key()));
|
TestEntity persisted = tm().transactNewReadOnly(() -> tm().load(theEntity.key()));
|
||||||
assertThat(persisted).isEqualTo(theEntity);
|
assertThat(persisted).isEqualTo(theEntity);
|
||||||
|
@ -140,14 +140,14 @@ public class TransactionManagerTest {
|
||||||
void transactNewReadOnly_throwsWhenWritingEntity() {
|
void transactNewReadOnly_throwsWhenWritingEntity() {
|
||||||
assertEntityNotExist(theEntity);
|
assertEntityNotExist(theEntity);
|
||||||
assertThrows(
|
assertThrows(
|
||||||
RuntimeException.class, () -> tm().transactNewReadOnly(() -> tm().saveNew(theEntity)));
|
RuntimeException.class, () -> tm().transactNewReadOnly(() -> tm().insert(theEntity)));
|
||||||
assertEntityNotExist(theEntity);
|
assertEntityNotExist(theEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestTemplate
|
@TestTemplate
|
||||||
void saveNew_succeeds() {
|
void saveNew_succeeds() {
|
||||||
assertEntityNotExist(theEntity);
|
assertEntityNotExist(theEntity);
|
||||||
tm().transact(() -> tm().saveNew(theEntity));
|
tm().transact(() -> tm().insert(theEntity));
|
||||||
assertEntityExists(theEntity);
|
assertEntityExists(theEntity);
|
||||||
assertThat(tm().transact(() -> tm().load(theEntity.key()))).isEqualTo(theEntity);
|
assertThat(tm().transact(() -> tm().load(theEntity.key()))).isEqualTo(theEntity);
|
||||||
}
|
}
|
||||||
|
@ -155,26 +155,26 @@ public class TransactionManagerTest {
|
||||||
@TestTemplate
|
@TestTemplate
|
||||||
void saveAllNew_succeeds() {
|
void saveAllNew_succeeds() {
|
||||||
assertAllEntitiesNotExist(moreEntities);
|
assertAllEntitiesNotExist(moreEntities);
|
||||||
tm().transact(() -> tm().saveAllNew(moreEntities));
|
tm().transact(() -> tm().insertAll(moreEntities));
|
||||||
assertAllEntitiesExist(moreEntities);
|
assertAllEntitiesExist(moreEntities);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestTemplate
|
@TestTemplate
|
||||||
void saveNewOrUpdate_persistsNewEntity() {
|
void saveNewOrUpdate_persistsNewEntity() {
|
||||||
assertEntityNotExist(theEntity);
|
assertEntityNotExist(theEntity);
|
||||||
tm().transact(() -> tm().saveNewOrUpdate(theEntity));
|
tm().transact(() -> tm().put(theEntity));
|
||||||
assertEntityExists(theEntity);
|
assertEntityExists(theEntity);
|
||||||
assertThat(tm().transact(() -> tm().load(theEntity.key()))).isEqualTo(theEntity);
|
assertThat(tm().transact(() -> tm().load(theEntity.key()))).isEqualTo(theEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestTemplate
|
@TestTemplate
|
||||||
void saveNewOrUpdate_updatesExistingEntity() {
|
void saveNewOrUpdate_updatesExistingEntity() {
|
||||||
tm().transact(() -> tm().saveNew(theEntity));
|
tm().transact(() -> tm().insert(theEntity));
|
||||||
TestEntity persisted = tm().transact(() -> tm().load(theEntity.key()));
|
TestEntity persisted = tm().transact(() -> tm().load(theEntity.key()));
|
||||||
assertThat(persisted.data).isEqualTo("foo");
|
assertThat(persisted.data).isEqualTo("foo");
|
||||||
theEntity.data = "bar";
|
theEntity.data = "bar";
|
||||||
fakeClock.advanceOneMilli();
|
fakeClock.advanceOneMilli();
|
||||||
tm().transact(() -> tm().saveNewOrUpdate(theEntity));
|
tm().transact(() -> tm().put(theEntity));
|
||||||
persisted = tm().transact(() -> tm().load(theEntity.key()));
|
persisted = tm().transact(() -> tm().load(theEntity.key()));
|
||||||
assertThat(persisted.data).isEqualTo("bar");
|
assertThat(persisted.data).isEqualTo("bar");
|
||||||
}
|
}
|
||||||
|
@ -182,13 +182,13 @@ public class TransactionManagerTest {
|
||||||
@TestTemplate
|
@TestTemplate
|
||||||
void saveNewOrUpdateAll_succeeds() {
|
void saveNewOrUpdateAll_succeeds() {
|
||||||
assertAllEntitiesNotExist(moreEntities);
|
assertAllEntitiesNotExist(moreEntities);
|
||||||
tm().transact(() -> tm().saveNewOrUpdateAll(moreEntities));
|
tm().transact(() -> tm().putAll(moreEntities));
|
||||||
assertAllEntitiesExist(moreEntities);
|
assertAllEntitiesExist(moreEntities);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestTemplate
|
@TestTemplate
|
||||||
void update_succeeds() {
|
void update_succeeds() {
|
||||||
tm().transact(() -> tm().saveNew(theEntity));
|
tm().transact(() -> tm().insert(theEntity));
|
||||||
TestEntity persisted =
|
TestEntity persisted =
|
||||||
tm().transact(
|
tm().transact(
|
||||||
() ->
|
() ->
|
||||||
|
@ -205,7 +205,7 @@ public class TransactionManagerTest {
|
||||||
@TestTemplate
|
@TestTemplate
|
||||||
void load_succeeds() {
|
void load_succeeds() {
|
||||||
assertEntityNotExist(theEntity);
|
assertEntityNotExist(theEntity);
|
||||||
tm().transact(() -> tm().saveNew(theEntity));
|
tm().transact(() -> tm().insert(theEntity));
|
||||||
TestEntity persisted = tm().transact(() -> tm().load(theEntity.key()));
|
TestEntity persisted = tm().transact(() -> tm().load(theEntity.key()));
|
||||||
assertThat(persisted.name).isEqualTo("theEntity");
|
assertThat(persisted.name).isEqualTo("theEntity");
|
||||||
assertThat(persisted.data).isEqualTo("foo");
|
assertThat(persisted.data).isEqualTo("foo");
|
||||||
|
@ -221,7 +221,7 @@ public class TransactionManagerTest {
|
||||||
@TestTemplate
|
@TestTemplate
|
||||||
void maybeLoad_succeeds() {
|
void maybeLoad_succeeds() {
|
||||||
assertEntityNotExist(theEntity);
|
assertEntityNotExist(theEntity);
|
||||||
tm().transact(() -> tm().saveNew(theEntity));
|
tm().transact(() -> tm().insert(theEntity));
|
||||||
TestEntity persisted = tm().transact(() -> tm().maybeLoad(theEntity.key()).get());
|
TestEntity persisted = tm().transact(() -> tm().maybeLoad(theEntity.key()).get());
|
||||||
assertThat(persisted.name).isEqualTo("theEntity");
|
assertThat(persisted.name).isEqualTo("theEntity");
|
||||||
assertThat(persisted.data).isEqualTo("foo");
|
assertThat(persisted.data).isEqualTo("foo");
|
||||||
|
@ -235,7 +235,7 @@ public class TransactionManagerTest {
|
||||||
|
|
||||||
@TestTemplate
|
@TestTemplate
|
||||||
void delete_succeeds() {
|
void delete_succeeds() {
|
||||||
tm().transact(() -> tm().saveNew(theEntity));
|
tm().transact(() -> tm().insert(theEntity));
|
||||||
assertEntityExists(theEntity);
|
assertEntityExists(theEntity);
|
||||||
fakeClock.advanceOneMilli();
|
fakeClock.advanceOneMilli();
|
||||||
tm().transact(() -> tm().delete(theEntity.key()));
|
tm().transact(() -> tm().delete(theEntity.key()));
|
||||||
|
@ -252,7 +252,7 @@ public class TransactionManagerTest {
|
||||||
@TestTemplate
|
@TestTemplate
|
||||||
void delete_succeedsForEntitySet() {
|
void delete_succeedsForEntitySet() {
|
||||||
assertAllEntitiesNotExist(moreEntities);
|
assertAllEntitiesNotExist(moreEntities);
|
||||||
tm().transact(() -> tm().saveAllNew(moreEntities));
|
tm().transact(() -> tm().insertAll(moreEntities));
|
||||||
Set<VKey<TestEntity>> keys =
|
Set<VKey<TestEntity>> keys =
|
||||||
moreEntities.stream().map(TestEntity::key).collect(toImmutableSet());
|
moreEntities.stream().map(TestEntity::key).collect(toImmutableSet());
|
||||||
assertAllEntitiesExist(moreEntities);
|
assertAllEntitiesExist(moreEntities);
|
||||||
|
@ -264,7 +264,7 @@ public class TransactionManagerTest {
|
||||||
@TestTemplate
|
@TestTemplate
|
||||||
void delete_ignoreNonExistentEntity() {
|
void delete_ignoreNonExistentEntity() {
|
||||||
assertAllEntitiesNotExist(moreEntities);
|
assertAllEntitiesNotExist(moreEntities);
|
||||||
tm().transact(() -> tm().saveAllNew(moreEntities));
|
tm().transact(() -> tm().insertAll(moreEntities));
|
||||||
List<VKey<TestEntity>> keys =
|
List<VKey<TestEntity>> keys =
|
||||||
moreEntities.stream().map(TestEntity::key).collect(toImmutableList());
|
moreEntities.stream().map(TestEntity::key).collect(toImmutableList());
|
||||||
assertAllEntitiesExist(moreEntities);
|
assertAllEntitiesExist(moreEntities);
|
||||||
|
@ -279,7 +279,7 @@ public class TransactionManagerTest {
|
||||||
@TestTemplate
|
@TestTemplate
|
||||||
void load_multi() {
|
void load_multi() {
|
||||||
assertAllEntitiesNotExist(moreEntities);
|
assertAllEntitiesNotExist(moreEntities);
|
||||||
tm().transact(() -> tm().saveAllNew(moreEntities));
|
tm().transact(() -> tm().insertAll(moreEntities));
|
||||||
List<VKey<TestEntity>> keys =
|
List<VKey<TestEntity>> keys =
|
||||||
moreEntities.stream().map(TestEntity::key).collect(toImmutableList());
|
moreEntities.stream().map(TestEntity::key).collect(toImmutableList());
|
||||||
assertThat(tm().transact(() -> tm().load(keys)))
|
assertThat(tm().transact(() -> tm().load(keys)))
|
||||||
|
@ -289,7 +289,7 @@ public class TransactionManagerTest {
|
||||||
@TestTemplate
|
@TestTemplate
|
||||||
void load_multiWithDuplicateKeys() {
|
void load_multiWithDuplicateKeys() {
|
||||||
assertAllEntitiesNotExist(moreEntities);
|
assertAllEntitiesNotExist(moreEntities);
|
||||||
tm().transact(() -> tm().saveAllNew(moreEntities));
|
tm().transact(() -> tm().insertAll(moreEntities));
|
||||||
ImmutableList<VKey<TestEntity>> keys =
|
ImmutableList<VKey<TestEntity>> keys =
|
||||||
moreEntities.stream().map(TestEntity::key).collect(toImmutableList());
|
moreEntities.stream().map(TestEntity::key).collect(toImmutableList());
|
||||||
ImmutableList<VKey<TestEntity>> doubleKeys =
|
ImmutableList<VKey<TestEntity>> doubleKeys =
|
||||||
|
@ -301,7 +301,7 @@ public class TransactionManagerTest {
|
||||||
@TestTemplate
|
@TestTemplate
|
||||||
void load_multiMissingKeys() {
|
void load_multiMissingKeys() {
|
||||||
assertAllEntitiesNotExist(moreEntities);
|
assertAllEntitiesNotExist(moreEntities);
|
||||||
tm().transact(() -> tm().saveAllNew(moreEntities));
|
tm().transact(() -> tm().insertAll(moreEntities));
|
||||||
List<VKey<TestEntity>> keys =
|
List<VKey<TestEntity>> keys =
|
||||||
Stream.concat(moreEntities.stream(), Stream.of(new TestEntity("dark", "matter")))
|
Stream.concat(moreEntities.stream(), Stream.of(new TestEntity("dark", "matter")))
|
||||||
.map(TestEntity::key)
|
.map(TestEntity::key)
|
||||||
|
@ -311,11 +311,11 @@ public class TransactionManagerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertEntityExists(TestEntity entity) {
|
private static void assertEntityExists(TestEntity entity) {
|
||||||
assertThat(tm().transact(() -> tm().checkExists(entity))).isTrue();
|
assertThat(tm().transact(() -> tm().exists(entity))).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertEntityNotExist(TestEntity entity) {
|
private static void assertEntityNotExist(TestEntity entity) {
|
||||||
assertThat(tm().transact(() -> tm().checkExists(entity))).isFalse();
|
assertThat(tm().transact(() -> tm().exists(entity))).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertAllEntitiesExist(ImmutableList<TestEntity> entities) {
|
private static void assertAllEntitiesExist(ImmutableList<TestEntity> entities) {
|
||||||
|
|
|
@ -66,7 +66,7 @@ class TransactionTest {
|
||||||
|
|
||||||
txn = new Transaction.Builder().addDelete(barEntity.key()).build();
|
txn = new Transaction.Builder().addDelete(barEntity.key()).build();
|
||||||
txn.writeToDatastore();
|
txn.writeToDatastore();
|
||||||
assertThat(ofyTm().checkExists(barEntity.key())).isEqualTo(false);
|
assertThat(ofyTm().exists(barEntity.key())).isEqualTo(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -83,7 +83,7 @@ class TransactionTest {
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
assertThat(ofyTm().load(fooEntity.key())).isEqualTo(fooEntity);
|
assertThat(ofyTm().load(fooEntity.key())).isEqualTo(fooEntity);
|
||||||
assertThat(ofyTm().checkExists(barEntity.key())).isEqualTo(false);
|
assertThat(ofyTm().exists(barEntity.key())).isEqualTo(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,8 +107,8 @@ class TransactionTest {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
jpaTm().saveNew(fooEntity);
|
jpaTm().insert(fooEntity);
|
||||||
jpaTm().saveNew(barEntity);
|
jpaTm().insert(barEntity);
|
||||||
});
|
});
|
||||||
TransactionEntity txnEnt =
|
TransactionEntity txnEnt =
|
||||||
jpaTm().transact(() -> jpaTm().load(VKey.createSql(TransactionEntity.class, 1L)));
|
jpaTm().transact(() -> jpaTm().load(VKey.createSql(TransactionEntity.class, 1L)));
|
||||||
|
@ -123,8 +123,7 @@ class TransactionTest {
|
||||||
|
|
||||||
// Verify that no transaction was persisted for the load transaction.
|
// Verify that no transaction was persisted for the load transaction.
|
||||||
assertThat(
|
assertThat(
|
||||||
jpaTm()
|
jpaTm().transact(() -> jpaTm().exists(VKey.createSql(TransactionEntity.class, 2L))))
|
||||||
.transact(() -> jpaTm().checkExists(VKey.createSql(TransactionEntity.class, 2L))))
|
|
||||||
.isFalse();
|
.isFalse();
|
||||||
} finally {
|
} finally {
|
||||||
RegistryConfig.overrideCloudSqlReplicateTransactions(false);
|
RegistryConfig.overrideCloudSqlReplicateTransactions(false);
|
||||||
|
@ -136,12 +135,10 @@ class TransactionTest {
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
() -> {
|
() -> {
|
||||||
jpaTm().saveNew(fooEntity);
|
jpaTm().insert(fooEntity);
|
||||||
jpaTm().saveNew(barEntity);
|
jpaTm().insert(barEntity);
|
||||||
});
|
});
|
||||||
assertThat(
|
assertThat(jpaTm().transact(() -> jpaTm().exists(VKey.createSql(TransactionEntity.class, 1L))))
|
||||||
jpaTm()
|
|
||||||
.transact(() -> jpaTm().checkExists(VKey.createSql(TransactionEntity.class, 1L))))
|
|
||||||
.isFalse();
|
.isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ class RdeStagingMapperTest {
|
||||||
// Set Registrar states which are required for reporting.
|
// Set Registrar states which are required for reporting.
|
||||||
tm().transact(
|
tm().transact(
|
||||||
() ->
|
() ->
|
||||||
tm().saveNewOrUpdateAll(
|
tm().putAll(
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
externalMonitoringRegistrar.asBuilder().setState(State.ACTIVE).build(),
|
externalMonitoringRegistrar.asBuilder().setState(State.ACTIVE).build(),
|
||||||
testRegistrar.asBuilder().setState(State.ACTIVE).build(),
|
testRegistrar.asBuilder().setState(State.ACTIVE).build(),
|
||||||
|
|
|
@ -65,7 +65,7 @@ class RegistrarContactTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testPersistence_succeeds() {
|
void testPersistence_succeeds() {
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(testRegistrarPoc));
|
jpaTm().transact(() -> jpaTm().insert(testRegistrarPoc));
|
||||||
RegistrarContact persisted =
|
RegistrarContact persisted =
|
||||||
jpaTm().transact(() -> jpaTm().load(testRegistrarPoc.createVKey()));
|
jpaTm().transact(() -> jpaTm().load(testRegistrarPoc.createVKey()));
|
||||||
assertThat(persisted).isEqualTo(testRegistrarPoc);
|
assertThat(persisted).isEqualTo(testRegistrarPoc);
|
||||||
|
|
|
@ -70,14 +70,14 @@ public class RegistrarDaoTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void saveNew_worksSuccessfully() {
|
void saveNew_worksSuccessfully() {
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(testRegistrar))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(testRegistrar))).isFalse();
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(testRegistrar));
|
jpaTm().transact(() -> jpaTm().insert(testRegistrar));
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(testRegistrar))).isTrue();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(testRegistrar))).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void update_worksSuccessfully() {
|
void update_worksSuccessfully() {
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(testRegistrar));
|
jpaTm().transact(() -> jpaTm().insert(testRegistrar));
|
||||||
Registrar persisted = jpaTm().transact(() -> jpaTm().load(registrarKey));
|
Registrar persisted = jpaTm().transact(() -> jpaTm().load(registrarKey));
|
||||||
assertThat(persisted.getRegistrarName()).isEqualTo("registrarName");
|
assertThat(persisted.getRegistrarName()).isEqualTo("registrarName");
|
||||||
jpaTm()
|
jpaTm()
|
||||||
|
@ -92,7 +92,7 @@ public class RegistrarDaoTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void update_throwsExceptionWhenEntityDoesNotExist() {
|
void update_throwsExceptionWhenEntityDoesNotExist() {
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(testRegistrar))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(testRegistrar))).isFalse();
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() -> jpaTm().transact(() -> jpaTm().update(testRegistrar)));
|
() -> jpaTm().transact(() -> jpaTm().update(testRegistrar)));
|
||||||
|
@ -100,8 +100,8 @@ public class RegistrarDaoTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void load_worksSuccessfully() {
|
void load_worksSuccessfully() {
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(testRegistrar))).isFalse();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(testRegistrar))).isFalse();
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(testRegistrar));
|
jpaTm().transact(() -> jpaTm().insert(testRegistrar));
|
||||||
Registrar persisted = jpaTm().transact(() -> jpaTm().load(registrarKey));
|
Registrar persisted = jpaTm().transact(() -> jpaTm().load(registrarKey));
|
||||||
|
|
||||||
assertThat(persisted.getClientId()).isEqualTo("registrarId");
|
assertThat(persisted.getClientId()).isEqualTo("registrarId");
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class SqlHelper {
|
||||||
|
|
||||||
public static Registrar saveRegistrar(String clientId) {
|
public static Registrar saveRegistrar(String clientId) {
|
||||||
Registrar registrar = makeRegistrar1().asBuilder().setClientId(clientId).build();
|
Registrar registrar = makeRegistrar1().asBuilder().setClientId(clientId).build();
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(registrar));
|
jpaTm().transact(() -> jpaTm().insert(registrar));
|
||||||
return jpaTm().transact(() -> jpaTm().load(registrar.createVKey()));
|
return jpaTm().transact(() -> jpaTm().load(registrar.createVKey()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,7 @@ class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarCommand>
|
||||||
Optional<Registrar> registrar = Registrar.loadByClientId("clientz");
|
Optional<Registrar> registrar = Registrar.loadByClientId("clientz");
|
||||||
assertThat(registrar).isPresent();
|
assertThat(registrar).isPresent();
|
||||||
assertThat(registrar.get().verifyPassword("some_password")).isTrue();
|
assertThat(registrar.get().verifyPassword("some_password")).isTrue();
|
||||||
assertThat(jpaTm().transact(() -> jpaTm().checkExists(registrar.get()))).isTrue();
|
assertThat(jpaTm().transact(() -> jpaTm().exists(registrar.get()))).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -47,7 +47,7 @@ class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarCommand>
|
||||||
@Test
|
@Test
|
||||||
void testSuccess_alsoUpdateInCloudSql() throws Exception {
|
void testSuccess_alsoUpdateInCloudSql() throws Exception {
|
||||||
assertThat(loadRegistrar("NewRegistrar").verifyPassword("some_password")).isFalse();
|
assertThat(loadRegistrar("NewRegistrar").verifyPassword("some_password")).isFalse();
|
||||||
jpaTm().transact(() -> jpaTm().saveNew(loadRegistrar("NewRegistrar")));
|
jpaTm().transact(() -> jpaTm().insert(loadRegistrar("NewRegistrar")));
|
||||||
runCommand("--password=some_password", "--force", "NewRegistrar");
|
runCommand("--password=some_password", "--force", "NewRegistrar");
|
||||||
assertThat(loadRegistrar("NewRegistrar").verifyPassword("some_password")).isTrue();
|
assertThat(loadRegistrar("NewRegistrar").verifyPassword("some_password")).isTrue();
|
||||||
assertThat(
|
assertThat(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue