@Test @Sql(scripts = { "/sql/clearAccountCodePurpose.sql", "/sql/insertAccountCodePurposeData.sql" }) public void test_search_without_pagesize_offset_sortby() { AccountCodePurposeSearch search = getAccountCodePurposeSearch(); search.setSortBy(null); search.setPageSize(null); search.setOffset(null); Pagination<AccountCodePurpose> page = (Pagination<AccountCodePurpose>) accountCodePurposeJdbcRepository .search(getAccountCodePurposeSearch()); assertThat(page.getPagedData().get(0).getName()).isEqualTo("name"); }
public Pagination<AccountCodePurpose> search(AccountCodePurposeSearch domain) { AccountCodePurposeSearchEntity accountCodePurposeSearchEntity = new AccountCodePurposeSearchEntity(); accountCodePurposeSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (accountCodePurposeSearchEntity.getSortBy() != null && !accountCodePurposeSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(accountCodePurposeSearchEntity.getSortBy()); validateEntityFieldName(accountCodePurposeSearchEntity.getSortBy(), AccountCodePurposeEntity.class); } String orderBy = "order by name"; if (accountCodePurposeSearchEntity.getSortBy() != null && !accountCodePurposeSearchEntity.getSortBy().isEmpty()) { orderBy = "order by " + accountCodePurposeSearchEntity.getSortBy(); } searchQuery = searchQuery.replace(":tablename", AccountCodePurposeEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (accountCodePurposeSearchEntity.getTenantId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("tenantId =:tenantId"); paramValues.put("tenantId", accountCodePurposeSearchEntity.getTenantId()); } if (accountCodePurposeSearchEntity.getId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id =:id"); paramValues.put("id", accountCodePurposeSearchEntity.getId()); } if (accountCodePurposeSearchEntity.getIds() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id in(:ids) "); paramValues.put("ids", new ArrayList<String>(Arrays.asList(accountCodePurposeSearchEntity.getIds().split(",")))); } if (accountCodePurposeSearchEntity.getName() != null) { if (params.length() > 0) { params.append(" and "); } params.append("name =:name"); paramValues.put("name", accountCodePurposeSearchEntity.getName()); } Pagination<AccountCodePurpose> page = new Pagination<>(); if (accountCodePurposeSearchEntity.getOffset() != null) { page.setOffset(accountCodePurposeSearchEntity.getOffset()); } if (accountCodePurposeSearchEntity.getPageSize() != null) { page.setPageSize(accountCodePurposeSearchEntity.getPageSize()); } if (params.length() > 0) { searchQuery = searchQuery.replace(":condition", " where " + params.toString()); } else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<AccountCodePurpose>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(AccountCodePurposeEntity.class); List<AccountCodePurposeEntity> accountCodePurposeEntities = namedParameterJdbcTemplate .query(searchQuery.toString(), paramValues, row); page.setTotalResults(accountCodePurposeEntities.size()); List<AccountCodePurpose> accountcodepurposes = new ArrayList<>(); for (AccountCodePurposeEntity accountCodePurposeEntity : accountCodePurposeEntities) { accountcodepurposes.add(accountCodePurposeEntity.toDomain()); } page.setPagedData(accountcodepurposes); return page; }
AccountCodePurposeJdbcRepository extends JdbcRepository { public Pagination<AccountCodePurpose> search(AccountCodePurposeSearch domain) { AccountCodePurposeSearchEntity accountCodePurposeSearchEntity = new AccountCodePurposeSearchEntity(); accountCodePurposeSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (accountCodePurposeSearchEntity.getSortBy() != null && !accountCodePurposeSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(accountCodePurposeSearchEntity.getSortBy()); validateEntityFieldName(accountCodePurposeSearchEntity.getSortBy(), AccountCodePurposeEntity.class); } String orderBy = "order by name"; if (accountCodePurposeSearchEntity.getSortBy() != null && !accountCodePurposeSearchEntity.getSortBy().isEmpty()) { orderBy = "order by " + accountCodePurposeSearchEntity.getSortBy(); } searchQuery = searchQuery.replace(":tablename", AccountCodePurposeEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (accountCodePurposeSearchEntity.getTenantId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("tenantId =:tenantId"); paramValues.put("tenantId", accountCodePurposeSearchEntity.getTenantId()); } if (accountCodePurposeSearchEntity.getId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id =:id"); paramValues.put("id", accountCodePurposeSearchEntity.getId()); } if (accountCodePurposeSearchEntity.getIds() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id in(:ids) "); paramValues.put("ids", new ArrayList<String>(Arrays.asList(accountCodePurposeSearchEntity.getIds().split(",")))); } if (accountCodePurposeSearchEntity.getName() != null) { if (params.length() > 0) { params.append(" and "); } params.append("name =:name"); paramValues.put("name", accountCodePurposeSearchEntity.getName()); } Pagination<AccountCodePurpose> page = new Pagination<>(); if (accountCodePurposeSearchEntity.getOffset() != null) { page.setOffset(accountCodePurposeSearchEntity.getOffset()); } if (accountCodePurposeSearchEntity.getPageSize() != null) { page.setPageSize(accountCodePurposeSearchEntity.getPageSize()); } if (params.length() > 0) { searchQuery = searchQuery.replace(":condition", " where " + params.toString()); } else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<AccountCodePurpose>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(AccountCodePurposeEntity.class); List<AccountCodePurposeEntity> accountCodePurposeEntities = namedParameterJdbcTemplate .query(searchQuery.toString(), paramValues, row); page.setTotalResults(accountCodePurposeEntities.size()); List<AccountCodePurpose> accountcodepurposes = new ArrayList<>(); for (AccountCodePurposeEntity accountCodePurposeEntity : accountCodePurposeEntities) { accountcodepurposes.add(accountCodePurposeEntity.toDomain()); } page.setPagedData(accountcodepurposes); return page; } }
AccountCodePurposeJdbcRepository extends JdbcRepository { public Pagination<AccountCodePurpose> search(AccountCodePurposeSearch domain) { AccountCodePurposeSearchEntity accountCodePurposeSearchEntity = new AccountCodePurposeSearchEntity(); accountCodePurposeSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (accountCodePurposeSearchEntity.getSortBy() != null && !accountCodePurposeSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(accountCodePurposeSearchEntity.getSortBy()); validateEntityFieldName(accountCodePurposeSearchEntity.getSortBy(), AccountCodePurposeEntity.class); } String orderBy = "order by name"; if (accountCodePurposeSearchEntity.getSortBy() != null && !accountCodePurposeSearchEntity.getSortBy().isEmpty()) { orderBy = "order by " + accountCodePurposeSearchEntity.getSortBy(); } searchQuery = searchQuery.replace(":tablename", AccountCodePurposeEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (accountCodePurposeSearchEntity.getTenantId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("tenantId =:tenantId"); paramValues.put("tenantId", accountCodePurposeSearchEntity.getTenantId()); } if (accountCodePurposeSearchEntity.getId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id =:id"); paramValues.put("id", accountCodePurposeSearchEntity.getId()); } if (accountCodePurposeSearchEntity.getIds() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id in(:ids) "); paramValues.put("ids", new ArrayList<String>(Arrays.asList(accountCodePurposeSearchEntity.getIds().split(",")))); } if (accountCodePurposeSearchEntity.getName() != null) { if (params.length() > 0) { params.append(" and "); } params.append("name =:name"); paramValues.put("name", accountCodePurposeSearchEntity.getName()); } Pagination<AccountCodePurpose> page = new Pagination<>(); if (accountCodePurposeSearchEntity.getOffset() != null) { page.setOffset(accountCodePurposeSearchEntity.getOffset()); } if (accountCodePurposeSearchEntity.getPageSize() != null) { page.setPageSize(accountCodePurposeSearchEntity.getPageSize()); } if (params.length() > 0) { searchQuery = searchQuery.replace(":condition", " where " + params.toString()); } else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<AccountCodePurpose>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(AccountCodePurposeEntity.class); List<AccountCodePurposeEntity> accountCodePurposeEntities = namedParameterJdbcTemplate .query(searchQuery.toString(), paramValues, row); page.setTotalResults(accountCodePurposeEntities.size()); List<AccountCodePurpose> accountcodepurposes = new ArrayList<>(); for (AccountCodePurposeEntity accountCodePurposeEntity : accountCodePurposeEntities) { accountcodepurposes.add(accountCodePurposeEntity.toDomain()); } page.setPagedData(accountcodepurposes); return page; } AccountCodePurposeJdbcRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate); }
AccountCodePurposeJdbcRepository extends JdbcRepository { public Pagination<AccountCodePurpose> search(AccountCodePurposeSearch domain) { AccountCodePurposeSearchEntity accountCodePurposeSearchEntity = new AccountCodePurposeSearchEntity(); accountCodePurposeSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (accountCodePurposeSearchEntity.getSortBy() != null && !accountCodePurposeSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(accountCodePurposeSearchEntity.getSortBy()); validateEntityFieldName(accountCodePurposeSearchEntity.getSortBy(), AccountCodePurposeEntity.class); } String orderBy = "order by name"; if (accountCodePurposeSearchEntity.getSortBy() != null && !accountCodePurposeSearchEntity.getSortBy().isEmpty()) { orderBy = "order by " + accountCodePurposeSearchEntity.getSortBy(); } searchQuery = searchQuery.replace(":tablename", AccountCodePurposeEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (accountCodePurposeSearchEntity.getTenantId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("tenantId =:tenantId"); paramValues.put("tenantId", accountCodePurposeSearchEntity.getTenantId()); } if (accountCodePurposeSearchEntity.getId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id =:id"); paramValues.put("id", accountCodePurposeSearchEntity.getId()); } if (accountCodePurposeSearchEntity.getIds() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id in(:ids) "); paramValues.put("ids", new ArrayList<String>(Arrays.asList(accountCodePurposeSearchEntity.getIds().split(",")))); } if (accountCodePurposeSearchEntity.getName() != null) { if (params.length() > 0) { params.append(" and "); } params.append("name =:name"); paramValues.put("name", accountCodePurposeSearchEntity.getName()); } Pagination<AccountCodePurpose> page = new Pagination<>(); if (accountCodePurposeSearchEntity.getOffset() != null) { page.setOffset(accountCodePurposeSearchEntity.getOffset()); } if (accountCodePurposeSearchEntity.getPageSize() != null) { page.setPageSize(accountCodePurposeSearchEntity.getPageSize()); } if (params.length() > 0) { searchQuery = searchQuery.replace(":condition", " where " + params.toString()); } else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<AccountCodePurpose>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(AccountCodePurposeEntity.class); List<AccountCodePurposeEntity> accountCodePurposeEntities = namedParameterJdbcTemplate .query(searchQuery.toString(), paramValues, row); page.setTotalResults(accountCodePurposeEntities.size()); List<AccountCodePurpose> accountcodepurposes = new ArrayList<>(); for (AccountCodePurposeEntity accountCodePurposeEntity : accountCodePurposeEntities) { accountcodepurposes.add(accountCodePurposeEntity.toDomain()); } page.setPagedData(accountcodepurposes); return page; } AccountCodePurposeJdbcRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate); AccountCodePurposeEntity create(AccountCodePurposeEntity entity); AccountCodePurposeEntity update(AccountCodePurposeEntity entity); Pagination<AccountCodePurpose> search(AccountCodePurposeSearch domain); AccountCodePurposeEntity findById(AccountCodePurposeEntity entity); Boolean uniqueCheck(String fieldName, AccountCodePurposeEntity accountCodePurpose); }
AccountCodePurposeJdbcRepository extends JdbcRepository { public Pagination<AccountCodePurpose> search(AccountCodePurposeSearch domain) { AccountCodePurposeSearchEntity accountCodePurposeSearchEntity = new AccountCodePurposeSearchEntity(); accountCodePurposeSearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (accountCodePurposeSearchEntity.getSortBy() != null && !accountCodePurposeSearchEntity.getSortBy().isEmpty()) { validateSortByOrder(accountCodePurposeSearchEntity.getSortBy()); validateEntityFieldName(accountCodePurposeSearchEntity.getSortBy(), AccountCodePurposeEntity.class); } String orderBy = "order by name"; if (accountCodePurposeSearchEntity.getSortBy() != null && !accountCodePurposeSearchEntity.getSortBy().isEmpty()) { orderBy = "order by " + accountCodePurposeSearchEntity.getSortBy(); } searchQuery = searchQuery.replace(":tablename", AccountCodePurposeEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (accountCodePurposeSearchEntity.getTenantId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("tenantId =:tenantId"); paramValues.put("tenantId", accountCodePurposeSearchEntity.getTenantId()); } if (accountCodePurposeSearchEntity.getId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id =:id"); paramValues.put("id", accountCodePurposeSearchEntity.getId()); } if (accountCodePurposeSearchEntity.getIds() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id in(:ids) "); paramValues.put("ids", new ArrayList<String>(Arrays.asList(accountCodePurposeSearchEntity.getIds().split(",")))); } if (accountCodePurposeSearchEntity.getName() != null) { if (params.length() > 0) { params.append(" and "); } params.append("name =:name"); paramValues.put("name", accountCodePurposeSearchEntity.getName()); } Pagination<AccountCodePurpose> page = new Pagination<>(); if (accountCodePurposeSearchEntity.getOffset() != null) { page.setOffset(accountCodePurposeSearchEntity.getOffset()); } if (accountCodePurposeSearchEntity.getPageSize() != null) { page.setPageSize(accountCodePurposeSearchEntity.getPageSize()); } if (params.length() > 0) { searchQuery = searchQuery.replace(":condition", " where " + params.toString()); } else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<AccountCodePurpose>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(AccountCodePurposeEntity.class); List<AccountCodePurposeEntity> accountCodePurposeEntities = namedParameterJdbcTemplate .query(searchQuery.toString(), paramValues, row); page.setTotalResults(accountCodePurposeEntities.size()); List<AccountCodePurpose> accountcodepurposes = new ArrayList<>(); for (AccountCodePurposeEntity accountCodePurposeEntity : accountCodePurposeEntities) { accountcodepurposes.add(accountCodePurposeEntity.toDomain()); } page.setPagedData(accountcodepurposes); return page; } AccountCodePurposeJdbcRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate); AccountCodePurposeEntity create(AccountCodePurposeEntity entity); AccountCodePurposeEntity update(AccountCodePurposeEntity entity); Pagination<AccountCodePurpose> search(AccountCodePurposeSearch domain); AccountCodePurposeEntity findById(AccountCodePurposeEntity entity); Boolean uniqueCheck(String fieldName, AccountCodePurposeEntity accountCodePurpose);  }