Skip to content
This repository has been archived by the owner on Sep 10, 2019. It is now read-only.

Commit

Permalink
Handiling the null pointer exception in property row mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
prasadkhandagale committed Jun 29, 2017
1 parent 6a731d8 commit 986dd88
Showing 1 changed file with 38 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,61 @@

import java.sql.ResultSet;
import java.sql.SQLException;

import org.egov.models.Boundary;
import org.egov.models.PropertyLocation;
import org.springframework.jdbc.core.RowMapper;

/**
* This class will create property location object from the given result set
*
* @author prasad
*
*/
public class PropertyLocationRowMapper implements RowMapper<Object> {

@Override
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {

PropertyLocation propertyLocation = new PropertyLocation();


propertyLocation.setId(Long.valueOf(rs.getInt("id")));

propertyLocation.setId(getLong(rs.getInt("id")));
Boundary boundary = new Boundary();
boundary.setId(Long.valueOf(rs.getInt("revenueboundary")));
boundary.setId(getLong(rs.getInt("revenueboundary")));
propertyLocation.setRevenueBoundary(boundary);
boundary = new Boundary();
boundary.setId(Long.valueOf(rs.getInt("locationboundary")));
boundary.setId(getLong(rs.getInt("locationboundary")));
propertyLocation.setLocationBoundary(boundary);
boundary = new Boundary();
boundary.setId(Long.valueOf(rs.getInt("adminboundary")));
boundary.setId(getLong(rs.getInt("adminboundary")));
propertyLocation.setAdminBoundary(boundary);
propertyLocation.setNorthBoundedBy(rs.getString("northboundedby"));
propertyLocation.setEastBoundedBy(rs.getString("eastboundedby"));
propertyLocation.setWestBoundedBy(rs.getString("westboundedby"));
propertyLocation.setNorthBoundedBy(getString(rs.getString("northboundedby")));
propertyLocation.setEastBoundedBy(getString(rs.getString("eastboundedby")));
propertyLocation.setWestBoundedBy(getString(rs.getString("westboundedby")));
propertyLocation.setSouthBoundedBy("southboundedby");

return propertyLocation;
}

/**
* This method will cast the given object to String
*
* @param object
* that need to be cast to string
* @return {@link String}
*/
private String getString(Object object) {
return object == null ? "" : object.toString().trim();
}

/**
* This method will cast the given object to Long
*
* @param object
* that need to be cast to Long
* @return {@link Long}
*/
private Long getLong(Object object) {
return object == null ? 0l : Long.parseLong(object.toString().trim());
}

}

0 comments on commit 986dd88

Please sign in to comment.