@Test @Sql(scripts = { "/sql/clearAddresses.sql","/sql/clearUserRoles.sql","/sql/clearUsers.sql","/sql/createUsers.sql","/sql/createAddresses.sql"}) public void test_should_delete_all_associated_addresses() { final List<Address> domainAddresses = Collections.emptyList(); addressRepository.update(domainAddresses, 1L, "ap.public"); }
public void update(List<Address> domainAddresses, Long userId, String tenantId) { final Map<String, Object> Map = new HashMap<String, Object>(); Map.put("userId", userId); Map.put("tenantId", tenantId); List<Address> entityAddresses = namedParameterJdbcTemplate.query(GET_ADDRESS_BY_USERID, Map, new AddressRowMapper()); if (isEmpty(domainAddresses) && isEmpty(entityAddresses)) { return; } conditionallyDeleteAllAddresses(domainAddresses, entityAddresses); deleteRemovedAddresses(domainAddresses, entityAddresses); createNewAddresses(domainAddresses, entityAddresses, userId, tenantId); updateAddresses(domainAddresses, entityAddresses, userId); }
AddressRepository { public void update(List<Address> domainAddresses, Long userId, String tenantId) { final Map<String, Object> Map = new HashMap<String, Object>(); Map.put("userId", userId); Map.put("tenantId", tenantId); List<Address> entityAddresses = namedParameterJdbcTemplate.query(GET_ADDRESS_BY_USERID, Map, new AddressRowMapper()); if (isEmpty(domainAddresses) && isEmpty(entityAddresses)) { return; } conditionallyDeleteAllAddresses(domainAddresses, entityAddresses); deleteRemovedAddresses(domainAddresses, entityAddresses); createNewAddresses(domainAddresses, entityAddresses, userId, tenantId); updateAddresses(domainAddresses, entityAddresses, userId); } }
AddressRepository { public void update(List<Address> domainAddresses, Long userId, String tenantId) { final Map<String, Object> Map = new HashMap<String, Object>(); Map.put("userId", userId); Map.put("tenantId", tenantId); List<Address> entityAddresses = namedParameterJdbcTemplate.query(GET_ADDRESS_BY_USERID, Map, new AddressRowMapper()); if (isEmpty(domainAddresses) && isEmpty(entityAddresses)) { return; } conditionallyDeleteAllAddresses(domainAddresses, entityAddresses); deleteRemovedAddresses(domainAddresses, entityAddresses); createNewAddresses(domainAddresses, entityAddresses, userId, tenantId); updateAddresses(domainAddresses, entityAddresses, userId); } AddressRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate, JdbcTemplate jdbcTemplate); }
AddressRepository { public void update(List<Address> domainAddresses, Long userId, String tenantId) { final Map<String, Object> Map = new HashMap<String, Object>(); Map.put("userId", userId); Map.put("tenantId", tenantId); List<Address> entityAddresses = namedParameterJdbcTemplate.query(GET_ADDRESS_BY_USERID, Map, new AddressRowMapper()); if (isEmpty(domainAddresses) && isEmpty(entityAddresses)) { return; } conditionallyDeleteAllAddresses(domainAddresses, entityAddresses); deleteRemovedAddresses(domainAddresses, entityAddresses); createNewAddresses(domainAddresses, entityAddresses, userId, tenantId); updateAddresses(domainAddresses, entityAddresses, userId); } AddressRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate, JdbcTemplate jdbcTemplate); Address create(Address address, Long userId, String tenantId); void update(List<Address> domainAddresses, Long userId, String tenantId); List<Address> find(Long userId, String tenantId); }
AddressRepository { public void update(List<Address> domainAddresses, Long userId, String tenantId) { final Map<String, Object> Map = new HashMap<String, Object>(); Map.put("userId", userId); Map.put("tenantId", tenantId); List<Address> entityAddresses = namedParameterJdbcTemplate.query(GET_ADDRESS_BY_USERID, Map, new AddressRowMapper()); if (isEmpty(domainAddresses) && isEmpty(entityAddresses)) { return; } conditionallyDeleteAllAddresses(domainAddresses, entityAddresses); deleteRemovedAddresses(domainAddresses, entityAddresses); createNewAddresses(domainAddresses, entityAddresses, userId, tenantId); updateAddresses(domainAddresses, entityAddresses, userId); } AddressRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate, JdbcTemplate jdbcTemplate); Address create(Address address, Long userId, String tenantId); void update(List<Address> domainAddresses, Long userId, String tenantId); List<Address> find(Long userId, String tenantId); static final String GET_ADDRESS_BY_USERID; static final String INSERT_ADDRESS_BYUSERID; static final String SELECT_NEXT_SEQUENCE; static final String DELETE_ADDRESSES; static final String DELETE_ADDRESS; static final String UPDATE_ADDRESS_BYIDAND_TENANTID; }