@Test @Sql(scripts = { "/sql/instrumenttype/clearInstrumentType.sql", "/sql/instrumenttype/insertInstrumentTypeData.sql" }) public void test_search_without_pagesize_offset_sortby() { InstrumentTypeSearch search = getInstrumentTypeSearch(); search.setSortBy(null); search.setPageSize(null); search.setOffset(null); Pagination<InstrumentType> page = (Pagination<InstrumentType>) instrumentTypeJdbcRepository .search(getInstrumentTypeSearch()); assertThat(page.getPagedData().get(0).getActive()).isEqualTo(true); assertThat(page.getPagedData().get(0).getName()).isEqualTo("name"); assertThat(page.getPagedData().get(0).getDescription()).isEqualTo("description"); }
public Pagination<InstrumentType> search(InstrumentTypeSearch domain) { InstrumentTypeSearchEntity instrumentTypeSearchEntity = new InstrumentTypeSearchEntity(); instrumentTypeSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (instrumentTypeSearchEntity.getSortBy() != null && !instrumentTypeSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(instrumentTypeSearchEntity.getSortBy()); validateEntityFieldName(instrumentTypeSearchEntity.getSortBy(), InstrumentTypeEntity.class); } String orderBy = "order by id"; if (instrumentTypeSearchEntity.getSortBy() != null && !instrumentTypeSearchEntity.getSortBy().isEmpty()) orderBy = "order by " + instrumentTypeSearchEntity.getSortBy(); searchQuery = searchQuery.replace(":tablename", InstrumentTypeEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (instrumentTypeSearchEntity.getTenantId() != null) { if (params.length() > 0) params.append(" and "); params.append("tenantId =:tenantId"); paramValues.put("tenantId", instrumentTypeSearchEntity.getTenantId()); } if (instrumentTypeSearchEntity.getId() != null) { if (params.length() > 0) params.append(" and "); params.append("id =:id"); paramValues.put("id", instrumentTypeSearchEntity.getId()); } if (instrumentTypeSearchEntity.getName() != null) { if (params.length() > 0) params.append(" and "); params.append("name =:name"); paramValues.put("name", instrumentTypeSearchEntity.getName()); } if (instrumentTypeSearchEntity.getDescription() != null) { if (params.length() > 0) params.append(" and "); params.append("description =:description"); paramValues.put("description", instrumentTypeSearchEntity.getDescription()); } if (instrumentTypeSearchEntity.getActive() != null) { if (params.length() > 0) params.append(" and "); params.append("active =:active"); paramValues.put("active", instrumentTypeSearchEntity.getActive()); } if (instrumentTypeSearchEntity.getIds() != null) { if (params.length() > 0) params.append(" and "); params.append("id in (:ids)"); paramValues.put("ids", instrumentTypeSearchEntity.getIds()); } Pagination<InstrumentType> page = new Pagination<>(); if (instrumentTypeSearchEntity.getOffset() != null) page.setOffset(instrumentTypeSearchEntity.getOffset()); if (instrumentTypeSearchEntity.getPageSize() != null) page.setPageSize(instrumentTypeSearchEntity.getPageSize()); if (params.length() > 0) searchQuery = searchQuery.replace(":condition", " where " + params.toString()); else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<InstrumentType>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(InstrumentTypeEntity.class); List<InstrumentTypeEntity> instrumentTypeEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(instrumentTypeEntities.size()); List<InstrumentType> instrumenttypes = new ArrayList<>(); for (InstrumentTypeEntity instrumentTypeEntity : instrumentTypeEntities) instrumenttypes.add(instrumentTypeEntity.toDomain()); page.setPagedData(instrumenttypes); return page; }
InstrumentTypeJdbcRepository extends JdbcRepository { public Pagination<InstrumentType> search(InstrumentTypeSearch domain) { InstrumentTypeSearchEntity instrumentTypeSearchEntity = new InstrumentTypeSearchEntity(); instrumentTypeSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (instrumentTypeSearchEntity.getSortBy() != null && !instrumentTypeSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(instrumentTypeSearchEntity.getSortBy()); validateEntityFieldName(instrumentTypeSearchEntity.getSortBy(), InstrumentTypeEntity.class); } String orderBy = "order by id"; if (instrumentTypeSearchEntity.getSortBy() != null && !instrumentTypeSearchEntity.getSortBy().isEmpty()) orderBy = "order by " + instrumentTypeSearchEntity.getSortBy(); searchQuery = searchQuery.replace(":tablename", InstrumentTypeEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (instrumentTypeSearchEntity.getTenantId() != null) { if (params.length() > 0) params.append(" and "); params.append("tenantId =:tenantId"); paramValues.put("tenantId", instrumentTypeSearchEntity.getTenantId()); } if (instrumentTypeSearchEntity.getId() != null) { if (params.length() > 0) params.append(" and "); params.append("id =:id"); paramValues.put("id", instrumentTypeSearchEntity.getId()); } if (instrumentTypeSearchEntity.getName() != null) { if (params.length() > 0) params.append(" and "); params.append("name =:name"); paramValues.put("name", instrumentTypeSearchEntity.getName()); } if (instrumentTypeSearchEntity.getDescription() != null) { if (params.length() > 0) params.append(" and "); params.append("description =:description"); paramValues.put("description", instrumentTypeSearchEntity.getDescription()); } if (instrumentTypeSearchEntity.getActive() != null) { if (params.length() > 0) params.append(" and "); params.append("active =:active"); paramValues.put("active", instrumentTypeSearchEntity.getActive()); } if (instrumentTypeSearchEntity.getIds() != null) { if (params.length() > 0) params.append(" and "); params.append("id in (:ids)"); paramValues.put("ids", instrumentTypeSearchEntity.getIds()); } Pagination<InstrumentType> page = new Pagination<>(); if (instrumentTypeSearchEntity.getOffset() != null) page.setOffset(instrumentTypeSearchEntity.getOffset()); if (instrumentTypeSearchEntity.getPageSize() != null) page.setPageSize(instrumentTypeSearchEntity.getPageSize()); if (params.length() > 0) searchQuery = searchQuery.replace(":condition", " where " + params.toString()); else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<InstrumentType>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(InstrumentTypeEntity.class); List<InstrumentTypeEntity> instrumentTypeEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(instrumentTypeEntities.size()); List<InstrumentType> instrumenttypes = new ArrayList<>(); for (InstrumentTypeEntity instrumentTypeEntity : instrumentTypeEntities) instrumenttypes.add(instrumentTypeEntity.toDomain()); page.setPagedData(instrumenttypes); return page; } }
InstrumentTypeJdbcRepository extends JdbcRepository { public Pagination<InstrumentType> search(InstrumentTypeSearch domain) { InstrumentTypeSearchEntity instrumentTypeSearchEntity = new InstrumentTypeSearchEntity(); instrumentTypeSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (instrumentTypeSearchEntity.getSortBy() != null && !instrumentTypeSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(instrumentTypeSearchEntity.getSortBy()); validateEntityFieldName(instrumentTypeSearchEntity.getSortBy(), InstrumentTypeEntity.class); } String orderBy = "order by id"; if (instrumentTypeSearchEntity.getSortBy() != null && !instrumentTypeSearchEntity.getSortBy().isEmpty()) orderBy = "order by " + instrumentTypeSearchEntity.getSortBy(); searchQuery = searchQuery.replace(":tablename", InstrumentTypeEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (instrumentTypeSearchEntity.getTenantId() != null) { if (params.length() > 0) params.append(" and "); params.append("tenantId =:tenantId"); paramValues.put("tenantId", instrumentTypeSearchEntity.getTenantId()); } if (instrumentTypeSearchEntity.getId() != null) { if (params.length() > 0) params.append(" and "); params.append("id =:id"); paramValues.put("id", instrumentTypeSearchEntity.getId()); } if (instrumentTypeSearchEntity.getName() != null) { if (params.length() > 0) params.append(" and "); params.append("name =:name"); paramValues.put("name", instrumentTypeSearchEntity.getName()); } if (instrumentTypeSearchEntity.getDescription() != null) { if (params.length() > 0) params.append(" and "); params.append("description =:description"); paramValues.put("description", instrumentTypeSearchEntity.getDescription()); } if (instrumentTypeSearchEntity.getActive() != null) { if (params.length() > 0) params.append(" and "); params.append("active =:active"); paramValues.put("active", instrumentTypeSearchEntity.getActive()); } if (instrumentTypeSearchEntity.getIds() != null) { if (params.length() > 0) params.append(" and "); params.append("id in (:ids)"); paramValues.put("ids", instrumentTypeSearchEntity.getIds()); } Pagination<InstrumentType> page = new Pagination<>(); if (instrumentTypeSearchEntity.getOffset() != null) page.setOffset(instrumentTypeSearchEntity.getOffset()); if (instrumentTypeSearchEntity.getPageSize() != null) page.setPageSize(instrumentTypeSearchEntity.getPageSize()); if (params.length() > 0) searchQuery = searchQuery.replace(":condition", " where " + params.toString()); else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<InstrumentType>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(InstrumentTypeEntity.class); List<InstrumentTypeEntity> instrumentTypeEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(instrumentTypeEntities.size()); List<InstrumentType> instrumenttypes = new ArrayList<>(); for (InstrumentTypeEntity instrumentTypeEntity : instrumentTypeEntities) instrumenttypes.add(instrumentTypeEntity.toDomain()); page.setPagedData(instrumenttypes); return page; } InstrumentTypeJdbcRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate, JdbcTemplate jdbcTemplate); }
InstrumentTypeJdbcRepository extends JdbcRepository { public Pagination<InstrumentType> search(InstrumentTypeSearch domain) { InstrumentTypeSearchEntity instrumentTypeSearchEntity = new InstrumentTypeSearchEntity(); instrumentTypeSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (instrumentTypeSearchEntity.getSortBy() != null && !instrumentTypeSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(instrumentTypeSearchEntity.getSortBy()); validateEntityFieldName(instrumentTypeSearchEntity.getSortBy(), InstrumentTypeEntity.class); } String orderBy = "order by id"; if (instrumentTypeSearchEntity.getSortBy() != null && !instrumentTypeSearchEntity.getSortBy().isEmpty()) orderBy = "order by " + instrumentTypeSearchEntity.getSortBy(); searchQuery = searchQuery.replace(":tablename", InstrumentTypeEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (instrumentTypeSearchEntity.getTenantId() != null) { if (params.length() > 0) params.append(" and "); params.append("tenantId =:tenantId"); paramValues.put("tenantId", instrumentTypeSearchEntity.getTenantId()); } if (instrumentTypeSearchEntity.getId() != null) { if (params.length() > 0) params.append(" and "); params.append("id =:id"); paramValues.put("id", instrumentTypeSearchEntity.getId()); } if (instrumentTypeSearchEntity.getName() != null) { if (params.length() > 0) params.append(" and "); params.append("name =:name"); paramValues.put("name", instrumentTypeSearchEntity.getName()); } if (instrumentTypeSearchEntity.getDescription() != null) { if (params.length() > 0) params.append(" and "); params.append("description =:description"); paramValues.put("description", instrumentTypeSearchEntity.getDescription()); } if (instrumentTypeSearchEntity.getActive() != null) { if (params.length() > 0) params.append(" and "); params.append("active =:active"); paramValues.put("active", instrumentTypeSearchEntity.getActive()); } if (instrumentTypeSearchEntity.getIds() != null) { if (params.length() > 0) params.append(" and "); params.append("id in (:ids)"); paramValues.put("ids", instrumentTypeSearchEntity.getIds()); } Pagination<InstrumentType> page = new Pagination<>(); if (instrumentTypeSearchEntity.getOffset() != null) page.setOffset(instrumentTypeSearchEntity.getOffset()); if (instrumentTypeSearchEntity.getPageSize() != null) page.setPageSize(instrumentTypeSearchEntity.getPageSize()); if (params.length() > 0) searchQuery = searchQuery.replace(":condition", " where " + params.toString()); else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<InstrumentType>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(InstrumentTypeEntity.class); List<InstrumentTypeEntity> instrumentTypeEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(instrumentTypeEntities.size()); List<InstrumentType> instrumenttypes = new ArrayList<>(); for (InstrumentTypeEntity instrumentTypeEntity : instrumentTypeEntities) instrumenttypes.add(instrumentTypeEntity.toDomain()); page.setPagedData(instrumenttypes); return page; } InstrumentTypeJdbcRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate, JdbcTemplate jdbcTemplate); InstrumentTypeEntity create(InstrumentTypeEntity entity); InstrumentTypeEntity update(InstrumentTypeEntity entity); InstrumentTypeEntity delete(InstrumentTypeEntity entity); Pagination<InstrumentType> search(InstrumentTypeSearch domain); InstrumentTypeEntity findById(InstrumentTypeEntity entity); }
InstrumentTypeJdbcRepository extends JdbcRepository { public Pagination<InstrumentType> search(InstrumentTypeSearch domain) { InstrumentTypeSearchEntity instrumentTypeSearchEntity = new InstrumentTypeSearchEntity(); instrumentTypeSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (instrumentTypeSearchEntity.getSortBy() != null && !instrumentTypeSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(instrumentTypeSearchEntity.getSortBy()); validateEntityFieldName(instrumentTypeSearchEntity.getSortBy(), InstrumentTypeEntity.class); } String orderBy = "order by id"; if (instrumentTypeSearchEntity.getSortBy() != null && !instrumentTypeSearchEntity.getSortBy().isEmpty()) orderBy = "order by " + instrumentTypeSearchEntity.getSortBy(); searchQuery = searchQuery.replace(":tablename", InstrumentTypeEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (instrumentTypeSearchEntity.getTenantId() != null) { if (params.length() > 0) params.append(" and "); params.append("tenantId =:tenantId"); paramValues.put("tenantId", instrumentTypeSearchEntity.getTenantId()); } if (instrumentTypeSearchEntity.getId() != null) { if (params.length() > 0) params.append(" and "); params.append("id =:id"); paramValues.put("id", instrumentTypeSearchEntity.getId()); } if (instrumentTypeSearchEntity.getName() != null) { if (params.length() > 0) params.append(" and "); params.append("name =:name"); paramValues.put("name", instrumentTypeSearchEntity.getName()); } if (instrumentTypeSearchEntity.getDescription() != null) { if (params.length() > 0) params.append(" and "); params.append("description =:description"); paramValues.put("description", instrumentTypeSearchEntity.getDescription()); } if (instrumentTypeSearchEntity.getActive() != null) { if (params.length() > 0) params.append(" and "); params.append("active =:active"); paramValues.put("active", instrumentTypeSearchEntity.getActive()); } if (instrumentTypeSearchEntity.getIds() != null) { if (params.length() > 0) params.append(" and "); params.append("id in (:ids)"); paramValues.put("ids", instrumentTypeSearchEntity.getIds()); } Pagination<InstrumentType> page = new Pagination<>(); if (instrumentTypeSearchEntity.getOffset() != null) page.setOffset(instrumentTypeSearchEntity.getOffset()); if (instrumentTypeSearchEntity.getPageSize() != null) page.setPageSize(instrumentTypeSearchEntity.getPageSize()); if (params.length() > 0) searchQuery = searchQuery.replace(":condition", " where " + params.toString()); else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<InstrumentType>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(InstrumentTypeEntity.class); List<InstrumentTypeEntity> instrumentTypeEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(instrumentTypeEntities.size()); List<InstrumentType> instrumenttypes = new ArrayList<>(); for (InstrumentTypeEntity instrumentTypeEntity : instrumentTypeEntities) instrumenttypes.add(instrumentTypeEntity.toDomain()); page.setPagedData(instrumenttypes); return page; } InstrumentTypeJdbcRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate, JdbcTemplate jdbcTemplate); InstrumentTypeEntity create(InstrumentTypeEntity entity); InstrumentTypeEntity update(InstrumentTypeEntity entity); InstrumentTypeEntity delete(InstrumentTypeEntity entity); Pagination<InstrumentType> search(InstrumentTypeSearch domain); InstrumentTypeEntity findById(InstrumentTypeEntity entity);  }