Use try with resources for dao layer

licensing-improvements
Pasindu Rupasinghe 3 months ago
parent 6d324c084a
commit 87b98a6cb5

@ -130,11 +130,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
public int updateOperationByDeviceTypeAndInitialStatus(String deiceType, String initialStatus, String requiredStatus)
throws OperationManagementDAOException {
PreparedStatement stmt = null;
int numOfRecordsUpdated;
try {
long time = DeviceManagementDAOUtil.getCurrentUTCTime();
Connection connection = OperationManagementDAOFactory.getConnection();
String sql = "UPDATE DM_ENROLMENT_OP_MAPPING SET STATUS=?, UPDATED_TIMESTAMP=? WHERE DEVICE_TYPE=?";
@ -144,7 +141,10 @@ public class GenericOperationDAOImpl implements OperationDAO {
sql += " AND STATUS=?";
}
stmt = connection.prepareStatement(sql);
try (
Connection connection = OperationManagementDAOFactory.getConnection();
PreparedStatement stmt = connection.prepareStatement(sql)
) {
stmt.setString(1, requiredStatus);
stmt.setLong(2, time);
stmt.setString(3, deiceType);
@ -156,8 +156,6 @@ public class GenericOperationDAOImpl implements OperationDAO {
} catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while update device mapping operation status " +
e.getMessage(), e);
} finally {
OperationManagementDAOUtil.cleanupResources(stmt);
}
return numOfRecordsUpdated;
}

Loading…
Cancel
Save