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