1
0
mirror of https://github.com/google/nomulus synced 2026-04-25 10:40:49 +00:00

Add/use more DatabaseHelper convenience methods (#1327)

* Add/use more DatabaseHelper convenience methods

This also fixes up some existing uses of "put" in test code that should be
inserts or updates (depending on which is intended). Doing an insert/update
makes stronger guarantees about an entity either not existing or existing,
depending on what you're doing.

* Convert more Object -> ImmutableObject

* Merge branch 'master' into tx-manager-sigs

* Revert breaking PremiumListDao change

* Refactor more insertInDb()

* Fight more testing errors

* Merge branch 'master' into tx-manager-sigs

* Merge branch 'master' into tx-manager-sigs

* Merge branch 'master' into tx-manager-sigs

* Merge branch 'master' into tx-manager-sigs

* Add removeTmOverrideForTest() calls

* Merge branch 'master' into tx-manager-sigs
This commit is contained in:
Ben McIlwain
2021-09-28 17:16:54 -04:00
committed by GitHub
parent 420a0b8b9a
commit b05b77cfd1
34 changed files with 449 additions and 558 deletions

View File

@@ -134,7 +134,7 @@ public class DatastoreTransactionManager implements TransactionManager {
}
@Override
public void insertWithoutBackup(Object entity) {
public void insertWithoutBackup(ImmutableObject entity) {
putWithoutBackup(entity);
}
@@ -160,7 +160,7 @@ public class DatastoreTransactionManager implements TransactionManager {
}
@Override
public void putWithoutBackup(Object entity) {
public void putWithoutBackup(ImmutableObject entity) {
syncIfTransactionless(getOfy().saveWithoutBackup().entities(toDatastoreEntity(entity)));
}
@@ -180,12 +180,12 @@ public class DatastoreTransactionManager implements TransactionManager {
}
@Override
public void updateAll(Object... entities) {
updateAll(ImmutableList.of(entities));
public void updateAll(ImmutableObject... entities) {
updateAll(ImmutableList.copyOf(entities));
}
@Override
public void updateWithoutBackup(Object entity) {
public void updateWithoutBackup(ImmutableObject entity) {
putWithoutBackup(entity);
}

View File

@@ -318,7 +318,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
}
@Override
public void insertWithoutBackup(Object entity) {
public void insertWithoutBackup(ImmutableObject entity) {
insert(entity);
}
@@ -356,7 +356,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
}
@Override
public void putWithoutBackup(Object entity) {
public void putWithoutBackup(ImmutableObject entity) {
put(entity);
}
@@ -386,12 +386,12 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
}
@Override
public void updateAll(Object... entities) {
updateAll(ImmutableList.of(entities));
public void updateAll(ImmutableObject... entities) {
updateAll(ImmutableList.copyOf(entities));
}
@Override
public void updateWithoutBackup(Object entity) {
public void updateWithoutBackup(ImmutableObject entity) {
update(entity);
}

View File

@@ -111,7 +111,7 @@ public interface TransactionManager {
* "WithoutBackup" in its method name because it is not necessary to have the backup mechanism in
* SQL.
*/
void insertWithoutBackup(Object entity);
void insertWithoutBackup(ImmutableObject entity);
/**
* Persists all new entities in the database without writing any backup if the underlying database
@@ -144,7 +144,7 @@ public interface TransactionManager {
* "WithoutBackup" in its method name because it is not necessary to have the backup mechanism in
* SQL.
*/
void putWithoutBackup(Object entity);
void putWithoutBackup(ImmutableObject entity);
/**
* Persists all new entities or update the existing entities in the database without writing
@@ -165,7 +165,7 @@ public interface TransactionManager {
void updateAll(ImmutableCollection<?> entities);
/** Updates all entities in the database, throws exception if any entity does not exist. */
void updateAll(Object... entities);
void updateAll(ImmutableObject... entities);
/**
* Updates an entity in the database without writing commit logs if the underlying database is
@@ -177,7 +177,7 @@ public interface TransactionManager {
* "WithoutBackup" in its method name because it is not necessary to have the backup mechanism in
* SQL.
*/
void updateWithoutBackup(Object entity);
void updateWithoutBackup(ImmutableObject entity);
/**
* Updates all entities in the database without writing any backup if the underlying database is

View File

@@ -132,7 +132,9 @@ public class TransactionManagerFactory {
/**
* Sets the return of {@link #tm()} to the given instance of {@link TransactionManager}.
*
* <p>Used when overriding the per-test transaction manager for dual-database tests.
* <p>Used when overriding the per-test transaction manager for dual-database tests. Should be
* matched with a corresponding invocation of {@link #removeTmOverrideForTest()} either at the end
* of the test or in an <code>@AfterEach</code> handler.
*/
@VisibleForTesting
public static void setTmForTest(TransactionManager newTm) {