mirror of
https://github.com/google/nomulus.git
synced 2025-04-29 19:47:51 +02:00
Add a jpaTm().query(...) convenience method (#1023)
* Add a jpaTm().query(...) convenience method This replaces the more ungainly jpaTm().getEntityManager().createQuery(...). Note that this is in JpaTransactionManager, not the parent TransactionManager, because this is not an operation that Datastore can support. Once we finish migrating away from Datastore this won't matter anyway because JpaTransactionManager will be merged into TransactionManager and then deleted. In the process of writing this PR I discovered several other methods available on the EntityManager that may merit their own convenience methods if we start using them enough. The more commonly used ones will be addressed in subsequent PRs. They are: jpaTm().getEntityManager().getMetamodel().entity(...).getName() jpaTm().getEntityManager().getCriteriaBuilder().createQuery(...) jpaTm().getEntityManager().createNativeQuery(...) jpaTm().getEntityManager().find(...) This PR also addresses some existing callsites that were calling getEntityManager() rather than using extant convenience methods, such as jpa().insert(...).
This commit is contained in:
parent
c827ea033a
commit
4ed23f6813
57 changed files with 166 additions and 177 deletions
|
@ -196,7 +196,7 @@ PRESUBMITS = {
|
|||
# - concatenation of literals: (\s*\+\s*"([^"]|\\")*")*
|
||||
# Line 3: , or the closing parenthesis, marking the end of the first
|
||||
# parameter
|
||||
r'.*\.create(Native)?Query\('
|
||||
r'.*\.(query|createQuery|createNativeQuery)\('
|
||||
r'(?!(\s*([A-Z_]+|"([^"]|\\")*"(\s*\+\s*"([^"]|\\")*")*)'
|
||||
r'(,|\s*\))))',
|
||||
"java",
|
||||
|
@ -206,6 +206,7 @@ PRESUBMITS = {
|
|||
# using Criteria
|
||||
"ForeignKeyIndex.java",
|
||||
"HistoryEntryDao.java",
|
||||
"JpaTransactionManager.java",
|
||||
"JpaTransactionManagerImpl.java",
|
||||
# CriteriaQueryBuilder is a false positive
|
||||
"CriteriaQueryBuilder.java",
|
||||
|
|
|
@ -300,10 +300,9 @@ public class BigqueryConnection implements AutoCloseable {
|
|||
* Initializes the BigqueryConnection object by setting up the API client and creating the default
|
||||
* dataset if it doesn't exist.
|
||||
*/
|
||||
private BigqueryConnection initialize() throws Exception {
|
||||
private void initialize() throws Exception {
|
||||
createDatasetIfNeeded(datasetId);
|
||||
createDatasetIfNeeded(TEMP_DATASET_NAME);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -378,13 +377,11 @@ public class BigqueryConnection implements AutoCloseable {
|
|||
|
||||
/**
|
||||
* Starts an asynchronous load job to populate the specified destination table with the given
|
||||
* source URIs and source format. Returns a ListenableFuture that holds the same destination
|
||||
* table object on success.
|
||||
* source URIs and source format. Returns a ListenableFuture that holds the same destination table
|
||||
* object on success.
|
||||
*/
|
||||
public ListenableFuture<DestinationTable> load(
|
||||
DestinationTable dest,
|
||||
SourceFormat sourceFormat,
|
||||
Iterable<String> sourceUris) {
|
||||
public ListenableFuture<DestinationTable> startLoad(
|
||||
DestinationTable dest, SourceFormat sourceFormat, Iterable<String> sourceUris) {
|
||||
Job job = new Job()
|
||||
.setConfiguration(new JobConfiguration()
|
||||
.setLoad(new JobConfigurationLoad()
|
||||
|
@ -400,9 +397,7 @@ public class BigqueryConnection implements AutoCloseable {
|
|||
* of the specified query, or if the table is a view, to update the view to reflect that query.
|
||||
* Returns a ListenableFuture that holds the same destination table object on success.
|
||||
*/
|
||||
public ListenableFuture<DestinationTable> query(
|
||||
String querySql,
|
||||
DestinationTable dest) {
|
||||
public ListenableFuture<DestinationTable> startQuery(String querySql, DestinationTable dest) {
|
||||
if (dest.type == TableType.VIEW) {
|
||||
// Use Futures.transform() rather than calling apply() directly so that any exceptions thrown
|
||||
// by calling updateTable will be propagated on the get() call, not from here.
|
||||
|
@ -562,20 +557,18 @@ public class BigqueryConnection implements AutoCloseable {
|
|||
// Tracking bug for query-to-GCS support is b/13777340.
|
||||
DestinationTable tempTable = buildTemporaryTable().build();
|
||||
return transformAsync(
|
||||
query(querySql, tempTable),
|
||||
startQuery(querySql, tempTable),
|
||||
tempTable1 -> extractTable(tempTable1, destinationUri, destinationFormat, printHeader),
|
||||
directExecutor());
|
||||
}
|
||||
|
||||
/** @see #runJob(Job, AbstractInputStreamContent) */
|
||||
public Job runJob(Job job) {
|
||||
private Job runJob(Job job) {
|
||||
return runJob(job, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch a job, wait for it to complete, but <i>do not</i> check for errors.
|
||||
*/
|
||||
public Job runJob(Job job, @Nullable AbstractInputStreamContent data) {
|
||||
/** Launch a job, wait for it to complete, but <i>do not</i> check for errors. */
|
||||
private Job runJob(Job job, @Nullable AbstractInputStreamContent data) {
|
||||
return checkJob(waitForJob(launchJob(job, data)));
|
||||
}
|
||||
|
||||
|
|
|
@ -1093,8 +1093,7 @@ public class DomainFlowUtils {
|
|||
.list();
|
||||
} else {
|
||||
return jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery(
|
||||
.query(
|
||||
"FROM DomainHistory WHERE modificationTime >= :beginning "
|
||||
+ "ORDER BY modificationTime ASC",
|
||||
DomainHistory.class)
|
||||
|
|
|
@ -58,16 +58,16 @@ class CommitLogManifestReader
|
|||
|
||||
@Override
|
||||
public QueryResultIterator<Key<CommitLogManifest>> getQueryIterator(@Nullable Cursor cursor) {
|
||||
return startQueryAt(query(), cursor).keys().iterator();
|
||||
return startQueryAt(createBucketQuery(), cursor).keys().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotal() {
|
||||
return query().count();
|
||||
return createBucketQuery().count();
|
||||
}
|
||||
|
||||
/** Query for children of this bucket. */
|
||||
Query<CommitLogManifest> query() {
|
||||
Query<CommitLogManifest> createBucketQuery() {
|
||||
Query<CommitLogManifest> query = ofy().load().type(CommitLogManifest.class).ancestor(bucketKey);
|
||||
if (olderThan != null) {
|
||||
query = query.filterKey(
|
||||
|
|
|
@ -418,8 +418,7 @@ public final class EppResourceUtils {
|
|||
if (isContactKey) {
|
||||
query =
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery(CONTACT_LINKED_DOMAIN_QUERY, String.class)
|
||||
.query(CONTACT_LINKED_DOMAIN_QUERY, String.class)
|
||||
.setParameter("fkRepoId", key)
|
||||
.setParameter("now", now);
|
||||
} else {
|
||||
|
|
|
@ -378,13 +378,11 @@ public class DomainContent extends EppResource
|
|||
public static void beforeSqlDelete(VKey<DomainBase> key) {
|
||||
// Delete all grace periods associated with the domain.
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery("DELETE FROM GracePeriod WHERE domain_repo_id = :repo_id")
|
||||
.query("DELETE FROM GracePeriod WHERE domain_repo_id = :repo_id")
|
||||
.setParameter("repo_id", key.getSqlKey())
|
||||
.executeUpdate();
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery("DELETE FROM DelegationSignerData WHERE domain_repo_id = :repo_id")
|
||||
.query("DELETE FROM DelegationSignerData WHERE domain_repo_id = :repo_id")
|
||||
.setParameter("repo_id", key.getSqlKey())
|
||||
.executeUpdate();
|
||||
}
|
||||
|
|
|
@ -204,8 +204,7 @@ public abstract class ForeignKeyIndex<E extends EppResource> extends BackupGroup
|
|||
String entityName =
|
||||
jpaTm().getEntityManager().getMetamodel().entity(clazz).getName();
|
||||
return jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery(
|
||||
.query(
|
||||
String.format(
|
||||
"FROM %s WHERE %s IN :propertyValue and deletionTime > :now ",
|
||||
entityName, property),
|
||||
|
|
|
@ -651,8 +651,7 @@ public class Registrar extends ImmutableObject
|
|||
return tm().transact(
|
||||
() ->
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery(
|
||||
.query(
|
||||
"FROM RegistrarPoc WHERE registrarId = :registrarId",
|
||||
RegistrarContact.class)
|
||||
.setParameter("registrarId", clientIdentifier)
|
||||
|
|
|
@ -20,7 +20,6 @@ import static google.registry.persistence.transaction.TransactionManagerFactory.
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import google.registry.schema.domain.RegistryLock;
|
||||
import java.util.Optional;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
/** Data access object for {@link google.registry.schema.domain.RegistryLock}. */
|
||||
public final class RegistryLockDao {
|
||||
|
@ -34,15 +33,16 @@ public final class RegistryLockDao {
|
|||
/** Returns the most recent version of the {@link RegistryLock} referred to by the code. */
|
||||
public static Optional<RegistryLock> getByVerificationCode(String verificationCode) {
|
||||
jpaTm().assertInTransaction();
|
||||
EntityManager em = jpaTm().getEntityManager();
|
||||
Long revisionId =
|
||||
em.createQuery(
|
||||
jpaTm()
|
||||
.query(
|
||||
"SELECT MAX(revisionId) FROM RegistryLock WHERE verificationCode ="
|
||||
+ " :verificationCode",
|
||||
Long.class)
|
||||
.setParameter("verificationCode", verificationCode)
|
||||
.getSingleResult();
|
||||
return Optional.ofNullable(revisionId).map(revision -> em.find(RegistryLock.class, revision));
|
||||
return Optional.ofNullable(revisionId)
|
||||
.map(revision -> jpaTm().getEntityManager().find(RegistryLock.class, revision));
|
||||
}
|
||||
|
||||
/** Returns all lock objects that this registrar has created, including pending locks. */
|
||||
|
@ -50,8 +50,7 @@ public final class RegistryLockDao {
|
|||
jpaTm().assertInTransaction();
|
||||
return ImmutableList.copyOf(
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery(
|
||||
.query(
|
||||
"SELECT lock FROM RegistryLock lock"
|
||||
+ " WHERE lock.registrarId = :registrarId"
|
||||
+ " AND lock.unlockCompletionTimestamp IS NULL"
|
||||
|
@ -69,8 +68,7 @@ public final class RegistryLockDao {
|
|||
public static Optional<RegistryLock> getMostRecentByRepoId(String repoId) {
|
||||
jpaTm().assertInTransaction();
|
||||
return jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery(
|
||||
.query(
|
||||
"SELECT lock FROM RegistryLock lock WHERE lock.repoId = :repoId"
|
||||
+ " ORDER BY lock.revisionId DESC",
|
||||
RegistryLock.class)
|
||||
|
@ -89,8 +87,7 @@ public final class RegistryLockDao {
|
|||
public static Optional<RegistryLock> getMostRecentVerifiedLockByRepoId(String repoId) {
|
||||
jpaTm().assertInTransaction();
|
||||
return jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery(
|
||||
.query(
|
||||
"SELECT lock FROM RegistryLock lock WHERE lock.repoId = :repoId AND"
|
||||
+ " lock.lockCompletionTimestamp IS NOT NULL AND"
|
||||
+ " lock.unlockCompletionTimestamp IS NULL ORDER BY lock.revisionId"
|
||||
|
@ -111,8 +108,7 @@ public final class RegistryLockDao {
|
|||
public static Optional<RegistryLock> getMostRecentVerifiedUnlockByRepoId(String repoId) {
|
||||
jpaTm().assertInTransaction();
|
||||
return jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery(
|
||||
.query(
|
||||
"SELECT lock FROM RegistryLock lock WHERE lock.repoId = :repoId AND"
|
||||
+ " lock.unlockCompletionTimestamp IS NOT NULL ORDER BY lock.revisionId"
|
||||
+ " DESC",
|
||||
|
|
|
@ -50,8 +50,7 @@ public class ReservedListSqlDao {
|
|||
.transact(
|
||||
() ->
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery(
|
||||
.query(
|
||||
"FROM ReservedList rl LEFT JOIN FETCH rl.reservedListMap WHERE"
|
||||
+ " rl.revisionId IN (SELECT MAX(revisionId) FROM ReservedList subrl"
|
||||
+ " WHERE subrl.name = :name)",
|
||||
|
@ -71,8 +70,7 @@ public class ReservedListSqlDao {
|
|||
.transact(
|
||||
() ->
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery("SELECT 1 FROM ReservedList WHERE name = :name", Integer.class)
|
||||
.query("SELECT 1 FROM ReservedList WHERE name = :name", Integer.class)
|
||||
.setParameter("name", reservedListName)
|
||||
.setMaxResults(1)
|
||||
.getResultList()
|
||||
|
|
|
@ -31,7 +31,6 @@ import google.registry.model.host.HostHistory;
|
|||
import google.registry.model.host.HostResource;
|
||||
import google.registry.persistence.VKey;
|
||||
import java.util.Comparator;
|
||||
import javax.persistence.EntityManager;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
|
@ -90,15 +89,14 @@ public class HistoryEntryDao {
|
|||
VKey<? extends EppResource> parentKey, DateTime afterTime, DateTime beforeTime) {
|
||||
Class<? extends HistoryEntry> historyClass = getHistoryClassFromParent(parentKey.getKind());
|
||||
String repoIdFieldName = getRepoIdFieldNameFromHistoryClass(historyClass);
|
||||
EntityManager entityManager = jpaTm().getEntityManager();
|
||||
String tableName = entityManager.getMetamodel().entity(historyClass).getName();
|
||||
String tableName = jpaTm().getEntityManager().getMetamodel().entity(historyClass).getName();
|
||||
String queryString =
|
||||
String.format(
|
||||
"SELECT entry FROM %s entry WHERE entry.modificationTime >= :afterTime AND "
|
||||
+ "entry.modificationTime <= :beforeTime AND entry.%s = :parentKey",
|
||||
tableName, repoIdFieldName);
|
||||
return entityManager
|
||||
.createQuery(queryString, historyClass)
|
||||
return jpaTm()
|
||||
.query(queryString, historyClass)
|
||||
.setParameter("afterTime", afterTime)
|
||||
.setParameter("beforeTime", beforeTime)
|
||||
.setParameter("parentKey", parentKey.getSqlKey().toString())
|
||||
|
@ -129,13 +127,12 @@ public class HistoryEntryDao {
|
|||
|
||||
private static Iterable<? extends HistoryEntry> loadAllHistoryObjectsFromSql(
|
||||
Class<? extends HistoryEntry> historyClass, DateTime afterTime, DateTime beforeTime) {
|
||||
EntityManager entityManager = jpaTm().getEntityManager();
|
||||
return entityManager
|
||||
.createQuery(
|
||||
return jpaTm()
|
||||
.query(
|
||||
String.format(
|
||||
"SELECT entry FROM %s entry WHERE entry.modificationTime >= :afterTime AND "
|
||||
+ "entry.modificationTime <= :beforeTime",
|
||||
entityManager.getMetamodel().entity(historyClass).getName()),
|
||||
jpaTm().getEntityManager().getMetamodel().entity(historyClass).getName()),
|
||||
historyClass)
|
||||
.setParameter("afterTime", afterTime)
|
||||
.setParameter("beforeTime", beforeTime)
|
||||
|
|
|
@ -32,8 +32,7 @@ public class Spec11ThreatMatchDao {
|
|||
public static void deleteEntriesByDate(JpaTransactionManager jpaTm, LocalDate date) {
|
||||
jpaTm.assertInTransaction();
|
||||
jpaTm
|
||||
.getEntityManager()
|
||||
.createQuery("DELETE FROM Spec11ThreatMatch WHERE check_date = :date")
|
||||
.query("DELETE FROM Spec11ThreatMatch WHERE check_date = :date")
|
||||
.setParameter("date", DateTimeUtils.toSqlDate(date), TemporalType.DATE)
|
||||
.executeUpdate();
|
||||
}
|
||||
|
@ -44,8 +43,7 @@ public class Spec11ThreatMatchDao {
|
|||
jpaTm.assertInTransaction();
|
||||
return ImmutableList.copyOf(
|
||||
jpaTm
|
||||
.getEntityManager()
|
||||
.createQuery(
|
||||
.query(
|
||||
"SELECT match FROM Spec11ThreatMatch match WHERE match.checkDate = :date",
|
||||
Spec11ThreatMatch.class)
|
||||
.setParameter("date", date)
|
||||
|
|
|
@ -42,8 +42,7 @@ public class KmsSecretRevisionSqlDao {
|
|||
checkArgument(!isNullOrEmpty(secretName), "secretName cannot be null or empty");
|
||||
jpaTm().assertInTransaction();
|
||||
return jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery(
|
||||
.query(
|
||||
"FROM KmsSecret ks WHERE ks.revisionKey IN (SELECT MAX(revisionKey) FROM "
|
||||
+ "KmsSecret subKs WHERE subKs.secretName = :secretName)",
|
||||
KmsSecretRevision.class)
|
||||
|
|
|
@ -40,7 +40,6 @@ import google.registry.model.common.DatabaseTransitionSchedule.TransitionId;
|
|||
import google.registry.util.CollectionUtils;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import javax.persistence.EntityManager;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
public class SignedMarkRevocationListDao {
|
||||
|
@ -153,11 +152,12 @@ public class SignedMarkRevocationListDao {
|
|||
return jpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
EntityManager em = jpaTm().getEntityManager();
|
||||
Long revisionId =
|
||||
em.createQuery("SELECT MAX(revisionId) FROM SignedMarkRevocationList", Long.class)
|
||||
jpaTm()
|
||||
.query("SELECT MAX(revisionId) FROM SignedMarkRevocationList", Long.class)
|
||||
.getSingleResult();
|
||||
return em.createQuery(
|
||||
return jpaTm()
|
||||
.query(
|
||||
"FROM SignedMarkRevocationList smrl LEFT JOIN FETCH smrl.revokes "
|
||||
+ "WHERE smrl.revisionId = :revisionId",
|
||||
SignedMarkRevocationList.class)
|
||||
|
@ -196,7 +196,7 @@ public class SignedMarkRevocationListDao {
|
|||
}
|
||||
|
||||
private static void saveToCloudSql(SignedMarkRevocationList signedMarkRevocationList) {
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(signedMarkRevocationList));
|
||||
jpaTm().transact(() -> jpaTm().insert(signedMarkRevocationList));
|
||||
logger.atInfo().log(
|
||||
"Inserted %,d signed mark revocations into Cloud SQL.",
|
||||
signedMarkRevocationList.revokes.size());
|
||||
|
|
|
@ -17,14 +17,13 @@ package google.registry.model.tmch;
|
|||
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
|
||||
|
||||
import java.util.Optional;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
/** Data access object for {@link ClaimsListShard}. */
|
||||
public class ClaimsListSqlDao {
|
||||
|
||||
/** Saves the given {@link ClaimsListShard} to Cloud SQL. */
|
||||
static void save(ClaimsListShard claimsList) {
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(claimsList));
|
||||
jpaTm().transact(() -> jpaTm().insert(claimsList));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -35,11 +34,12 @@ public class ClaimsListSqlDao {
|
|||
return jpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
EntityManager em = jpaTm().getEntityManager();
|
||||
Long revisionId =
|
||||
em.createQuery("SELECT MAX(revisionId) FROM ClaimsList", Long.class)
|
||||
jpaTm()
|
||||
.query("SELECT MAX(revisionId) FROM ClaimsList", Long.class)
|
||||
.getSingleResult();
|
||||
return em.createQuery(
|
||||
return jpaTm()
|
||||
.query(
|
||||
"FROM ClaimsList cl LEFT JOIN FETCH cl.labelsToKeys WHERE cl.revisionId ="
|
||||
+ " :revisionId",
|
||||
ClaimsListShard.class)
|
||||
|
|
|
@ -79,10 +79,7 @@ public final class TmchCrl extends CrossTldSingleton implements NonReplicatedEnt
|
|||
.transactNew(
|
||||
() -> {
|
||||
// Delete the old one and insert the new one
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery("DELETE FROM TmchCrl")
|
||||
.executeUpdate();
|
||||
jpaTm().query("DELETE FROM TmchCrl").executeUpdate();
|
||||
jpaTm().putWithoutBackup(tmchCrl);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -17,6 +17,8 @@ package google.registry.persistence.transaction;
|
|||
import google.registry.persistence.VKey;
|
||||
import java.util.function.Supplier;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
import javax.persistence.TypedQuery;
|
||||
|
||||
/** Sub-interface of {@link TransactionManager} which defines JPA related methods. */
|
||||
public interface JpaTransactionManager extends TransactionManager {
|
||||
|
@ -24,6 +26,22 @@ public interface JpaTransactionManager extends TransactionManager {
|
|||
/** Returns the {@link EntityManager} for the current request. */
|
||||
EntityManager getEntityManager();
|
||||
|
||||
/**
|
||||
* Creates a JPA SQL query for the given query string and result class.
|
||||
*
|
||||
* <p>This is a convenience method for the longer <code>
|
||||
* jpaTm().getEntityManager().createQuery(...)</code>.
|
||||
*/
|
||||
<T> TypedQuery<T> query(String sqlString, Class<T> resultClass);
|
||||
|
||||
/**
|
||||
* Creates a JPA SQL query for the given query string (which does not return results).
|
||||
*
|
||||
* <p>This is a convenience method for the longer <code>
|
||||
* jpaTm().getEntityManager().createQuery(...)</code>.
|
||||
*/
|
||||
Query query(String sqlString);
|
||||
|
||||
/** Executes the work in a transaction with no retries and returns the result. */
|
||||
<T> T transactNoRetry(Supplier<T> work);
|
||||
|
||||
|
|
|
@ -104,6 +104,16 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
|||
return transactionInfo.get().entityManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> TypedQuery<T> query(String sqlString, Class<T> resultClass) {
|
||||
return getEntityManager().createQuery(sqlString, resultClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query query(String sqlString) {
|
||||
return getEntityManager().createQuery(sqlString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inTransaction() {
|
||||
return transactionInfo.get().inTransaction;
|
||||
|
@ -365,8 +375,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
|||
private boolean exists(String entityName, ImmutableSet<EntityId> entityIds) {
|
||||
assertInTransaction();
|
||||
TypedQuery<Integer> query =
|
||||
getEntityManager()
|
||||
.createQuery(
|
||||
query(
|
||||
String.format("SELECT 1 FROM %s WHERE %s", entityName, getAndClause(entityIds)),
|
||||
Integer.class)
|
||||
.setMaxResults(1);
|
||||
|
@ -470,7 +479,7 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
|||
// TODO(b/179158393): use Criteria for query to leave not doubt about sql injection risk.
|
||||
String sql =
|
||||
String.format("DELETE FROM %s WHERE %s", entityType.getName(), getAndClause(entityIds));
|
||||
Query query = getEntityManager().createQuery(sql);
|
||||
Query query = query(sql);
|
||||
entityIds.forEach(entityId -> query.setParameter(entityId.name, entityId.value));
|
||||
transactionInfo.get().addDelete(key);
|
||||
return query.executeUpdate();
|
||||
|
|
|
@ -106,14 +106,17 @@ public class IcannReportingStager {
|
|||
throws ExecutionException, InterruptedException {
|
||||
// Later views depend on the results of earlier ones, so query everything synchronously
|
||||
logger.atInfo().log("Generating intermediary view %s", queryName);
|
||||
bigquery.query(
|
||||
query,
|
||||
bigquery.buildDestinationTable(queryName)
|
||||
.description(String.format(
|
||||
"An intermediary view to generate %s reports for this month.", reportType))
|
||||
.type(TableType.VIEW)
|
||||
.build()
|
||||
).get();
|
||||
bigquery
|
||||
.startQuery(
|
||||
query,
|
||||
bigquery
|
||||
.buildDestinationTable(queryName)
|
||||
.description(
|
||||
String.format(
|
||||
"An intermediary view to generate %s reports for this month.", reportType))
|
||||
.type(TableType.VIEW)
|
||||
.build())
|
||||
.get();
|
||||
}
|
||||
|
||||
private Iterable<String> getHeaders(ImmutableSet<TableFieldSchema> fields) {
|
||||
|
|
|
@ -57,8 +57,7 @@ class ReplicateToDatastoreAction implements Runnable {
|
|||
.transact(
|
||||
() ->
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery(
|
||||
.query(
|
||||
"SELECT txn FROM TransactionEntity txn WHERE id >"
|
||||
+ " :lastId ORDER BY id")
|
||||
.setParameter("lastId", lastSqlTxnBeforeBatch.getTransactionId())
|
||||
|
|
|
@ -39,8 +39,7 @@ public class SqlReplayCheckpoint implements SqlEntity {
|
|||
public static DateTime get() {
|
||||
jpaTm().assertInTransaction();
|
||||
return jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery("FROM SqlReplayCheckpoint", SqlReplayCheckpoint.class)
|
||||
.query("FROM SqlReplayCheckpoint", SqlReplayCheckpoint.class)
|
||||
.setMaxResults(1)
|
||||
.getResultStream()
|
||||
.findFirst()
|
||||
|
|
|
@ -33,7 +33,7 @@ public class LockDao {
|
|||
jpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
jpaTm().getEntityManager().merge(lock);
|
||||
jpaTm().put(lock);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ public class LockDao {
|
|||
() -> {
|
||||
Optional<Lock> loadedLock = load(resourceName, tld);
|
||||
if (loadedLock.isPresent()) {
|
||||
jpaTm().getEntityManager().remove(loadedLock.get());
|
||||
jpaTm().delete(loadedLock.get());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -159,7 +159,7 @@ public class PremiumListSqlDao {
|
|||
}
|
||||
|
||||
public static PremiumList save(PremiumList premiumList) {
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(premiumList));
|
||||
jpaTm().transact(() -> jpaTm().insert(premiumList));
|
||||
premiumListCache.invalidate(premiumList.getName());
|
||||
return premiumList;
|
||||
}
|
||||
|
@ -174,8 +174,7 @@ public class PremiumListSqlDao {
|
|||
.transact(
|
||||
() ->
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery(
|
||||
.query(
|
||||
"FROM PremiumList WHERE name = :name ORDER BY revisionId DESC",
|
||||
PremiumList.class)
|
||||
.setParameter("name", premiumListName)
|
||||
|
@ -194,8 +193,7 @@ public class PremiumListSqlDao {
|
|||
.transact(
|
||||
() ->
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery(
|
||||
.query(
|
||||
"FROM PremiumEntry pe WHERE pe.revisionId = :revisionId",
|
||||
PremiumEntry.class)
|
||||
.setParameter("revisionId", premiumList.getRevisionId())
|
||||
|
@ -211,8 +209,7 @@ public class PremiumListSqlDao {
|
|||
.transact(
|
||||
() ->
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery(
|
||||
.query(
|
||||
"SELECT pe.price FROM PremiumEntry pe WHERE pe.revisionId = :revisionId"
|
||||
+ " AND pe.domainLabel = :label",
|
||||
BigDecimal.class)
|
||||
|
|
|
@ -79,12 +79,14 @@ final class LoadSnapshotCommand extends BigqueryCommand {
|
|||
|
||||
/** Starts a load job for the specified kind name, sourcing data from the given GCS file. */
|
||||
private ListenableFuture<?> loadSnapshotFile(String filename, String kindName) {
|
||||
return bigquery().load(
|
||||
bigquery().buildDestinationTable(kindName)
|
||||
.description("Datastore snapshot import for " + kindName + ".")
|
||||
.build(),
|
||||
SourceFormat.DATASTORE_BACKUP,
|
||||
ImmutableList.of(filename));
|
||||
return bigquery()
|
||||
.startLoad(
|
||||
bigquery()
|
||||
.buildDestinationTable(kindName)
|
||||
.description("Datastore snapshot import for " + kindName + ".")
|
||||
.build(),
|
||||
SourceFormat.DATASTORE_BACKUP,
|
||||
ImmutableList.of(filename));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -207,8 +207,7 @@ public class BackfillSpec11ThreatMatchesCommand extends ConfirmingCommand
|
|||
.transact(
|
||||
() ->
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery(
|
||||
.query(
|
||||
"SELECT DISTINCT stm.checkDate FROM Spec11ThreatMatch stm", LocalDate.class)
|
||||
.getResultStream()
|
||||
.collect(toImmutableSet()));
|
||||
|
|
|
@ -71,8 +71,7 @@ public class ReservedListSqlDaoTest {
|
|||
() -> {
|
||||
ReservedList persistedList =
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery("FROM ReservedList WHERE name = :name", ReservedList.class)
|
||||
.query("FROM ReservedList WHERE name = :name", ReservedList.class)
|
||||
.setParameter("name", "testlist")
|
||||
.getSingleResult();
|
||||
assertThat(persistedList.getReservedListEntries())
|
||||
|
|
|
@ -74,8 +74,7 @@ public class ServerSecretTest extends EntityTestCase {
|
|||
.transact(
|
||||
() ->
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery("FROM ServerSecret", ServerSecret.class)
|
||||
.query("FROM ServerSecret", ServerSecret.class)
|
||||
.setMaxResults(1)
|
||||
.getResultStream()
|
||||
.findFirst()
|
||||
|
|
|
@ -149,10 +149,7 @@ public class SignedMarkRevocationListTest {
|
|||
}
|
||||
jpaTm()
|
||||
.transact(
|
||||
() ->
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.persist(SignedMarkRevocationList.create(clock.nowUtc(), revokes.build())));
|
||||
() -> jpaTm().insert(SignedMarkRevocationList.create(clock.nowUtc(), revokes.build())));
|
||||
RuntimeException thrown =
|
||||
assertThrows(RuntimeException.class, () -> SignedMarkRevocationList.get());
|
||||
assertThat(thrown).hasMessageThat().contains("Unequal SignedMarkRevocationList detected:");
|
||||
|
|
|
@ -57,10 +57,7 @@ public class TmchCrlTest extends EntityTestCase {
|
|||
.transact(
|
||||
() ->
|
||||
assertThat(
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery("SELECT COUNT(*) FROM TmchCrl", Long.class)
|
||||
.getSingleResult())
|
||||
jpaTm().query("SELECT COUNT(*) FROM TmchCrl", Long.class).getSingleResult())
|
||||
.isEqualTo(1L));
|
||||
}
|
||||
|
||||
|
@ -69,8 +66,7 @@ public class TmchCrlTest extends EntityTestCase {
|
|||
.transact(
|
||||
() ->
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery("FROM TmchCrl", TmchCrl.class)
|
||||
.query("FROM TmchCrl", TmchCrl.class)
|
||||
.setMaxResults(1)
|
||||
.getResultStream()
|
||||
.findFirst()
|
||||
|
|
|
@ -74,7 +74,7 @@ class EntityCallbacksListenerTest {
|
|||
.transact(
|
||||
() -> {
|
||||
TestEntity removed = jpaTm().loadByKey(VKey.createSql(TestEntity.class, "id"));
|
||||
jpaTm().getEntityManager().remove(removed);
|
||||
jpaTm().delete(removed);
|
||||
return removed;
|
||||
});
|
||||
checkAll(testRemove, 0, 0, 1, 1);
|
||||
|
|
|
@ -59,7 +59,7 @@ public class AllocationTokenStatusTransitionConverterTest {
|
|||
TimedTransitionProperty.fromValueMap(values, TokenStatusTransition.class);
|
||||
AllocationTokenStatusTransitionConverterTestEntity testEntity =
|
||||
new AllocationTokenStatusTransitionConverterTestEntity(timedTransitionProperty);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
AllocationTokenStatusTransitionConverterTestEntity persisted =
|
||||
jpaTm()
|
||||
.transact(
|
||||
|
|
|
@ -54,7 +54,7 @@ public class BillingCostTransitionConverterTest {
|
|||
TimedTransitionProperty<Money, BillingCostTransition> timedTransitionProperty =
|
||||
TimedTransitionProperty.fromValueMap(values, BillingCostTransition.class);
|
||||
TestEntity testEntity = new TestEntity(timedTransitionProperty);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.timedTransitionProperty).containsExactlyEntriesIn(timedTransitionProperty);
|
||||
|
|
|
@ -41,7 +41,7 @@ class BloomFilterConverterTest {
|
|||
BloomFilter<String> bloomFilter = BloomFilter.create(stringFunnel(US_ASCII), 3);
|
||||
ImmutableSet.of("foo", "bar", "baz").forEach(bloomFilter::put);
|
||||
TestEntity entity = new TestEntity(bloomFilter);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(entity));
|
||||
jpaTm().transact(() -> jpaTm().insert(entity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.bloomFilter).isEqualTo(bloomFilter);
|
||||
|
|
|
@ -45,7 +45,7 @@ public class CidrAddressBlockListConverterTest {
|
|||
CidrAddressBlock.create("8000::/1"),
|
||||
CidrAddressBlock.create("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128"));
|
||||
TestEntity testEntity = new TestEntity(addresses);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.addresses).isEqualTo(addresses);
|
||||
|
|
|
@ -45,7 +45,7 @@ public class CreateAutoTimestampConverterTest {
|
|||
CreateAutoTimestamp ts = CreateAutoTimestamp.create(DateTime.parse("2019-09-9T11:39:00Z"));
|
||||
TestEntity ent = new TestEntity("myinst", ts);
|
||||
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(ent));
|
||||
jpaTm().transact(() -> jpaTm().insert(ent));
|
||||
TestEntity result =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "myinst"));
|
||||
assertThat(result).isEqualTo(new TestEntity("myinst", ts));
|
||||
|
@ -56,7 +56,7 @@ public class CreateAutoTimestampConverterTest {
|
|||
CreateAutoTimestamp ts = CreateAutoTimestamp.create(null);
|
||||
TestEntity ent = new TestEntity("autoinit", ts);
|
||||
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(ent));
|
||||
jpaTm().transact(() -> jpaTm().insert(ent));
|
||||
|
||||
TestEntity result =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "autoinit"));
|
||||
|
|
|
@ -48,7 +48,7 @@ public class CurrencyToBillingConverterTest {
|
|||
CurrencyUnit.of("CNY"),
|
||||
new BillingAccountEntry(CurrencyUnit.of("CNY"), "accountId2"));
|
||||
TestEntity testEntity = new TestEntity(currencyToBilling);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.currencyToBilling).containsExactlyEntriesIn(currencyToBilling);
|
||||
|
|
|
@ -39,7 +39,7 @@ public class CurrencyUnitConverterTest {
|
|||
@Test
|
||||
void roundTripConversion() {
|
||||
TestEntity entity = new TestEntity(CurrencyUnit.EUR);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(entity));
|
||||
jpaTm().transact(() -> jpaTm().insert(entity));
|
||||
assertThat(
|
||||
jpaTm()
|
||||
.transact(
|
||||
|
|
|
@ -69,7 +69,7 @@ public class DateTimeConverterTest {
|
|||
void converter_generatesTimestampWithNormalizedZone() {
|
||||
DateTime dt = parseDateTime("2019-09-01T01:01:01Z");
|
||||
TestEntity entity = new TestEntity("normalized_utc_time", dt);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(entity));
|
||||
jpaTm().transact(() -> jpaTm().insert(entity));
|
||||
TestEntity retrievedEntity =
|
||||
jpaTm()
|
||||
.transact(
|
||||
|
@ -82,7 +82,7 @@ public class DateTimeConverterTest {
|
|||
DateTime dt = parseDateTime("2019-09-01T01:01:01-05:00");
|
||||
TestEntity entity = new TestEntity("new_york_time", dt);
|
||||
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(entity));
|
||||
jpaTm().transact(() -> jpaTm().insert(entity));
|
||||
TestEntity retrievedEntity =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "new_york_time"));
|
||||
assertThat(retrievedEntity.dt.toString()).isEqualTo("2019-09-01T06:01:01.000Z");
|
||||
|
|
|
@ -71,7 +71,7 @@ public class JodaMoneyConverterTest {
|
|||
void roundTripConversion() {
|
||||
Money money = Money.of(CurrencyUnit.USD, 100);
|
||||
TestEntity entity = new TestEntity(money);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(entity));
|
||||
jpaTm().transact(() -> jpaTm().insert(entity));
|
||||
List<?> result =
|
||||
jpaTm()
|
||||
.transact(
|
||||
|
@ -101,7 +101,7 @@ public class JodaMoneyConverterTest {
|
|||
"dos", Money.ofMajor(CurrencyUnit.JPY, 2000),
|
||||
"tres", Money.of(CurrencyUnit.GBP, 20));
|
||||
ComplexTestEntity entity = new ComplexTestEntity(moneyMap, myMoney, yourMoney);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(entity));
|
||||
jpaTm().transact(() -> jpaTm().insert(entity));
|
||||
List<?> result =
|
||||
jpaTm()
|
||||
.transact(
|
||||
|
|
|
@ -46,7 +46,7 @@ public class LongVKeyConverterTest {
|
|||
new TestLongEntity(
|
||||
VKey.createSql(TestLongEntity.class, 10L),
|
||||
VKey.createSql(CompositeKeyTestLongEntity.class, 20L));
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(original));
|
||||
jpaTm().transact(() -> jpaTm().insert(original));
|
||||
|
||||
TestLongEntity retrieved =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestLongEntity.class, "id"));
|
||||
|
|
|
@ -67,7 +67,7 @@ class PremiumListKeyConverterTest {
|
|||
void testRoundTrip() {
|
||||
Key<PremiumList> key = Key.create(getCrossTldKey(), PremiumList.class, "test");
|
||||
PremiumListEntity testEntity = new PremiumListEntity(key);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
PremiumListEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(PremiumListEntity.class, "test"));
|
||||
assertThat(persisted.premiumList).isEqualTo(key);
|
||||
|
|
|
@ -47,7 +47,7 @@ class ReservedListKeySetConverterTest {
|
|||
|
||||
Set<Key<ReservedList>> reservedLists = ImmutableSet.of(key1, key2, key3);
|
||||
ReservedListSetEntity testEntity = new ReservedListSetEntity(reservedLists);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
ReservedListSetEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(ReservedListSetEntity.class, "id"));
|
||||
assertThat(persisted.reservedList).containsExactly(key1, key2, key3);
|
||||
|
@ -56,7 +56,7 @@ class ReservedListKeySetConverterTest {
|
|||
@Test
|
||||
void testNullValue_writesAndReadsNullSuccessfully() {
|
||||
ReservedListSetEntity testEntity = new ReservedListSetEntity(null);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
ReservedListSetEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(ReservedListSetEntity.class, "id"));
|
||||
assertThat(persisted.reservedList).isNull();
|
||||
|
@ -65,7 +65,7 @@ class ReservedListKeySetConverterTest {
|
|||
@Test
|
||||
void testEmptyCollection_writesAndReadsEmptyCollectionSuccessfully() {
|
||||
ReservedListSetEntity testEntity = new ReservedListSetEntity(ImmutableSet.of());
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
ReservedListSetEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(ReservedListSetEntity.class, "id"));
|
||||
assertThat(persisted.reservedList).isEmpty();
|
||||
|
|
|
@ -39,7 +39,7 @@ public class StatusValueSetConverterTest {
|
|||
Set<StatusValue> enums = ImmutableSet.of(StatusValue.INACTIVE, StatusValue.PENDING_DELETE);
|
||||
TestEntity obj = new TestEntity("foo", enums);
|
||||
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(obj));
|
||||
jpaTm().transact(() -> jpaTm().insert(obj));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "foo"));
|
||||
assertThat(persisted.data).isEqualTo(enums);
|
||||
|
|
|
@ -40,7 +40,7 @@ public class StringListConverterTest {
|
|||
void roundTripConversion_returnsSameStringList() {
|
||||
List<String> tlds = ImmutableList.of("app", "dev", "how");
|
||||
TestEntity testEntity = new TestEntity(tlds);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.tlds).containsExactly("app", "dev", "how");
|
||||
|
@ -50,7 +50,7 @@ public class StringListConverterTest {
|
|||
void testMerge_succeeds() {
|
||||
List<String> tlds = ImmutableList.of("app", "dev", "how");
|
||||
TestEntity testEntity = new TestEntity(tlds);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
persisted.tlds = ImmutableList.of("com", "gov");
|
||||
|
@ -63,7 +63,7 @@ public class StringListConverterTest {
|
|||
@Test
|
||||
void testNullValue_writesAndReadsNullSuccessfully() {
|
||||
TestEntity testEntity = new TestEntity(null);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.tlds).isNull();
|
||||
|
@ -72,7 +72,7 @@ public class StringListConverterTest {
|
|||
@Test
|
||||
void testEmptyCollection_writesAndReadsEmptyCollectionSuccessfully() {
|
||||
TestEntity testEntity = new TestEntity(ImmutableList.of());
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.tlds).isEmpty();
|
||||
|
|
|
@ -50,7 +50,7 @@ public class StringMapConverterBaseTest {
|
|||
@Test
|
||||
void roundTripConversion_returnsSameMap() {
|
||||
TestEntity testEntity = new TestEntity(MAP);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.map).containsExactlyEntriesIn(MAP);
|
||||
|
@ -59,7 +59,7 @@ public class StringMapConverterBaseTest {
|
|||
@Test
|
||||
void testUpdateColumn_succeeds() {
|
||||
TestEntity testEntity = new TestEntity(MAP);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.map).containsExactlyEntriesIn(MAP);
|
||||
|
@ -73,7 +73,7 @@ public class StringMapConverterBaseTest {
|
|||
@Test
|
||||
void testNullValue_writesAndReadsNullSuccessfully() {
|
||||
TestEntity testEntity = new TestEntity(null);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.map).isNull();
|
||||
|
@ -82,7 +82,7 @@ public class StringMapConverterBaseTest {
|
|||
@Test
|
||||
void testEmptyMap_writesAndReadsEmptyCollectionSuccessfully() {
|
||||
TestEntity testEntity = new TestEntity(ImmutableMap.of());
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.map).isEmpty();
|
||||
|
|
|
@ -38,7 +38,7 @@ public class StringSetConverterTest {
|
|||
void roundTripConversion_returnsSameStringList() {
|
||||
Set<String> tlds = ImmutableSet.of("app", "dev", "how");
|
||||
TestEntity testEntity = new TestEntity(tlds);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.tlds).containsExactly("app", "dev", "how");
|
||||
|
@ -47,7 +47,7 @@ public class StringSetConverterTest {
|
|||
@Test
|
||||
void testNullValue_writesAndReadsNullSuccessfully() {
|
||||
TestEntity testEntity = new TestEntity(null);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.tlds).isNull();
|
||||
|
@ -56,7 +56,7 @@ public class StringSetConverterTest {
|
|||
@Test
|
||||
void testEmptyCollection_writesAndReadsEmptyCollectionSuccessfully() {
|
||||
TestEntity testEntity = new TestEntity(ImmutableSet.of());
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.tlds).isEmpty();
|
||||
|
|
|
@ -47,7 +47,7 @@ public class StringVKeyConverterTest {
|
|||
"TheRealSpartacus",
|
||||
VKey.createSql(TestStringEntity.class, "ImSpartacus!"),
|
||||
VKey.createSql(CompositeKeyTestStringEntity.class, "NoImSpartacus!"));
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(original));
|
||||
jpaTm().transact(() -> jpaTm().insert(original));
|
||||
|
||||
TestStringEntity retrieved =
|
||||
jpaTm()
|
||||
|
|
|
@ -38,7 +38,7 @@ public class StringValueEnumeratedTest {
|
|||
@Test
|
||||
void roundTripConversion_returnsSameEnum() {
|
||||
TestEntity testEntity = new TestEntity(State.ACTIVE);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.state).isEqualTo(State.ACTIVE);
|
||||
|
@ -47,7 +47,7 @@ public class StringValueEnumeratedTest {
|
|||
@Test
|
||||
void testNativeQuery_succeeds() {
|
||||
TestEntity testEntity = new TestEntity(State.DISABLED);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
|
||||
assertThat(
|
||||
jpaTm()
|
||||
|
|
|
@ -60,7 +60,7 @@ class TimedTransitionPropertyConverterBaseTest {
|
|||
@Test
|
||||
void roundTripConversion_returnsSameTimedTransitionProperty() {
|
||||
TestEntity testEntity = new TestEntity(TIMED_TRANSITION_PROPERTY);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.property).containsExactlyEntriesIn(TIMED_TRANSITION_PROPERTY);
|
||||
|
@ -69,7 +69,7 @@ class TimedTransitionPropertyConverterBaseTest {
|
|||
@Test
|
||||
void testUpdateColumn_succeeds() {
|
||||
TestEntity testEntity = new TestEntity(TIMED_TRANSITION_PROPERTY);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.property).containsExactlyEntriesIn(TIMED_TRANSITION_PROPERTY);
|
||||
|
@ -84,7 +84,7 @@ class TimedTransitionPropertyConverterBaseTest {
|
|||
@Test
|
||||
void testNullValue_writesAndReadsNullSuccessfully() {
|
||||
TestEntity testEntity = new TestEntity(null);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.property).isNull();
|
||||
|
|
|
@ -57,7 +57,7 @@ class TldStateTransitionConverterTest {
|
|||
TimedTransitionProperty<TldState, TldStateTransition> timedTransitionProperty =
|
||||
TimedTransitionProperty.fromValueMap(values, TldStateTransition.class);
|
||||
TestEntity testEntity = new TestEntity(timedTransitionProperty);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity));
|
||||
jpaTm().transact(() -> jpaTm().insert(testEntity));
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "id"));
|
||||
assertThat(persisted.timedTransitionProperty).containsExactlyEntriesIn(timedTransitionProperty);
|
||||
|
|
|
@ -43,7 +43,7 @@ public class UpdateAutoTimestampConverterTest {
|
|||
void testTypeConversion() {
|
||||
TestEntity ent = new TestEntity("myinst", null);
|
||||
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(ent));
|
||||
jpaTm().transact(() -> jpaTm().insert(ent));
|
||||
|
||||
TestEntity result =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "myinst"));
|
||||
|
@ -56,7 +56,7 @@ public class UpdateAutoTimestampConverterTest {
|
|||
void testTimeChangesOnSubsequentTransactions() {
|
||||
TestEntity ent1 = new TestEntity("myinst1", null);
|
||||
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(ent1));
|
||||
jpaTm().transact(() -> jpaTm().insert(ent1));
|
||||
|
||||
TestEntity result1 =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "myinst1"));
|
||||
|
@ -65,7 +65,7 @@ public class UpdateAutoTimestampConverterTest {
|
|||
|
||||
TestEntity ent2 = new TestEntity("myinst2", result1.uat);
|
||||
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(ent2));
|
||||
jpaTm().transact(() -> jpaTm().insert(ent2));
|
||||
|
||||
TestEntity result2 =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "myinst2"));
|
||||
|
|
|
@ -66,7 +66,7 @@ public class ZonedDateTimeConverterTest {
|
|||
void converter_generatesTimestampWithNormalizedZone() {
|
||||
ZonedDateTime zdt = ZonedDateTime.parse("2019-09-01T01:01:01Z");
|
||||
TestEntity entity = new TestEntity("normalized_utc_time", zdt);
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(entity));
|
||||
jpaTm().transact(() -> jpaTm().insert(entity));
|
||||
TestEntity retrievedEntity =
|
||||
jpaTm()
|
||||
.transact(
|
||||
|
@ -79,7 +79,7 @@ public class ZonedDateTimeConverterTest {
|
|||
ZonedDateTime zdt = ZonedDateTime.parse("2019-09-01T01:01:01Z[UTC]");
|
||||
TestEntity entity = new TestEntity("non_normalized_utc_time", zdt);
|
||||
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(entity));
|
||||
jpaTm().transact(() -> jpaTm().insert(entity));
|
||||
TestEntity retrievedEntity =
|
||||
jpaTm()
|
||||
.transact(
|
||||
|
@ -92,7 +92,7 @@ public class ZonedDateTimeConverterTest {
|
|||
ZonedDateTime zdt = ZonedDateTime.parse("2019-09-01T01:01:01+05:00");
|
||||
TestEntity entity = new TestEntity("new_york_time", zdt);
|
||||
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(entity));
|
||||
jpaTm().transact(() -> jpaTm().insert(entity));
|
||||
TestEntity retrievedEntity =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "new_york_time"));
|
||||
assertThat(retrievedEntity.zdt.toString()).isEqualTo("2019-08-31T20:01:01Z");
|
||||
|
|
|
@ -106,8 +106,7 @@ public class JpaEntityCoverageExtension implements BeforeEachCallback, AfterEach
|
|||
.transact(
|
||||
() ->
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery(
|
||||
.query(
|
||||
String.format("SELECT e FROM %s e", getJpaEntityName(entityType)),
|
||||
entityType)
|
||||
.setMaxResults(1)
|
||||
|
|
|
@ -66,7 +66,7 @@ public class JpaTransactionManagerRuleTest {
|
|||
// This test verifies that 1) withEntityClass() has registered TestEntity and 2) The table
|
||||
// has been created, implying withProperty(HBM2DDL_AUTO, "update") worked.
|
||||
TestEntity original = new TestEntity("key", "value");
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().persist(original));
|
||||
jpaTm().transact(() -> jpaTm().insert(original));
|
||||
TestEntity retrieved =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "key"));
|
||||
assertThat(retrieved).isEqualTo(original);
|
||||
|
|
|
@ -70,7 +70,8 @@ class IcannReportingStagerTest {
|
|||
}
|
||||
|
||||
private void setUpBigquery() {
|
||||
when(bigquery.query(any(String.class), any(DestinationTable.class))).thenReturn(fakeFuture());
|
||||
when(bigquery.startQuery(any(String.class), any(DestinationTable.class)))
|
||||
.thenReturn(fakeFuture());
|
||||
DestinationTable.Builder tableBuilder =
|
||||
new DestinationTable.Builder()
|
||||
.datasetId("testdataset")
|
||||
|
|
|
@ -53,8 +53,7 @@ public class SqlReplayCheckpointTest extends EntityTestCase {
|
|||
() ->
|
||||
assertThat(
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery("SELECT COUNT(*) FROM SqlReplayCheckpoint", Long.class)
|
||||
.query("SELECT COUNT(*) FROM SqlReplayCheckpoint", Long.class)
|
||||
.getSingleResult())
|
||||
.isEqualTo(1L));
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ import google.registry.model.registry.label.ReservedList.ReservedListEntry;
|
|||
import google.registry.model.registry.label.ReservedListSqlDao;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import javax.persistence.EntityManager;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -118,14 +117,15 @@ abstract class CreateOrUpdateReservedListCommandTestCase<
|
|||
return jpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
EntityManager em = jpaTm().getEntityManager();
|
||||
long revisionId =
|
||||
em.createQuery(
|
||||
jpaTm()
|
||||
.query(
|
||||
"SELECT MAX(rl.revisionId) FROM ReservedList rl WHERE name = :name",
|
||||
Long.class)
|
||||
.setParameter("name", name)
|
||||
.getSingleResult();
|
||||
return em.createQuery(
|
||||
return jpaTm()
|
||||
.query(
|
||||
"FROM ReservedList rl LEFT JOIN FETCH rl.reservedListMap WHERE"
|
||||
+ " rl.revisionId = :revisionId",
|
||||
ReservedList.class)
|
||||
|
|
Loading…
Add table
Reference in a new issue