@Test @Sql(scripts = { "/sql/clearBank.sql", "/sql/insertBank.sql" }) public void test_search_without_pagesize_offset_sortby() { BankSearch search = getBankSearch(); search.setSortBy(null); search.setPageSize(null); search.setOffset(null); Pagination<Bank> page = (Pagination<Bank>) bankJdbcRepository.search(getBankSearch()); assertThat(page.getPagedData().get(0).getName()).isEqualTo("name"); assertThat(page.getPagedData().get(0).getCode()).isEqualTo("code"); assertThat(page.getPagedData().get(0).getActive()).isEqualTo(true); }
public Pagination<Bank> search(BankSearch domain) { BankSearchEntity bankSearchEntity = new BankSearchEntity(); bankSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (bankSearchEntity.getSortBy() != null && !bankSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(bankSearchEntity.getSortBy()); validateEntityFieldName(bankSearchEntity.getSortBy(), BankEntity.class); } String orderBy = "order by name"; if (bankSearchEntity.getSortBy() != null && !bankSearchEntity.getSortBy().isEmpty()) { orderBy = "order by " + bankSearchEntity.getSortBy(); } searchQuery = searchQuery.replace(":tablename", BankEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (bankSearchEntity.getTenantId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("tenantId =:tenantId"); paramValues.put("tenantId", bankSearchEntity.getTenantId()); } if (bankSearchEntity.getId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id =:id"); paramValues.put("id", bankSearchEntity.getId()); } if (bankSearchEntity.getIds() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id in(:ids) "); paramValues.put("ids", new ArrayList<String>(Arrays.asList(bankSearchEntity.getIds().split(",")))); } if (bankSearchEntity.getCode() != null) { if (params.length() > 0) { params.append(" and "); } params.append("code =:code"); paramValues.put("code", bankSearchEntity.getCode()); } if (bankSearchEntity.getName() != null) { if (params.length() > 0) { params.append(" and "); } params.append("name =:name"); paramValues.put("name", bankSearchEntity.getName()); } if (bankSearchEntity.getDescription() != null) { if (params.length() > 0) { params.append(" and "); } params.append("description =:description"); paramValues.put("description", bankSearchEntity.getDescription()); } if (bankSearchEntity.getActive() != null) { if (params.length() > 0) { params.append(" and "); } params.append("active =:active"); paramValues.put("active", bankSearchEntity.getActive()); } if (bankSearchEntity.getType() != null) { if (params.length() > 0) { params.append(" and "); } params.append("type =:type"); paramValues.put("type", bankSearchEntity.getType()); } Pagination<Bank> page = new Pagination<>(); if (bankSearchEntity.getOffset() != null) { page.setOffset(bankSearchEntity.getOffset()); } if (bankSearchEntity.getPageSize() != null) { page.setPageSize(bankSearchEntity.getPageSize()); } if (params.length() > 0) { searchQuery = searchQuery.replace(":condition", " where " + params.toString()); } else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<Bank>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(BankEntity.class); List<BankEntity> bankEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(bankEntities.size()); List<Bank> banks = new ArrayList<>(); for (BankEntity bankEntity : bankEntities) { banks.add(bankEntity.toDomain()); } page.setPagedData(banks); return page; }
BankJdbcRepository extends JdbcRepository { public Pagination<Bank> search(BankSearch domain) { BankSearchEntity bankSearchEntity = new BankSearchEntity(); bankSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (bankSearchEntity.getSortBy() != null && !bankSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(bankSearchEntity.getSortBy()); validateEntityFieldName(bankSearchEntity.getSortBy(), BankEntity.class); } String orderBy = "order by name"; if (bankSearchEntity.getSortBy() != null && !bankSearchEntity.getSortBy().isEmpty()) { orderBy = "order by " + bankSearchEntity.getSortBy(); } searchQuery = searchQuery.replace(":tablename", BankEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (bankSearchEntity.getTenantId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("tenantId =:tenantId"); paramValues.put("tenantId", bankSearchEntity.getTenantId()); } if (bankSearchEntity.getId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id =:id"); paramValues.put("id", bankSearchEntity.getId()); } if (bankSearchEntity.getIds() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id in(:ids) "); paramValues.put("ids", new ArrayList<String>(Arrays.asList(bankSearchEntity.getIds().split(",")))); } if (bankSearchEntity.getCode() != null) { if (params.length() > 0) { params.append(" and "); } params.append("code =:code"); paramValues.put("code", bankSearchEntity.getCode()); } if (bankSearchEntity.getName() != null) { if (params.length() > 0) { params.append(" and "); } params.append("name =:name"); paramValues.put("name", bankSearchEntity.getName()); } if (bankSearchEntity.getDescription() != null) { if (params.length() > 0) { params.append(" and "); } params.append("description =:description"); paramValues.put("description", bankSearchEntity.getDescription()); } if (bankSearchEntity.getActive() != null) { if (params.length() > 0) { params.append(" and "); } params.append("active =:active"); paramValues.put("active", bankSearchEntity.getActive()); } if (bankSearchEntity.getType() != null) { if (params.length() > 0) { params.append(" and "); } params.append("type =:type"); paramValues.put("type", bankSearchEntity.getType()); } Pagination<Bank> page = new Pagination<>(); if (bankSearchEntity.getOffset() != null) { page.setOffset(bankSearchEntity.getOffset()); } if (bankSearchEntity.getPageSize() != null) { page.setPageSize(bankSearchEntity.getPageSize()); } if (params.length() > 0) { searchQuery = searchQuery.replace(":condition", " where " + params.toString()); } else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<Bank>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(BankEntity.class); List<BankEntity> bankEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(bankEntities.size()); List<Bank> banks = new ArrayList<>(); for (BankEntity bankEntity : bankEntities) { banks.add(bankEntity.toDomain()); } page.setPagedData(banks); return page; } }
BankJdbcRepository extends JdbcRepository { public Pagination<Bank> search(BankSearch domain) { BankSearchEntity bankSearchEntity = new BankSearchEntity(); bankSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (bankSearchEntity.getSortBy() != null && !bankSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(bankSearchEntity.getSortBy()); validateEntityFieldName(bankSearchEntity.getSortBy(), BankEntity.class); } String orderBy = "order by name"; if (bankSearchEntity.getSortBy() != null && !bankSearchEntity.getSortBy().isEmpty()) { orderBy = "order by " + bankSearchEntity.getSortBy(); } searchQuery = searchQuery.replace(":tablename", BankEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (bankSearchEntity.getTenantId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("tenantId =:tenantId"); paramValues.put("tenantId", bankSearchEntity.getTenantId()); } if (bankSearchEntity.getId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id =:id"); paramValues.put("id", bankSearchEntity.getId()); } if (bankSearchEntity.getIds() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id in(:ids) "); paramValues.put("ids", new ArrayList<String>(Arrays.asList(bankSearchEntity.getIds().split(",")))); } if (bankSearchEntity.getCode() != null) { if (params.length() > 0) { params.append(" and "); } params.append("code =:code"); paramValues.put("code", bankSearchEntity.getCode()); } if (bankSearchEntity.getName() != null) { if (params.length() > 0) { params.append(" and "); } params.append("name =:name"); paramValues.put("name", bankSearchEntity.getName()); } if (bankSearchEntity.getDescription() != null) { if (params.length() > 0) { params.append(" and "); } params.append("description =:description"); paramValues.put("description", bankSearchEntity.getDescription()); } if (bankSearchEntity.getActive() != null) { if (params.length() > 0) { params.append(" and "); } params.append("active =:active"); paramValues.put("active", bankSearchEntity.getActive()); } if (bankSearchEntity.getType() != null) { if (params.length() > 0) { params.append(" and "); } params.append("type =:type"); paramValues.put("type", bankSearchEntity.getType()); } Pagination<Bank> page = new Pagination<>(); if (bankSearchEntity.getOffset() != null) { page.setOffset(bankSearchEntity.getOffset()); } if (bankSearchEntity.getPageSize() != null) { page.setPageSize(bankSearchEntity.getPageSize()); } if (params.length() > 0) { searchQuery = searchQuery.replace(":condition", " where " + params.toString()); } else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<Bank>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(BankEntity.class); List<BankEntity> bankEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(bankEntities.size()); List<Bank> banks = new ArrayList<>(); for (BankEntity bankEntity : bankEntities) { banks.add(bankEntity.toDomain()); } page.setPagedData(banks); return page; } BankJdbcRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate); }
BankJdbcRepository extends JdbcRepository { public Pagination<Bank> search(BankSearch domain) { BankSearchEntity bankSearchEntity = new BankSearchEntity(); bankSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (bankSearchEntity.getSortBy() != null && !bankSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(bankSearchEntity.getSortBy()); validateEntityFieldName(bankSearchEntity.getSortBy(), BankEntity.class); } String orderBy = "order by name"; if (bankSearchEntity.getSortBy() != null && !bankSearchEntity.getSortBy().isEmpty()) { orderBy = "order by " + bankSearchEntity.getSortBy(); } searchQuery = searchQuery.replace(":tablename", BankEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (bankSearchEntity.getTenantId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("tenantId =:tenantId"); paramValues.put("tenantId", bankSearchEntity.getTenantId()); } if (bankSearchEntity.getId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id =:id"); paramValues.put("id", bankSearchEntity.getId()); } if (bankSearchEntity.getIds() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id in(:ids) "); paramValues.put("ids", new ArrayList<String>(Arrays.asList(bankSearchEntity.getIds().split(",")))); } if (bankSearchEntity.getCode() != null) { if (params.length() > 0) { params.append(" and "); } params.append("code =:code"); paramValues.put("code", bankSearchEntity.getCode()); } if (bankSearchEntity.getName() != null) { if (params.length() > 0) { params.append(" and "); } params.append("name =:name"); paramValues.put("name", bankSearchEntity.getName()); } if (bankSearchEntity.getDescription() != null) { if (params.length() > 0) { params.append(" and "); } params.append("description =:description"); paramValues.put("description", bankSearchEntity.getDescription()); } if (bankSearchEntity.getActive() != null) { if (params.length() > 0) { params.append(" and "); } params.append("active =:active"); paramValues.put("active", bankSearchEntity.getActive()); } if (bankSearchEntity.getType() != null) { if (params.length() > 0) { params.append(" and "); } params.append("type =:type"); paramValues.put("type", bankSearchEntity.getType()); } Pagination<Bank> page = new Pagination<>(); if (bankSearchEntity.getOffset() != null) { page.setOffset(bankSearchEntity.getOffset()); } if (bankSearchEntity.getPageSize() != null) { page.setPageSize(bankSearchEntity.getPageSize()); } if (params.length() > 0) { searchQuery = searchQuery.replace(":condition", " where " + params.toString()); } else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<Bank>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(BankEntity.class); List<BankEntity> bankEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(bankEntities.size()); List<Bank> banks = new ArrayList<>(); for (BankEntity bankEntity : bankEntities) { banks.add(bankEntity.toDomain()); } page.setPagedData(banks); return page; } BankJdbcRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate); BankEntity create(BankEntity entity); BankEntity update(BankEntity entity); Pagination<Bank> search(BankSearch domain); BankEntity findById(BankEntity entity); }
BankJdbcRepository extends JdbcRepository { public Pagination<Bank> search(BankSearch domain) { BankSearchEntity bankSearchEntity = new BankSearchEntity(); bankSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (bankSearchEntity.getSortBy() != null && !bankSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(bankSearchEntity.getSortBy()); validateEntityFieldName(bankSearchEntity.getSortBy(), BankEntity.class); } String orderBy = "order by name"; if (bankSearchEntity.getSortBy() != null && !bankSearchEntity.getSortBy().isEmpty()) { orderBy = "order by " + bankSearchEntity.getSortBy(); } searchQuery = searchQuery.replace(":tablename", BankEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (bankSearchEntity.getTenantId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("tenantId =:tenantId"); paramValues.put("tenantId", bankSearchEntity.getTenantId()); } if (bankSearchEntity.getId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id =:id"); paramValues.put("id", bankSearchEntity.getId()); } if (bankSearchEntity.getIds() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id in(:ids) "); paramValues.put("ids", new ArrayList<String>(Arrays.asList(bankSearchEntity.getIds().split(",")))); } if (bankSearchEntity.getCode() != null) { if (params.length() > 0) { params.append(" and "); } params.append("code =:code"); paramValues.put("code", bankSearchEntity.getCode()); } if (bankSearchEntity.getName() != null) { if (params.length() > 0) { params.append(" and "); } params.append("name =:name"); paramValues.put("name", bankSearchEntity.getName()); } if (bankSearchEntity.getDescription() != null) { if (params.length() > 0) { params.append(" and "); } params.append("description =:description"); paramValues.put("description", bankSearchEntity.getDescription()); } if (bankSearchEntity.getActive() != null) { if (params.length() > 0) { params.append(" and "); } params.append("active =:active"); paramValues.put("active", bankSearchEntity.getActive()); } if (bankSearchEntity.getType() != null) { if (params.length() > 0) { params.append(" and "); } params.append("type =:type"); paramValues.put("type", bankSearchEntity.getType()); } Pagination<Bank> page = new Pagination<>(); if (bankSearchEntity.getOffset() != null) { page.setOffset(bankSearchEntity.getOffset()); } if (bankSearchEntity.getPageSize() != null) { page.setPageSize(bankSearchEntity.getPageSize()); } if (params.length() > 0) { searchQuery = searchQuery.replace(":condition", " where " + params.toString()); } else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<Bank>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(BankEntity.class); List<BankEntity> bankEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(bankEntities.size()); List<Bank> banks = new ArrayList<>(); for (BankEntity bankEntity : bankEntities) { banks.add(bankEntity.toDomain()); } page.setPagedData(banks); return page; } BankJdbcRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate); BankEntity create(BankEntity entity); BankEntity update(BankEntity entity); Pagination<Bank> search(BankSearch domain); BankEntity findById(BankEntity entity);  }