@Test @Sql(scripts = { "/sql/surrenderreason/clearSurrenderReason.sql", "/sql/surrenderreason/insertSurrenderReasonData.sql" }) public void test_search_without_pagesize_offset_sortby() { SurrenderReasonSearch search = getSurrenderReasonSearch(); search.setSortBy(null); search.setPageSize(null); search.setOffset(null); Pagination<SurrenderReason> page = (Pagination<SurrenderReason>) surrenderReasonJdbcRepository .search(getSurrenderReasonSearch()); assertThat(page.getPagedData().get(0).getName()).isEqualTo("name"); assertThat(page.getPagedData().get(0).getDescription()).isEqualTo("description"); }
public Pagination<SurrenderReason> search(SurrenderReasonSearch domain) { SurrenderReasonSearchEntity surrenderReasonSearchEntity = new SurrenderReasonSearchEntity(); surrenderReasonSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (surrenderReasonSearchEntity.getSortBy() != null && !surrenderReasonSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(surrenderReasonSearchEntity.getSortBy()); validateEntityFieldName(surrenderReasonSearchEntity.getSortBy(), SurrenderReasonEntity.class); } String orderBy = "order by id"; if (surrenderReasonSearchEntity.getSortBy() != null && !surrenderReasonSearchEntity.getSortBy().isEmpty()) orderBy = "order by " + surrenderReasonSearchEntity.getSortBy(); searchQuery = searchQuery.replace(":tablename", SurrenderReasonEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (surrenderReasonSearchEntity.getTenantId() != null) { if (params.length() > 0) params.append(" and "); params.append("tenantId =:tenantId"); paramValues.put("tenantId", surrenderReasonSearchEntity.getTenantId()); } if (surrenderReasonSearchEntity.getId() != null) { if (params.length() > 0) params.append(" and "); params.append("id =:id"); paramValues.put("id", surrenderReasonSearchEntity.getId()); } if (surrenderReasonSearchEntity.getName() != null) { if (params.length() > 0) params.append(" and "); params.append("name =:name"); paramValues.put("name", surrenderReasonSearchEntity.getName()); } if (surrenderReasonSearchEntity.getDescription() != null) { if (params.length() > 0) params.append(" and "); params.append("description =:description"); paramValues.put("description", surrenderReasonSearchEntity.getDescription()); } if (surrenderReasonSearchEntity.getIds() != null) { if (params.length() > 0) params.append(" and "); params.append("id in (:ids)"); paramValues.put("ids", surrenderReasonSearchEntity.getIds()); } Pagination<SurrenderReason> page = new Pagination<>(); if (surrenderReasonSearchEntity.getOffset() != null) page.setOffset(surrenderReasonSearchEntity.getOffset()); if (surrenderReasonSearchEntity.getPageSize() != null) page.setPageSize(surrenderReasonSearchEntity.getPageSize()); if (params.length() > 0) searchQuery = searchQuery.replace(":condition", " where " + params.toString()); else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<SurrenderReason>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(SurrenderReasonEntity.class); List<SurrenderReasonEntity> surrenderReasonEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(surrenderReasonEntities.size()); List<SurrenderReason> surrenderreasons = new ArrayList<>(); for (SurrenderReasonEntity surrenderReasonEntity : surrenderReasonEntities) surrenderreasons.add(surrenderReasonEntity.toDomain()); page.setPagedData(surrenderreasons); return page; }
SurrenderReasonJdbcRepository extends JdbcRepository { public Pagination<SurrenderReason> search(SurrenderReasonSearch domain) { SurrenderReasonSearchEntity surrenderReasonSearchEntity = new SurrenderReasonSearchEntity(); surrenderReasonSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (surrenderReasonSearchEntity.getSortBy() != null && !surrenderReasonSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(surrenderReasonSearchEntity.getSortBy()); validateEntityFieldName(surrenderReasonSearchEntity.getSortBy(), SurrenderReasonEntity.class); } String orderBy = "order by id"; if (surrenderReasonSearchEntity.getSortBy() != null && !surrenderReasonSearchEntity.getSortBy().isEmpty()) orderBy = "order by " + surrenderReasonSearchEntity.getSortBy(); searchQuery = searchQuery.replace(":tablename", SurrenderReasonEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (surrenderReasonSearchEntity.getTenantId() != null) { if (params.length() > 0) params.append(" and "); params.append("tenantId =:tenantId"); paramValues.put("tenantId", surrenderReasonSearchEntity.getTenantId()); } if (surrenderReasonSearchEntity.getId() != null) { if (params.length() > 0) params.append(" and "); params.append("id =:id"); paramValues.put("id", surrenderReasonSearchEntity.getId()); } if (surrenderReasonSearchEntity.getName() != null) { if (params.length() > 0) params.append(" and "); params.append("name =:name"); paramValues.put("name", surrenderReasonSearchEntity.getName()); } if (surrenderReasonSearchEntity.getDescription() != null) { if (params.length() > 0) params.append(" and "); params.append("description =:description"); paramValues.put("description", surrenderReasonSearchEntity.getDescription()); } if (surrenderReasonSearchEntity.getIds() != null) { if (params.length() > 0) params.append(" and "); params.append("id in (:ids)"); paramValues.put("ids", surrenderReasonSearchEntity.getIds()); } Pagination<SurrenderReason> page = new Pagination<>(); if (surrenderReasonSearchEntity.getOffset() != null) page.setOffset(surrenderReasonSearchEntity.getOffset()); if (surrenderReasonSearchEntity.getPageSize() != null) page.setPageSize(surrenderReasonSearchEntity.getPageSize()); if (params.length() > 0) searchQuery = searchQuery.replace(":condition", " where " + params.toString()); else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<SurrenderReason>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(SurrenderReasonEntity.class); List<SurrenderReasonEntity> surrenderReasonEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(surrenderReasonEntities.size()); List<SurrenderReason> surrenderreasons = new ArrayList<>(); for (SurrenderReasonEntity surrenderReasonEntity : surrenderReasonEntities) surrenderreasons.add(surrenderReasonEntity.toDomain()); page.setPagedData(surrenderreasons); return page; } }
SurrenderReasonJdbcRepository extends JdbcRepository { public Pagination<SurrenderReason> search(SurrenderReasonSearch domain) { SurrenderReasonSearchEntity surrenderReasonSearchEntity = new SurrenderReasonSearchEntity(); surrenderReasonSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (surrenderReasonSearchEntity.getSortBy() != null && !surrenderReasonSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(surrenderReasonSearchEntity.getSortBy()); validateEntityFieldName(surrenderReasonSearchEntity.getSortBy(), SurrenderReasonEntity.class); } String orderBy = "order by id"; if (surrenderReasonSearchEntity.getSortBy() != null && !surrenderReasonSearchEntity.getSortBy().isEmpty()) orderBy = "order by " + surrenderReasonSearchEntity.getSortBy(); searchQuery = searchQuery.replace(":tablename", SurrenderReasonEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (surrenderReasonSearchEntity.getTenantId() != null) { if (params.length() > 0) params.append(" and "); params.append("tenantId =:tenantId"); paramValues.put("tenantId", surrenderReasonSearchEntity.getTenantId()); } if (surrenderReasonSearchEntity.getId() != null) { if (params.length() > 0) params.append(" and "); params.append("id =:id"); paramValues.put("id", surrenderReasonSearchEntity.getId()); } if (surrenderReasonSearchEntity.getName() != null) { if (params.length() > 0) params.append(" and "); params.append("name =:name"); paramValues.put("name", surrenderReasonSearchEntity.getName()); } if (surrenderReasonSearchEntity.getDescription() != null) { if (params.length() > 0) params.append(" and "); params.append("description =:description"); paramValues.put("description", surrenderReasonSearchEntity.getDescription()); } if (surrenderReasonSearchEntity.getIds() != null) { if (params.length() > 0) params.append(" and "); params.append("id in (:ids)"); paramValues.put("ids", surrenderReasonSearchEntity.getIds()); } Pagination<SurrenderReason> page = new Pagination<>(); if (surrenderReasonSearchEntity.getOffset() != null) page.setOffset(surrenderReasonSearchEntity.getOffset()); if (surrenderReasonSearchEntity.getPageSize() != null) page.setPageSize(surrenderReasonSearchEntity.getPageSize()); if (params.length() > 0) searchQuery = searchQuery.replace(":condition", " where " + params.toString()); else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<SurrenderReason>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(SurrenderReasonEntity.class); List<SurrenderReasonEntity> surrenderReasonEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(surrenderReasonEntities.size()); List<SurrenderReason> surrenderreasons = new ArrayList<>(); for (SurrenderReasonEntity surrenderReasonEntity : surrenderReasonEntities) surrenderreasons.add(surrenderReasonEntity.toDomain()); page.setPagedData(surrenderreasons); return page; } SurrenderReasonJdbcRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate, JdbcTemplate jdbcTemplate); }
SurrenderReasonJdbcRepository extends JdbcRepository { public Pagination<SurrenderReason> search(SurrenderReasonSearch domain) { SurrenderReasonSearchEntity surrenderReasonSearchEntity = new SurrenderReasonSearchEntity(); surrenderReasonSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (surrenderReasonSearchEntity.getSortBy() != null && !surrenderReasonSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(surrenderReasonSearchEntity.getSortBy()); validateEntityFieldName(surrenderReasonSearchEntity.getSortBy(), SurrenderReasonEntity.class); } String orderBy = "order by id"; if (surrenderReasonSearchEntity.getSortBy() != null && !surrenderReasonSearchEntity.getSortBy().isEmpty()) orderBy = "order by " + surrenderReasonSearchEntity.getSortBy(); searchQuery = searchQuery.replace(":tablename", SurrenderReasonEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (surrenderReasonSearchEntity.getTenantId() != null) { if (params.length() > 0) params.append(" and "); params.append("tenantId =:tenantId"); paramValues.put("tenantId", surrenderReasonSearchEntity.getTenantId()); } if (surrenderReasonSearchEntity.getId() != null) { if (params.length() > 0) params.append(" and "); params.append("id =:id"); paramValues.put("id", surrenderReasonSearchEntity.getId()); } if (surrenderReasonSearchEntity.getName() != null) { if (params.length() > 0) params.append(" and "); params.append("name =:name"); paramValues.put("name", surrenderReasonSearchEntity.getName()); } if (surrenderReasonSearchEntity.getDescription() != null) { if (params.length() > 0) params.append(" and "); params.append("description =:description"); paramValues.put("description", surrenderReasonSearchEntity.getDescription()); } if (surrenderReasonSearchEntity.getIds() != null) { if (params.length() > 0) params.append(" and "); params.append("id in (:ids)"); paramValues.put("ids", surrenderReasonSearchEntity.getIds()); } Pagination<SurrenderReason> page = new Pagination<>(); if (surrenderReasonSearchEntity.getOffset() != null) page.setOffset(surrenderReasonSearchEntity.getOffset()); if (surrenderReasonSearchEntity.getPageSize() != null) page.setPageSize(surrenderReasonSearchEntity.getPageSize()); if (params.length() > 0) searchQuery = searchQuery.replace(":condition", " where " + params.toString()); else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<SurrenderReason>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(SurrenderReasonEntity.class); List<SurrenderReasonEntity> surrenderReasonEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(surrenderReasonEntities.size()); List<SurrenderReason> surrenderreasons = new ArrayList<>(); for (SurrenderReasonEntity surrenderReasonEntity : surrenderReasonEntities) surrenderreasons.add(surrenderReasonEntity.toDomain()); page.setPagedData(surrenderreasons); return page; } SurrenderReasonJdbcRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate, JdbcTemplate jdbcTemplate); SurrenderReasonEntity create(SurrenderReasonEntity entity); SurrenderReasonEntity update(SurrenderReasonEntity entity); SurrenderReasonEntity delete(SurrenderReasonEntity entity); Pagination<SurrenderReason> search(SurrenderReasonSearch domain); SurrenderReasonEntity findById(SurrenderReasonEntity entity); }
SurrenderReasonJdbcRepository extends JdbcRepository { public Pagination<SurrenderReason> search(SurrenderReasonSearch domain) { SurrenderReasonSearchEntity surrenderReasonSearchEntity = new SurrenderReasonSearchEntity(); surrenderReasonSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (surrenderReasonSearchEntity.getSortBy() != null && !surrenderReasonSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(surrenderReasonSearchEntity.getSortBy()); validateEntityFieldName(surrenderReasonSearchEntity.getSortBy(), SurrenderReasonEntity.class); } String orderBy = "order by id"; if (surrenderReasonSearchEntity.getSortBy() != null && !surrenderReasonSearchEntity.getSortBy().isEmpty()) orderBy = "order by " + surrenderReasonSearchEntity.getSortBy(); searchQuery = searchQuery.replace(":tablename", SurrenderReasonEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (surrenderReasonSearchEntity.getTenantId() != null) { if (params.length() > 0) params.append(" and "); params.append("tenantId =:tenantId"); paramValues.put("tenantId", surrenderReasonSearchEntity.getTenantId()); } if (surrenderReasonSearchEntity.getId() != null) { if (params.length() > 0) params.append(" and "); params.append("id =:id"); paramValues.put("id", surrenderReasonSearchEntity.getId()); } if (surrenderReasonSearchEntity.getName() != null) { if (params.length() > 0) params.append(" and "); params.append("name =:name"); paramValues.put("name", surrenderReasonSearchEntity.getName()); } if (surrenderReasonSearchEntity.getDescription() != null) { if (params.length() > 0) params.append(" and "); params.append("description =:description"); paramValues.put("description", surrenderReasonSearchEntity.getDescription()); } if (surrenderReasonSearchEntity.getIds() != null) { if (params.length() > 0) params.append(" and "); params.append("id in (:ids)"); paramValues.put("ids", surrenderReasonSearchEntity.getIds()); } Pagination<SurrenderReason> page = new Pagination<>(); if (surrenderReasonSearchEntity.getOffset() != null) page.setOffset(surrenderReasonSearchEntity.getOffset()); if (surrenderReasonSearchEntity.getPageSize() != null) page.setPageSize(surrenderReasonSearchEntity.getPageSize()); if (params.length() > 0) searchQuery = searchQuery.replace(":condition", " where " + params.toString()); else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<SurrenderReason>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(SurrenderReasonEntity.class); List<SurrenderReasonEntity> surrenderReasonEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(surrenderReasonEntities.size()); List<SurrenderReason> surrenderreasons = new ArrayList<>(); for (SurrenderReasonEntity surrenderReasonEntity : surrenderReasonEntities) surrenderreasons.add(surrenderReasonEntity.toDomain()); page.setPagedData(surrenderreasons); return page; } SurrenderReasonJdbcRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate, JdbcTemplate jdbcTemplate); SurrenderReasonEntity create(SurrenderReasonEntity entity); SurrenderReasonEntity update(SurrenderReasonEntity entity); SurrenderReasonEntity delete(SurrenderReasonEntity entity); Pagination<SurrenderReason> search(SurrenderReasonSearch domain); SurrenderReasonEntity findById(SurrenderReasonEntity entity);  }