@Test public void storeAndLoadUrlShouldStoreCorrectUrl() throws Exception { Optional<String> loadedUrl = urlShorterDao.loadUrlById(postfix); Assert.assertTrue(loadedUrl.isPresent()); Assert.assertEquals(loadedUrl.get(), url); }
@Transactional(propagation = Propagation.SUPPORTS) public Optional<String> loadUrlById(String id) { final MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(Parameters.ID.name(), id); List<String> query = getNamedParameterJdbcTemplate().query( loadUrlByIdQuery, params, (rs, rowNum) -> rs.getString(Parameters.URL.name()) ); return query.isEmpty() ? Optional.empty() : Optional.of(query.get(0)); }
UrlShorterDao extends NamedParameterJdbcDaoSupport { @Transactional(propagation = Propagation.SUPPORTS) public Optional<String> loadUrlById(String id) { final MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(Parameters.ID.name(), id); List<String> query = getNamedParameterJdbcTemplate().query( loadUrlByIdQuery, params, (rs, rowNum) -> rs.getString(Parameters.URL.name()) ); return query.isEmpty() ? Optional.empty() : Optional.of(query.get(0)); } }
UrlShorterDao extends NamedParameterJdbcDaoSupport { @Transactional(propagation = Propagation.SUPPORTS) public Optional<String> loadUrlById(String id) { final MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(Parameters.ID.name(), id); List<String> query = getNamedParameterJdbcTemplate().query( loadUrlByIdQuery, params, (rs, rowNum) -> rs.getString(Parameters.URL.name()) ); return query.isEmpty() ? Optional.empty() : Optional.of(query.get(0)); }  }
UrlShorterDao extends NamedParameterJdbcDaoSupport { @Transactional(propagation = Propagation.SUPPORTS) public Optional<String> loadUrlById(String id) { final MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(Parameters.ID.name(), id); List<String> query = getNamedParameterJdbcTemplate().query( loadUrlByIdQuery, params, (rs, rowNum) -> rs.getString(Parameters.URL.name()) ); return query.isEmpty() ? Optional.empty() : Optional.of(query.get(0)); }  @Transactional(propagation = Propagation.MANDATORY) void storeUrl(String id, String url); @Transactional(propagation = Propagation.SUPPORTS) Optional<String> loadUrlById(String id); @Transactional(propagation = Propagation.MANDATORY) void deleteExpiredUrls(Date expiredDate); @Required void setLoadUrlByIdQuery(String loadUrlByIdQuery); @Required void setInsertUrlQuery(String insertUrlQuery); @Required void setDeleteExpiredUrlsQuery(String deleteExpiredUrlsQuery); }
UrlShorterDao extends NamedParameterJdbcDaoSupport { @Transactional(propagation = Propagation.SUPPORTS) public Optional<String> loadUrlById(String id) { final MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(Parameters.ID.name(), id); List<String> query = getNamedParameterJdbcTemplate().query( loadUrlByIdQuery, params, (rs, rowNum) -> rs.getString(Parameters.URL.name()) ); return query.isEmpty() ? Optional.empty() : Optional.of(query.get(0)); }  @Transactional(propagation = Propagation.MANDATORY) void storeUrl(String id, String url); @Transactional(propagation = Propagation.SUPPORTS) Optional<String> loadUrlById(String id); @Transactional(propagation = Propagation.MANDATORY) void deleteExpiredUrls(Date expiredDate); @Required void setLoadUrlByIdQuery(String loadUrlByIdQuery); @Required void setInsertUrlQuery(String insertUrlQuery); @Required void setDeleteExpiredUrlsQuery(String deleteExpiredUrlsQuery);  }