...
iii) Next, create a class by the name of BirthApplicationRowMapper
under rowmapper folder and annotate it with @Component
. Add the following content in the class -
Code Block | ||
---|---|---|
| ||
@Component public class BirthApplicationRowMapper implements ResultSetExtractor<List<BirthRegistrationApplication>> { public List<BirthRegistrationApplication> extractData(ResultSet rs) throws SQLException, DataAccessException { Map<String,BirthRegistrationApplication> birthRegistrationApplicationMap = new LinkedHashMap<>(); while (rs.next()){ String uuid = rs.getString("bapplicationnumber"); BirthRegistrationApplication birthRegistrationApplication = birthRegistrationApplicationMap.get(uuid); if(birthRegistrationApplication == null) { Long lastModifiedTime = rs.getLong("blastModifiedTime"); if (rs.wasNull()) { lastModifiedTime = null; } Applicant applicant = Applicant.builder().id(rs.getString("bapplicantid")).build(); AuditDetails auditdetails = AuditDetails.builder() .createdBy(rs.getString("bcreatedBy")) .createdTime(rs.getLong("bcreatedTime")) .lastModifiedBy(rs.getString("blastModifiedBy")) .lastModifiedTime(lastModifiedTime) .build(); birthRegistrationApplication = BirthRegistrationApplication.builder() .applicationNumber(rs.getString("bapplicationnumber")) .tenantId(rs.getString("btenantid")) .id(rs.getString("bid")) .assemblyConstituency(rs.getString("bassemblyconstituency")) .dateSinceResidence(rs.getInt("bdatesinceresidence")) .applicant(applicant) .auditDetails(auditdetails) .build(); } addChildrenToProperty(rs, birthRegistrationApplication); birthRegistrationApplicationMap.put(uuid, birthRegistrationApplication); } return new ArrayList<>(birthRegistrationApplicationMap.values()); } private void addChildrenToProperty(ResultSet rs, BirthRegistrationApplication birthRegistrationApplication) throws SQLException { addAddressToApplication(rs, birthRegistrationApplication); } private void addAddressToApplication(ResultSet rs, BirthRegistrationApplication birthRegistrationApplication) throws SQLException { Address address = Address.builder() .id(rs.getString("aid")) .tenantId(rs.getString("atenantid")) .doorNo(rs.getString("adoorno")) .latitude(rs.getDouble("alatitude")) .longitude(rs.getDouble("alongitude")) .buildingName(rs.getString("abuildingname")) .addressId(rs.getString("aaddressid")) .addressNumber(rs.getString("aaddressnumber")) .type(rs.getString("atype")) .addressLine1(rs.getString("aaddressline1")) .addressLine2(rs.getString("aaddressline2")) .landmark(rs.getString("alandmark")) .street(rs.getString("astreet")) .city(rs.getString("acity")) .pincode(rs.getString("apincode")) .detail("adetail") .registrationId("aregistrationid") .build(); birthRegistrationApplication.setAddress(address); } } |
...