@Test(expected = InvalidDataException.class) @Sql(scripts = { "/sql/clearFund.sql", "/sql/insertFundData.sql" }) public void test_search_invalid_sort_option() { FundSearch search = getFundSearch(); search.setSortBy("desc"); fundJdbcRepository.search(search); }
public Pagination<Fund> search(FundSearch domain) { FundSearchEntity fundSearchEntity = new FundSearchEntity(); fundSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (fundSearchEntity.getSortBy() != null && !fundSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(fundSearchEntity.getSortBy()); validateEntityFieldName(fundSearchEntity.getSortBy(), FundEntity.class); } String orderBy = "order by name"; if (fundSearchEntity.getSortBy() != null && !fundSearchEntity.getSortBy().isEmpty()) { orderBy = "order by " + fundSearchEntity.getSortBy(); } searchQuery = searchQuery.replace(":tablename", FundEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (fundSearchEntity.getTenantId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("tenantId =:tenantId"); paramValues.put("tenantId", fundSearchEntity.getTenantId()); } if (fundSearchEntity.getId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id =:id"); paramValues.put("id", fundSearchEntity.getId()); } if (fundSearchEntity.getCode() != null) { if (params.length() > 0) { params.append(" and "); } params.append("code =:code"); paramValues.put("code", fundSearchEntity.getCode()); } if (fundSearchEntity.getName() != null) { if (params.length() > 0) { params.append(" and "); } params.append("name =:name"); paramValues.put("name", fundSearchEntity.getName()); } if (fundSearchEntity.getIdentifier() != null) { if (params.length() > 0) { params.append(" and "); } params.append("description =:description"); paramValues.put("description", fundSearchEntity.getIdentifier()); } if (fundSearchEntity.getActive() != null) { if (params.length() > 0) { params.append(" and "); } params.append("active =:active"); paramValues.put("active", fundSearchEntity.getActive()); } if (fundSearchEntity.getLevel() != null) { if (params.length() > 0) { params.append(" and "); } params.append("type =:type"); paramValues.put("type", fundSearchEntity.getLevel()); } Pagination<Fund> page = new Pagination<>(); if (fundSearchEntity.getOffset() != null) { page.setOffset(fundSearchEntity.getOffset()); } if (fundSearchEntity.getPageSize() != null) { page.setPageSize(fundSearchEntity.getPageSize()); } if (params.length() > 0) { searchQuery = searchQuery.replace(":condition", " where " + params.toString()); } else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<Fund>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(FundEntity.class); List<FundEntity> fundEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(fundEntities.size()); List<Fund> funds = new ArrayList<>(); for (FundEntity fundEntity : fundEntities) { funds.add(fundEntity.toDomain()); } page.setPagedData(funds); return page; }
FundJdbcRepository extends JdbcRepository { public Pagination<Fund> search(FundSearch domain) { FundSearchEntity fundSearchEntity = new FundSearchEntity(); fundSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (fundSearchEntity.getSortBy() != null && !fundSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(fundSearchEntity.getSortBy()); validateEntityFieldName(fundSearchEntity.getSortBy(), FundEntity.class); } String orderBy = "order by name"; if (fundSearchEntity.getSortBy() != null && !fundSearchEntity.getSortBy().isEmpty()) { orderBy = "order by " + fundSearchEntity.getSortBy(); } searchQuery = searchQuery.replace(":tablename", FundEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (fundSearchEntity.getTenantId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("tenantId =:tenantId"); paramValues.put("tenantId", fundSearchEntity.getTenantId()); } if (fundSearchEntity.getId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id =:id"); paramValues.put("id", fundSearchEntity.getId()); } if (fundSearchEntity.getCode() != null) { if (params.length() > 0) { params.append(" and "); } params.append("code =:code"); paramValues.put("code", fundSearchEntity.getCode()); } if (fundSearchEntity.getName() != null) { if (params.length() > 0) { params.append(" and "); } params.append("name =:name"); paramValues.put("name", fundSearchEntity.getName()); } if (fundSearchEntity.getIdentifier() != null) { if (params.length() > 0) { params.append(" and "); } params.append("description =:description"); paramValues.put("description", fundSearchEntity.getIdentifier()); } if (fundSearchEntity.getActive() != null) { if (params.length() > 0) { params.append(" and "); } params.append("active =:active"); paramValues.put("active", fundSearchEntity.getActive()); } if (fundSearchEntity.getLevel() != null) { if (params.length() > 0) { params.append(" and "); } params.append("type =:type"); paramValues.put("type", fundSearchEntity.getLevel()); } Pagination<Fund> page = new Pagination<>(); if (fundSearchEntity.getOffset() != null) { page.setOffset(fundSearchEntity.getOffset()); } if (fundSearchEntity.getPageSize() != null) { page.setPageSize(fundSearchEntity.getPageSize()); } if (params.length() > 0) { searchQuery = searchQuery.replace(":condition", " where " + params.toString()); } else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<Fund>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(FundEntity.class); List<FundEntity> fundEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(fundEntities.size()); List<Fund> funds = new ArrayList<>(); for (FundEntity fundEntity : fundEntities) { funds.add(fundEntity.toDomain()); } page.setPagedData(funds); return page; } }
FundJdbcRepository extends JdbcRepository { public Pagination<Fund> search(FundSearch domain) { FundSearchEntity fundSearchEntity = new FundSearchEntity(); fundSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (fundSearchEntity.getSortBy() != null && !fundSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(fundSearchEntity.getSortBy()); validateEntityFieldName(fundSearchEntity.getSortBy(), FundEntity.class); } String orderBy = "order by name"; if (fundSearchEntity.getSortBy() != null && !fundSearchEntity.getSortBy().isEmpty()) { orderBy = "order by " + fundSearchEntity.getSortBy(); } searchQuery = searchQuery.replace(":tablename", FundEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (fundSearchEntity.getTenantId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("tenantId =:tenantId"); paramValues.put("tenantId", fundSearchEntity.getTenantId()); } if (fundSearchEntity.getId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id =:id"); paramValues.put("id", fundSearchEntity.getId()); } if (fundSearchEntity.getCode() != null) { if (params.length() > 0) { params.append(" and "); } params.append("code =:code"); paramValues.put("code", fundSearchEntity.getCode()); } if (fundSearchEntity.getName() != null) { if (params.length() > 0) { params.append(" and "); } params.append("name =:name"); paramValues.put("name", fundSearchEntity.getName()); } if (fundSearchEntity.getIdentifier() != null) { if (params.length() > 0) { params.append(" and "); } params.append("description =:description"); paramValues.put("description", fundSearchEntity.getIdentifier()); } if (fundSearchEntity.getActive() != null) { if (params.length() > 0) { params.append(" and "); } params.append("active =:active"); paramValues.put("active", fundSearchEntity.getActive()); } if (fundSearchEntity.getLevel() != null) { if (params.length() > 0) { params.append(" and "); } params.append("type =:type"); paramValues.put("type", fundSearchEntity.getLevel()); } Pagination<Fund> page = new Pagination<>(); if (fundSearchEntity.getOffset() != null) { page.setOffset(fundSearchEntity.getOffset()); } if (fundSearchEntity.getPageSize() != null) { page.setPageSize(fundSearchEntity.getPageSize()); } if (params.length() > 0) { searchQuery = searchQuery.replace(":condition", " where " + params.toString()); } else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<Fund>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(FundEntity.class); List<FundEntity> fundEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(fundEntities.size()); List<Fund> funds = new ArrayList<>(); for (FundEntity fundEntity : fundEntities) { funds.add(fundEntity.toDomain()); } page.setPagedData(funds); return page; } FundJdbcRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate); }
FundJdbcRepository extends JdbcRepository { public Pagination<Fund> search(FundSearch domain) { FundSearchEntity fundSearchEntity = new FundSearchEntity(); fundSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (fundSearchEntity.getSortBy() != null && !fundSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(fundSearchEntity.getSortBy()); validateEntityFieldName(fundSearchEntity.getSortBy(), FundEntity.class); } String orderBy = "order by name"; if (fundSearchEntity.getSortBy() != null && !fundSearchEntity.getSortBy().isEmpty()) { orderBy = "order by " + fundSearchEntity.getSortBy(); } searchQuery = searchQuery.replace(":tablename", FundEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (fundSearchEntity.getTenantId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("tenantId =:tenantId"); paramValues.put("tenantId", fundSearchEntity.getTenantId()); } if (fundSearchEntity.getId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id =:id"); paramValues.put("id", fundSearchEntity.getId()); } if (fundSearchEntity.getCode() != null) { if (params.length() > 0) { params.append(" and "); } params.append("code =:code"); paramValues.put("code", fundSearchEntity.getCode()); } if (fundSearchEntity.getName() != null) { if (params.length() > 0) { params.append(" and "); } params.append("name =:name"); paramValues.put("name", fundSearchEntity.getName()); } if (fundSearchEntity.getIdentifier() != null) { if (params.length() > 0) { params.append(" and "); } params.append("description =:description"); paramValues.put("description", fundSearchEntity.getIdentifier()); } if (fundSearchEntity.getActive() != null) { if (params.length() > 0) { params.append(" and "); } params.append("active =:active"); paramValues.put("active", fundSearchEntity.getActive()); } if (fundSearchEntity.getLevel() != null) { if (params.length() > 0) { params.append(" and "); } params.append("type =:type"); paramValues.put("type", fundSearchEntity.getLevel()); } Pagination<Fund> page = new Pagination<>(); if (fundSearchEntity.getOffset() != null) { page.setOffset(fundSearchEntity.getOffset()); } if (fundSearchEntity.getPageSize() != null) { page.setPageSize(fundSearchEntity.getPageSize()); } if (params.length() > 0) { searchQuery = searchQuery.replace(":condition", " where " + params.toString()); } else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<Fund>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(FundEntity.class); List<FundEntity> fundEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(fundEntities.size()); List<Fund> funds = new ArrayList<>(); for (FundEntity fundEntity : fundEntities) { funds.add(fundEntity.toDomain()); } page.setPagedData(funds); return page; } FundJdbcRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate); FundEntity create(FundEntity entity); FundEntity update(FundEntity entity); boolean delete(FundEntity entity,String reason); Pagination<Fund> search(FundSearch domain); FundEntity findById(FundEntity entity); }
FundJdbcRepository extends JdbcRepository { public Pagination<Fund> search(FundSearch domain) { FundSearchEntity fundSearchEntity = new FundSearchEntity(); fundSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (fundSearchEntity.getSortBy() != null && !fundSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(fundSearchEntity.getSortBy()); validateEntityFieldName(fundSearchEntity.getSortBy(), FundEntity.class); } String orderBy = "order by name"; if (fundSearchEntity.getSortBy() != null && !fundSearchEntity.getSortBy().isEmpty()) { orderBy = "order by " + fundSearchEntity.getSortBy(); } searchQuery = searchQuery.replace(":tablename", FundEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (fundSearchEntity.getTenantId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("tenantId =:tenantId"); paramValues.put("tenantId", fundSearchEntity.getTenantId()); } if (fundSearchEntity.getId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id =:id"); paramValues.put("id", fundSearchEntity.getId()); } if (fundSearchEntity.getCode() != null) { if (params.length() > 0) { params.append(" and "); } params.append("code =:code"); paramValues.put("code", fundSearchEntity.getCode()); } if (fundSearchEntity.getName() != null) { if (params.length() > 0) { params.append(" and "); } params.append("name =:name"); paramValues.put("name", fundSearchEntity.getName()); } if (fundSearchEntity.getIdentifier() != null) { if (params.length() > 0) { params.append(" and "); } params.append("description =:description"); paramValues.put("description", fundSearchEntity.getIdentifier()); } if (fundSearchEntity.getActive() != null) { if (params.length() > 0) { params.append(" and "); } params.append("active =:active"); paramValues.put("active", fundSearchEntity.getActive()); } if (fundSearchEntity.getLevel() != null) { if (params.length() > 0) { params.append(" and "); } params.append("type =:type"); paramValues.put("type", fundSearchEntity.getLevel()); } Pagination<Fund> page = new Pagination<>(); if (fundSearchEntity.getOffset() != null) { page.setOffset(fundSearchEntity.getOffset()); } if (fundSearchEntity.getPageSize() != null) { page.setPageSize(fundSearchEntity.getPageSize()); } if (params.length() > 0) { searchQuery = searchQuery.replace(":condition", " where " + params.toString()); } else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<Fund>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(FundEntity.class); List<FundEntity> fundEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(fundEntities.size()); List<Fund> funds = new ArrayList<>(); for (FundEntity fundEntity : fundEntities) { funds.add(fundEntity.toDomain()); } page.setPagedData(funds); return page; } FundJdbcRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate); FundEntity create(FundEntity entity); FundEntity update(FundEntity entity); boolean delete(FundEntity entity,String reason); Pagination<Fund> search(FundSearch domain); FundEntity findById(FundEntity entity);  }