@Test @Sql(scripts = { "/sql/clearAccountDetailKey.sql", "/sql/insertAccountDetailKey.sql" }) public void test_search_without_pagesize_offset_sortby() { AccountDetailKeySearch search = getAccountDetailKeySearch(); search.setSortBy(null); search.setPageSize(null); search.setOffset(null); Pagination<AccountDetailKey> page = (Pagination<AccountDetailKey>) accountDetailKeyJdbcRepository .search(getAccountDetailKeySearch()); assertThat(page.getPagedData().get(0).getKey()).isEqualTo("1"); }
public Pagination<AccountDetailKey> search(AccountDetailKeySearch domain) { AccountDetailKeySearchEntity accountDetailKeySearchEntity = new AccountDetailKeySearchEntity(); accountDetailKeySearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (accountDetailKeySearchEntity.getSortBy() != null && !accountDetailKeySearchEntity.getSortBy().isEmpty()) { validateSortByOrder(accountDetailKeySearchEntity.getSortBy()); validateEntityFieldName(accountDetailKeySearchEntity.getSortBy(), AccountDetailKeyEntity.class); } String orderBy = "order by key"; if (accountDetailKeySearchEntity.getSortBy() != null && !accountDetailKeySearchEntity.getSortBy().isEmpty()) { orderBy = "order by " + accountDetailKeySearchEntity.getSortBy(); } searchQuery = searchQuery.replace(":tablename", AccountDetailKeyEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (accountDetailKeySearchEntity.getTenantId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("tenantId =:tenantId"); paramValues.put("tenantId", accountDetailKeySearchEntity.getTenantId()); } if (accountDetailKeySearchEntity.getId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id =:id"); paramValues.put("id", accountDetailKeySearchEntity.getId()); } if (accountDetailKeySearchEntity.getIds() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id in(:ids) "); paramValues.put("ids", new ArrayList<String>(Arrays.asList(accountDetailKeySearchEntity.getIds().split(",")))); } if (accountDetailKeySearchEntity.getKey() != null) { if (params.length() > 0) { params.append(" and "); } params.append("key =:key"); paramValues.put("key", accountDetailKeySearchEntity.getKey()); } if (accountDetailKeySearchEntity.getAccountDetailTypeId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("accountDetailTypeId =:accountDetailType"); paramValues.put("accountDetailType", accountDetailKeySearchEntity.getAccountDetailTypeId()); } Pagination<AccountDetailKey> page = new Pagination<>(); if (accountDetailKeySearchEntity.getOffset() != null) { page.setOffset(accountDetailKeySearchEntity.getOffset()); } if (accountDetailKeySearchEntity.getPageSize() != null) { page.setPageSize(accountDetailKeySearchEntity.getPageSize()); } if (params.length() > 0) { searchQuery = searchQuery.replace(":condition", " where " + params.toString()); } else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<AccountDetailKey>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(AccountDetailKeyEntity.class); List<AccountDetailKeyEntity> accountDetailKeyEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(accountDetailKeyEntities.size()); List<AccountDetailKey> accountdetailkeys = new ArrayList<>(); for (AccountDetailKeyEntity accountDetailKeyEntity : accountDetailKeyEntities) { accountdetailkeys.add(accountDetailKeyEntity.toDomain()); } page.setPagedData(accountdetailkeys); return page; }
AccountDetailKeyJdbcRepository extends JdbcRepository { public Pagination<AccountDetailKey> search(AccountDetailKeySearch domain) { AccountDetailKeySearchEntity accountDetailKeySearchEntity = new AccountDetailKeySearchEntity(); accountDetailKeySearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (accountDetailKeySearchEntity.getSortBy() != null && !accountDetailKeySearchEntity.getSortBy().isEmpty()) { validateSortByOrder(accountDetailKeySearchEntity.getSortBy()); validateEntityFieldName(accountDetailKeySearchEntity.getSortBy(), AccountDetailKeyEntity.class); } String orderBy = "order by key"; if (accountDetailKeySearchEntity.getSortBy() != null && !accountDetailKeySearchEntity.getSortBy().isEmpty()) { orderBy = "order by " + accountDetailKeySearchEntity.getSortBy(); } searchQuery = searchQuery.replace(":tablename", AccountDetailKeyEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (accountDetailKeySearchEntity.getTenantId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("tenantId =:tenantId"); paramValues.put("tenantId", accountDetailKeySearchEntity.getTenantId()); } if (accountDetailKeySearchEntity.getId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id =:id"); paramValues.put("id", accountDetailKeySearchEntity.getId()); } if (accountDetailKeySearchEntity.getIds() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id in(:ids) "); paramValues.put("ids", new ArrayList<String>(Arrays.asList(accountDetailKeySearchEntity.getIds().split(",")))); } if (accountDetailKeySearchEntity.getKey() != null) { if (params.length() > 0) { params.append(" and "); } params.append("key =:key"); paramValues.put("key", accountDetailKeySearchEntity.getKey()); } if (accountDetailKeySearchEntity.getAccountDetailTypeId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("accountDetailTypeId =:accountDetailType"); paramValues.put("accountDetailType", accountDetailKeySearchEntity.getAccountDetailTypeId()); } Pagination<AccountDetailKey> page = new Pagination<>(); if (accountDetailKeySearchEntity.getOffset() != null) { page.setOffset(accountDetailKeySearchEntity.getOffset()); } if (accountDetailKeySearchEntity.getPageSize() != null) { page.setPageSize(accountDetailKeySearchEntity.getPageSize()); } if (params.length() > 0) { searchQuery = searchQuery.replace(":condition", " where " + params.toString()); } else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<AccountDetailKey>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(AccountDetailKeyEntity.class); List<AccountDetailKeyEntity> accountDetailKeyEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(accountDetailKeyEntities.size()); List<AccountDetailKey> accountdetailkeys = new ArrayList<>(); for (AccountDetailKeyEntity accountDetailKeyEntity : accountDetailKeyEntities) { accountdetailkeys.add(accountDetailKeyEntity.toDomain()); } page.setPagedData(accountdetailkeys); return page; } }
AccountDetailKeyJdbcRepository extends JdbcRepository { public Pagination<AccountDetailKey> search(AccountDetailKeySearch domain) { AccountDetailKeySearchEntity accountDetailKeySearchEntity = new AccountDetailKeySearchEntity(); accountDetailKeySearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (accountDetailKeySearchEntity.getSortBy() != null && !accountDetailKeySearchEntity.getSortBy().isEmpty()) { validateSortByOrder(accountDetailKeySearchEntity.getSortBy()); validateEntityFieldName(accountDetailKeySearchEntity.getSortBy(), AccountDetailKeyEntity.class); } String orderBy = "order by key"; if (accountDetailKeySearchEntity.getSortBy() != null && !accountDetailKeySearchEntity.getSortBy().isEmpty()) { orderBy = "order by " + accountDetailKeySearchEntity.getSortBy(); } searchQuery = searchQuery.replace(":tablename", AccountDetailKeyEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (accountDetailKeySearchEntity.getTenantId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("tenantId =:tenantId"); paramValues.put("tenantId", accountDetailKeySearchEntity.getTenantId()); } if (accountDetailKeySearchEntity.getId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id =:id"); paramValues.put("id", accountDetailKeySearchEntity.getId()); } if (accountDetailKeySearchEntity.getIds() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id in(:ids) "); paramValues.put("ids", new ArrayList<String>(Arrays.asList(accountDetailKeySearchEntity.getIds().split(",")))); } if (accountDetailKeySearchEntity.getKey() != null) { if (params.length() > 0) { params.append(" and "); } params.append("key =:key"); paramValues.put("key", accountDetailKeySearchEntity.getKey()); } if (accountDetailKeySearchEntity.getAccountDetailTypeId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("accountDetailTypeId =:accountDetailType"); paramValues.put("accountDetailType", accountDetailKeySearchEntity.getAccountDetailTypeId()); } Pagination<AccountDetailKey> page = new Pagination<>(); if (accountDetailKeySearchEntity.getOffset() != null) { page.setOffset(accountDetailKeySearchEntity.getOffset()); } if (accountDetailKeySearchEntity.getPageSize() != null) { page.setPageSize(accountDetailKeySearchEntity.getPageSize()); } if (params.length() > 0) { searchQuery = searchQuery.replace(":condition", " where " + params.toString()); } else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<AccountDetailKey>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(AccountDetailKeyEntity.class); List<AccountDetailKeyEntity> accountDetailKeyEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(accountDetailKeyEntities.size()); List<AccountDetailKey> accountdetailkeys = new ArrayList<>(); for (AccountDetailKeyEntity accountDetailKeyEntity : accountDetailKeyEntities) { accountdetailkeys.add(accountDetailKeyEntity.toDomain()); } page.setPagedData(accountdetailkeys); return page; } AccountDetailKeyJdbcRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate); }
AccountDetailKeyJdbcRepository extends JdbcRepository { public Pagination<AccountDetailKey> search(AccountDetailKeySearch domain) { AccountDetailKeySearchEntity accountDetailKeySearchEntity = new AccountDetailKeySearchEntity(); accountDetailKeySearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (accountDetailKeySearchEntity.getSortBy() != null && !accountDetailKeySearchEntity.getSortBy().isEmpty()) { validateSortByOrder(accountDetailKeySearchEntity.getSortBy()); validateEntityFieldName(accountDetailKeySearchEntity.getSortBy(), AccountDetailKeyEntity.class); } String orderBy = "order by key"; if (accountDetailKeySearchEntity.getSortBy() != null && !accountDetailKeySearchEntity.getSortBy().isEmpty()) { orderBy = "order by " + accountDetailKeySearchEntity.getSortBy(); } searchQuery = searchQuery.replace(":tablename", AccountDetailKeyEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (accountDetailKeySearchEntity.getTenantId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("tenantId =:tenantId"); paramValues.put("tenantId", accountDetailKeySearchEntity.getTenantId()); } if (accountDetailKeySearchEntity.getId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id =:id"); paramValues.put("id", accountDetailKeySearchEntity.getId()); } if (accountDetailKeySearchEntity.getIds() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id in(:ids) "); paramValues.put("ids", new ArrayList<String>(Arrays.asList(accountDetailKeySearchEntity.getIds().split(",")))); } if (accountDetailKeySearchEntity.getKey() != null) { if (params.length() > 0) { params.append(" and "); } params.append("key =:key"); paramValues.put("key", accountDetailKeySearchEntity.getKey()); } if (accountDetailKeySearchEntity.getAccountDetailTypeId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("accountDetailTypeId =:accountDetailType"); paramValues.put("accountDetailType", accountDetailKeySearchEntity.getAccountDetailTypeId()); } Pagination<AccountDetailKey> page = new Pagination<>(); if (accountDetailKeySearchEntity.getOffset() != null) { page.setOffset(accountDetailKeySearchEntity.getOffset()); } if (accountDetailKeySearchEntity.getPageSize() != null) { page.setPageSize(accountDetailKeySearchEntity.getPageSize()); } if (params.length() > 0) { searchQuery = searchQuery.replace(":condition", " where " + params.toString()); } else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<AccountDetailKey>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(AccountDetailKeyEntity.class); List<AccountDetailKeyEntity> accountDetailKeyEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(accountDetailKeyEntities.size()); List<AccountDetailKey> accountdetailkeys = new ArrayList<>(); for (AccountDetailKeyEntity accountDetailKeyEntity : accountDetailKeyEntities) { accountdetailkeys.add(accountDetailKeyEntity.toDomain()); } page.setPagedData(accountdetailkeys); return page; } AccountDetailKeyJdbcRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate); AccountDetailKeyEntity create(AccountDetailKeyEntity entity); AccountDetailKeyEntity update(AccountDetailKeyEntity entity); Pagination<AccountDetailKey> search(AccountDetailKeySearch domain); AccountDetailKeyEntity findById(AccountDetailKeyEntity entity); }
AccountDetailKeyJdbcRepository extends JdbcRepository { public Pagination<AccountDetailKey> search(AccountDetailKeySearch domain) { AccountDetailKeySearchEntity accountDetailKeySearchEntity = new AccountDetailKeySearchEntity(); accountDetailKeySearchEntity.toEntity(domain); String searchQuery = "select :selectfields from :tablename :condition :orderby "; Map<String, Object> paramValues = new HashMap<>(); StringBuffer params = new StringBuffer(); if (accountDetailKeySearchEntity.getSortBy() != null && !accountDetailKeySearchEntity.getSortBy().isEmpty()) { validateSortByOrder(accountDetailKeySearchEntity.getSortBy()); validateEntityFieldName(accountDetailKeySearchEntity.getSortBy(), AccountDetailKeyEntity.class); } String orderBy = "order by key"; if (accountDetailKeySearchEntity.getSortBy() != null && !accountDetailKeySearchEntity.getSortBy().isEmpty()) { orderBy = "order by " + accountDetailKeySearchEntity.getSortBy(); } searchQuery = searchQuery.replace(":tablename", AccountDetailKeyEntity.TABLE_NAME); searchQuery = searchQuery.replace(":selectfields", " * "); if (accountDetailKeySearchEntity.getTenantId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("tenantId =:tenantId"); paramValues.put("tenantId", accountDetailKeySearchEntity.getTenantId()); } if (accountDetailKeySearchEntity.getId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id =:id"); paramValues.put("id", accountDetailKeySearchEntity.getId()); } if (accountDetailKeySearchEntity.getIds() != null) { if (params.length() > 0) { params.append(" and "); } params.append("id in(:ids) "); paramValues.put("ids", new ArrayList<String>(Arrays.asList(accountDetailKeySearchEntity.getIds().split(",")))); } if (accountDetailKeySearchEntity.getKey() != null) { if (params.length() > 0) { params.append(" and "); } params.append("key =:key"); paramValues.put("key", accountDetailKeySearchEntity.getKey()); } if (accountDetailKeySearchEntity.getAccountDetailTypeId() != null) { if (params.length() > 0) { params.append(" and "); } params.append("accountDetailTypeId =:accountDetailType"); paramValues.put("accountDetailType", accountDetailKeySearchEntity.getAccountDetailTypeId()); } Pagination<AccountDetailKey> page = new Pagination<>(); if (accountDetailKeySearchEntity.getOffset() != null) { page.setOffset(accountDetailKeySearchEntity.getOffset()); } if (accountDetailKeySearchEntity.getPageSize() != null) { page.setPageSize(accountDetailKeySearchEntity.getPageSize()); } if (params.length() > 0) { searchQuery = searchQuery.replace(":condition", " where " + params.toString()); } else searchQuery = searchQuery.replace(":condition", ""); searchQuery = searchQuery.replace(":orderby", orderBy); page = (Pagination<AccountDetailKey>) getPagination(searchQuery, page, paramValues); searchQuery = searchQuery + " :pagination"; searchQuery = searchQuery.replace(":pagination", "limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize()); BeanPropertyRowMapper row = new BeanPropertyRowMapper(AccountDetailKeyEntity.class); List<AccountDetailKeyEntity> accountDetailKeyEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row); page.setTotalResults(accountDetailKeyEntities.size()); List<AccountDetailKey> accountdetailkeys = new ArrayList<>(); for (AccountDetailKeyEntity accountDetailKeyEntity : accountDetailKeyEntities) { accountdetailkeys.add(accountDetailKeyEntity.toDomain()); } page.setPagedData(accountdetailkeys); return page; } AccountDetailKeyJdbcRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate); AccountDetailKeyEntity create(AccountDetailKeyEntity entity); AccountDetailKeyEntity update(AccountDetailKeyEntity entity); Pagination<AccountDetailKey> search(AccountDetailKeySearch domain); AccountDetailKeyEntity findById(AccountDetailKeyEntity entity);  }