mirror of
https://github.com/google/nomulus
synced 2026-09-18 22:14:23 +00:00
Create DAO for Spec11ThreatMatch (#750)
* Create DAO for Spec11ThreatMatch * Add tests * Execute SQL for deleteEntriesByDategit status * Remove testing line * Rename createSpec11ThreatMatch() * Add comments about jpaTm and use jpaTm() in test * Fix technicality in comment * Remove a new line * Truth chaining for comparing ImmutableLists of matches * Javadoc formatting
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
// Copyright 2020 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.model.reporting;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import google.registry.persistence.transaction.JpaTransactionManager;
|
||||
import org.joda.time.LocalDate;
|
||||
|
||||
/**
|
||||
* Data access object for {@link google.registry.model.reporting.Spec11ThreatMatch}.
|
||||
*
|
||||
* <p>A JpaTransactionManager is passed into each static method because they are called from a BEAM
|
||||
* pipeline and we don't know where it's coming from.</p>
|
||||
*/
|
||||
public class Spec11ThreatMatchDao {
|
||||
|
||||
/** Delete all entries with the specified date from the database. */
|
||||
public static void deleteEntriesByDate(JpaTransactionManager jpaTm, LocalDate date) {
|
||||
jpaTm.assertInTransaction();
|
||||
jpaTm
|
||||
.getEntityManager()
|
||||
.createQuery("DELETE FROM Spec11ThreatMatch WHERE check_date = :date")
|
||||
.setParameter("date", date.toString())
|
||||
.executeUpdate();
|
||||
}
|
||||
|
||||
/** Query the database and return a list of domain names with the specified date. */
|
||||
public static ImmutableList<Spec11ThreatMatch> loadEntriesByDate(
|
||||
JpaTransactionManager jpaTm, LocalDate date) {
|
||||
jpaTm.assertInTransaction();
|
||||
return ImmutableList.copyOf(
|
||||
jpaTm
|
||||
.getEntityManager()
|
||||
.createQuery(
|
||||
"SELECT match FROM Spec11ThreatMatch match WHERE match.checkDate = :date",
|
||||
Spec11ThreatMatch.class)
|
||||
.setParameter("date", date)
|
||||
.getResultList());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user