@Test public void testGetByUrlNoMatchUrl() { Document doc = dao.getByUrl("http: assertThat(doc).isNull(); }
@SuppressWarnings("unchecked") public List<Document> getByUrl(@NotNull String url, Optional<LocaleCode> fromLocaleCode, Optional<LocaleCode> toLocaleCode, Optional<DateRange> dateParam) { String urlHash = HashUtil.generateHash(url); StringBuilder queryBuilder = new StringBuilder(); queryBuilder.append("from Document where urlHash =:urlHash"); if (fromLocaleCode.isPresent()) { queryBuilder.append(" and fromLocale.localeCode =:fromLocaleCode"); } if (toLocaleCode.isPresent()) { queryBuilder.append(" and toLocale.localeCode =:toLocaleCode"); } if (dateParam.isPresent()) { queryBuilder.append(" and lastChanged between :fromDate and :toDate"); } Query query = getEntityManager().createQuery(queryBuilder.toString()) .setParameter("urlHash", urlHash); fromLocaleCode.ifPresent( localeCode -> query.setParameter("fromLocaleCode", localeCode)); toLocaleCode.ifPresent( localeCode -> query.setParameter("toLocaleCode", localeCode)); if (dateParam.isPresent()) { query.setParameter("fromDate", dateParam.get().getFromDate()); query.setParameter("toDate", dateParam.get().getToDate()); } List<Document> documents = query.getResultList(); return documents; }
DocumentDAO extends AbstractDAO<Document> { @SuppressWarnings("unchecked") public List<Document> getByUrl(@NotNull String url, Optional<LocaleCode> fromLocaleCode, Optional<LocaleCode> toLocaleCode, Optional<DateRange> dateParam) { String urlHash = HashUtil.generateHash(url); StringBuilder queryBuilder = new StringBuilder(); queryBuilder.append("from Document where urlHash =:urlHash"); if (fromLocaleCode.isPresent()) { queryBuilder.append(" and fromLocale.localeCode =:fromLocaleCode"); } if (toLocaleCode.isPresent()) { queryBuilder.append(" and toLocale.localeCode =:toLocaleCode"); } if (dateParam.isPresent()) { queryBuilder.append(" and lastChanged between :fromDate and :toDate"); } Query query = getEntityManager().createQuery(queryBuilder.toString()) .setParameter("urlHash", urlHash); fromLocaleCode.ifPresent( localeCode -> query.setParameter("fromLocaleCode", localeCode)); toLocaleCode.ifPresent( localeCode -> query.setParameter("toLocaleCode", localeCode)); if (dateParam.isPresent()) { query.setParameter("fromDate", dateParam.get().getFromDate()); query.setParameter("toDate", dateParam.get().getToDate()); } List<Document> documents = query.getResultList(); return documents; } }
DocumentDAO extends AbstractDAO<Document> { @SuppressWarnings("unchecked") public List<Document> getByUrl(@NotNull String url, Optional<LocaleCode> fromLocaleCode, Optional<LocaleCode> toLocaleCode, Optional<DateRange> dateParam) { String urlHash = HashUtil.generateHash(url); StringBuilder queryBuilder = new StringBuilder(); queryBuilder.append("from Document where urlHash =:urlHash"); if (fromLocaleCode.isPresent()) { queryBuilder.append(" and fromLocale.localeCode =:fromLocaleCode"); } if (toLocaleCode.isPresent()) { queryBuilder.append(" and toLocale.localeCode =:toLocaleCode"); } if (dateParam.isPresent()) { queryBuilder.append(" and lastChanged between :fromDate and :toDate"); } Query query = getEntityManager().createQuery(queryBuilder.toString()) .setParameter("urlHash", urlHash); fromLocaleCode.ifPresent( localeCode -> query.setParameter("fromLocaleCode", localeCode)); toLocaleCode.ifPresent( localeCode -> query.setParameter("toLocaleCode", localeCode)); if (dateParam.isPresent()) { query.setParameter("fromDate", dateParam.get().getFromDate()); query.setParameter("toDate", dateParam.get().getToDate()); } List<Document> documents = query.getResultList(); return documents; } @SuppressWarnings("unused")  DocumentDAO(); @VisibleForTesting  DocumentDAO(EntityManager entityManager); }
DocumentDAO extends AbstractDAO<Document> { @SuppressWarnings("unchecked") public List<Document> getByUrl(@NotNull String url, Optional<LocaleCode> fromLocaleCode, Optional<LocaleCode> toLocaleCode, Optional<DateRange> dateParam) { String urlHash = HashUtil.generateHash(url); StringBuilder queryBuilder = new StringBuilder(); queryBuilder.append("from Document where urlHash =:urlHash"); if (fromLocaleCode.isPresent()) { queryBuilder.append(" and fromLocale.localeCode =:fromLocaleCode"); } if (toLocaleCode.isPresent()) { queryBuilder.append(" and toLocale.localeCode =:toLocaleCode"); } if (dateParam.isPresent()) { queryBuilder.append(" and lastChanged between :fromDate and :toDate"); } Query query = getEntityManager().createQuery(queryBuilder.toString()) .setParameter("urlHash", urlHash); fromLocaleCode.ifPresent( localeCode -> query.setParameter("fromLocaleCode", localeCode)); toLocaleCode.ifPresent( localeCode -> query.setParameter("toLocaleCode", localeCode)); if (dateParam.isPresent()) { query.setParameter("fromDate", dateParam.get().getFromDate()); query.setParameter("toDate", dateParam.get().getToDate()); } List<Document> documents = query.getResultList(); return documents; } @SuppressWarnings("unused")  DocumentDAO(); @VisibleForTesting  DocumentDAO(EntityManager entityManager); Document reload(Document entity); @SuppressWarnings("unchecked") List<Document> getByUrl(@NotNull String url,
            Optional<LocaleCode> fromLocaleCode, Optional<LocaleCode> toLocaleCode,
            Optional<DateRange> dateParam); Document getByUrl(@NotNull String url, @NotNull Locale fromLocale,
            @NotNull Locale toLocale); @SuppressWarnings("unchecked") List<String> getUrlList(Optional<DateRange> dateParam); }
DocumentDAO extends AbstractDAO<Document> { @SuppressWarnings("unchecked") public List<Document> getByUrl(@NotNull String url, Optional<LocaleCode> fromLocaleCode, Optional<LocaleCode> toLocaleCode, Optional<DateRange> dateParam) { String urlHash = HashUtil.generateHash(url); StringBuilder queryBuilder = new StringBuilder(); queryBuilder.append("from Document where urlHash =:urlHash"); if (fromLocaleCode.isPresent()) { queryBuilder.append(" and fromLocale.localeCode =:fromLocaleCode"); } if (toLocaleCode.isPresent()) { queryBuilder.append(" and toLocale.localeCode =:toLocaleCode"); } if (dateParam.isPresent()) { queryBuilder.append(" and lastChanged between :fromDate and :toDate"); } Query query = getEntityManager().createQuery(queryBuilder.toString()) .setParameter("urlHash", urlHash); fromLocaleCode.ifPresent( localeCode -> query.setParameter("fromLocaleCode", localeCode)); toLocaleCode.ifPresent( localeCode -> query.setParameter("toLocaleCode", localeCode)); if (dateParam.isPresent()) { query.setParameter("fromDate", dateParam.get().getFromDate()); query.setParameter("toDate", dateParam.get().getToDate()); } List<Document> documents = query.getResultList(); return documents; } @SuppressWarnings("unused")  DocumentDAO(); @VisibleForTesting  DocumentDAO(EntityManager entityManager); Document reload(Document entity); @SuppressWarnings("unchecked") List<Document> getByUrl(@NotNull String url,
            Optional<LocaleCode> fromLocaleCode, Optional<LocaleCode> toLocaleCode,
            Optional<DateRange> dateParam); Document getByUrl(@NotNull String url, @NotNull Locale fromLocale,
            @NotNull Locale toLocale); @SuppressWarnings("unchecked") List<String> getUrlList(Optional<DateRange> dateParam);  }