class FundJdbcRepository extends JdbcRepository {

	public Pagination<Fund> search(FundSearch domain) {
		FundSearchEntity fundSearchEntity = new FundSearchEntity();
		fundSearchEntity.toEntity(domain);

		String searchQuery = "select :selectfields from :tablename :condition  :orderby   ";

		Map<String, Object> paramValues = new HashMap<>();
		StringBuffer params = new StringBuffer();

		if (fundSearchEntity.getSortBy() != null && !fundSearchEntity.getSortBy().isEmpty()) {
			validateSortByOrder(fundSearchEntity.getSortBy());
			validateEntityFieldName(fundSearchEntity.getSortBy(), FundEntity.class);
		}

		String orderBy = "order by name";
		if (fundSearchEntity.getSortBy() != null && !fundSearchEntity.getSortBy().isEmpty()) {
			orderBy = "order by " + fundSearchEntity.getSortBy();
		}

		searchQuery = searchQuery.replace(":tablename", FundEntity.TABLE_NAME);

		searchQuery = searchQuery.replace(":selectfields", " * ");

		// implement jdbc specfic search
		if (fundSearchEntity.getTenantId() != null) {
			if (params.length() > 0) {
				params.append(" and ");
			}
			params.append("tenantId =:tenantId");
			paramValues.put("tenantId", fundSearchEntity.getTenantId());
		}
		if (fundSearchEntity.getId() != null) {
			if (params.length() > 0) {
				params.append(" and ");
			}
			params.append("id =:id");
			paramValues.put("id", fundSearchEntity.getId());
		}
		if (fundSearchEntity.getCode() != null) {
			if (params.length() > 0) {
				params.append(" and ");
			}
			params.append("code =:code");
			paramValues.put("code", fundSearchEntity.getCode());
		}
		if (fundSearchEntity.getName() != null) {
			if (params.length() > 0) {
				params.append(" and ");
			}
			params.append("name =:name");
			paramValues.put("name", fundSearchEntity.getName());
		}
		if (fundSearchEntity.getIdentifier() != null) {
			if (params.length() > 0) {
				params.append(" and ");
			}
			params.append("description =:description");
			paramValues.put("description", fundSearchEntity.getIdentifier());
		}
		if (fundSearchEntity.getActive() != null) {
			if (params.length() > 0) {
				params.append(" and ");
			}
			params.append("active =:active");
			paramValues.put("active", fundSearchEntity.getActive());
		}
		if (fundSearchEntity.getLevel() != null) {
			if (params.length() > 0) {
				params.append(" and ");
			}
			params.append("type =:type");
			paramValues.put("type", fundSearchEntity.getLevel());
		}

		Pagination<Fund> page = new Pagination<>();
		if (fundSearchEntity.getOffset() != null) {
			page.setOffset(fundSearchEntity.getOffset());
		}
		if (fundSearchEntity.getPageSize() != null) {
			page.setPageSize(fundSearchEntity.getPageSize());
		}

		if (params.length() > 0) {

			searchQuery = searchQuery.replace(":condition", " where " + params.toString());

		} else

			searchQuery = searchQuery.replace(":condition", "");

		searchQuery = searchQuery.replace(":orderby", orderBy);

		page = (Pagination<Fund>) getPagination(searchQuery, page, paramValues);
		searchQuery = searchQuery + " :pagination";

		searchQuery = searchQuery.replace(":pagination",
				"limit " + page.getPageSize() + " offset " + page.getOffset() * page.getPageSize());

		BeanPropertyRowMapper row = new BeanPropertyRowMapper(FundEntity.class);

		List<FundEntity> fundEntities = namedParameterJdbcTemplate.query(searchQuery.toString(), paramValues, row);

		page.setTotalResults(fundEntities.size());

		List<Fund> funds = new ArrayList<>();
		for (FundEntity fundEntity : fundEntities) {

			funds.add(fundEntity.toDomain());
		}
		page.setPagedData(funds);

		return page;
	}

	public  FundJdbcRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate);

}