@Test public void test_should_persist_update_usageType_to_DB() { final UsageTypeReq usageTypeReq = usageTypeRepository.update(getUsageTypeRequestForUpdate()); assertThat(usageTypeReq.getUsageTypes().size()).isEqualTo(2); }
@SuppressWarnings("unchecked") public UsageTypeReq update(final UsageTypeReq usageTypeRequest) { final List<UsageType> usageTypes = usageTypeRequest.getUsageTypes(); final String usageTypeUpdateQuery = usageTypeQueryBuilder.getUpdateUsageTypeQuery(); final List<Map<String, Object>> usageTypeQueryParams = new ArrayList<>(); for (final UsageType usageType : usageTypes) usageTypeQueryParams.add(new MapSqlParameterSource("name", usageType.getName()) .addValue("description", usageType.getDescription()).addValue("parent", usageType.getParent()) .addValue("active", usageType.getActive()) .addValue("lastmodifiedby", usageTypeRequest.getRequestInfo().getUserInfo().getId()) .addValue("lastmodifieddate", new Date().getTime()).addValue("code", usageType.getCode()) .addValue("tenantid", usageType.getTenantId()).getValues()); try { namedParameterJdbcTemplate.batchUpdate(usageTypeUpdateQuery, usageTypeQueryParams.toArray(new Map[usageTypes.size()])); } catch (final Exception e) { logger.error("Error occured while updating usageType in db" + e); } return usageTypeRequest; }
UsageTypeRepository { @SuppressWarnings("unchecked") public UsageTypeReq update(final UsageTypeReq usageTypeRequest) { final List<UsageType> usageTypes = usageTypeRequest.getUsageTypes(); final String usageTypeUpdateQuery = usageTypeQueryBuilder.getUpdateUsageTypeQuery(); final List<Map<String, Object>> usageTypeQueryParams = new ArrayList<>(); for (final UsageType usageType : usageTypes) usageTypeQueryParams.add(new MapSqlParameterSource("name", usageType.getName()) .addValue("description", usageType.getDescription()).addValue("parent", usageType.getParent()) .addValue("active", usageType.getActive()) .addValue("lastmodifiedby", usageTypeRequest.getRequestInfo().getUserInfo().getId()) .addValue("lastmodifieddate", new Date().getTime()).addValue("code", usageType.getCode()) .addValue("tenantid", usageType.getTenantId()).getValues()); try { namedParameterJdbcTemplate.batchUpdate(usageTypeUpdateQuery, usageTypeQueryParams.toArray(new Map[usageTypes.size()])); } catch (final Exception e) { logger.error("Error occured while updating usageType in db" + e); } return usageTypeRequest; } }
UsageTypeRepository { @SuppressWarnings("unchecked") public UsageTypeReq update(final UsageTypeReq usageTypeRequest) { final List<UsageType> usageTypes = usageTypeRequest.getUsageTypes(); final String usageTypeUpdateQuery = usageTypeQueryBuilder.getUpdateUsageTypeQuery(); final List<Map<String, Object>> usageTypeQueryParams = new ArrayList<>(); for (final UsageType usageType : usageTypes) usageTypeQueryParams.add(new MapSqlParameterSource("name", usageType.getName()) .addValue("description", usageType.getDescription()).addValue("parent", usageType.getParent()) .addValue("active", usageType.getActive()) .addValue("lastmodifiedby", usageTypeRequest.getRequestInfo().getUserInfo().getId()) .addValue("lastmodifieddate", new Date().getTime()).addValue("code", usageType.getCode()) .addValue("tenantid", usageType.getTenantId()).getValues()); try { namedParameterJdbcTemplate.batchUpdate(usageTypeUpdateQuery, usageTypeQueryParams.toArray(new Map[usageTypes.size()])); } catch (final Exception e) { logger.error("Error occured while updating usageType in db" + e); } return usageTypeRequest; }  }
UsageTypeRepository { @SuppressWarnings("unchecked") public UsageTypeReq update(final UsageTypeReq usageTypeRequest) { final List<UsageType> usageTypes = usageTypeRequest.getUsageTypes(); final String usageTypeUpdateQuery = usageTypeQueryBuilder.getUpdateUsageTypeQuery(); final List<Map<String, Object>> usageTypeQueryParams = new ArrayList<>(); for (final UsageType usageType : usageTypes) usageTypeQueryParams.add(new MapSqlParameterSource("name", usageType.getName()) .addValue("description", usageType.getDescription()).addValue("parent", usageType.getParent()) .addValue("active", usageType.getActive()) .addValue("lastmodifiedby", usageTypeRequest.getRequestInfo().getUserInfo().getId()) .addValue("lastmodifieddate", new Date().getTime()).addValue("code", usageType.getCode()) .addValue("tenantid", usageType.getTenantId()).getValues()); try { namedParameterJdbcTemplate.batchUpdate(usageTypeUpdateQuery, usageTypeQueryParams.toArray(new Map[usageTypes.size()])); } catch (final Exception e) { logger.error("Error occured while updating usageType in db" + e); } return usageTypeRequest; }  List<UsageType> getUsageTypesByCriteria(final UsageTypeGetRequest usageTypeGetRequest); List<UsageType> pushCreateToQueue(final UsageTypeReq usageTypeRequest); @SuppressWarnings("unchecked") UsageTypeReq create(final UsageTypeReq usageTypeRequest); List<UsageType> pushUpdateToQueue(final UsageTypeReq usageTypeRequest); @SuppressWarnings("unchecked") UsageTypeReq update(final UsageTypeReq usageTypeRequest); }
UsageTypeRepository { @SuppressWarnings("unchecked") public UsageTypeReq update(final UsageTypeReq usageTypeRequest) { final List<UsageType> usageTypes = usageTypeRequest.getUsageTypes(); final String usageTypeUpdateQuery = usageTypeQueryBuilder.getUpdateUsageTypeQuery(); final List<Map<String, Object>> usageTypeQueryParams = new ArrayList<>(); for (final UsageType usageType : usageTypes) usageTypeQueryParams.add(new MapSqlParameterSource("name", usageType.getName()) .addValue("description", usageType.getDescription()).addValue("parent", usageType.getParent()) .addValue("active", usageType.getActive()) .addValue("lastmodifiedby", usageTypeRequest.getRequestInfo().getUserInfo().getId()) .addValue("lastmodifieddate", new Date().getTime()).addValue("code", usageType.getCode()) .addValue("tenantid", usageType.getTenantId()).getValues()); try { namedParameterJdbcTemplate.batchUpdate(usageTypeUpdateQuery, usageTypeQueryParams.toArray(new Map[usageTypes.size()])); } catch (final Exception e) { logger.error("Error occured while updating usageType in db" + e); } return usageTypeRequest; }  List<UsageType> getUsageTypesByCriteria(final UsageTypeGetRequest usageTypeGetRequest); List<UsageType> pushCreateToQueue(final UsageTypeReq usageTypeRequest); @SuppressWarnings("unchecked") UsageTypeReq create(final UsageTypeReq usageTypeRequest); List<UsageType> pushUpdateToQueue(final UsageTypeReq usageTypeRequest); @SuppressWarnings("unchecked") UsageTypeReq update(final UsageTypeReq usageTypeRequest); static final Logger logger; }