class 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", " * ");

		// implement jdbc specfic search
	        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;
	}

	public  AccountCodePurposeJdbcRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate);

}