class BudgetReAppropriationJdbcRepository extends JdbcRepository {

    public Pagination<BudgetReAppropriation> search(final BudgetReAppropriationSearch domain) {
        final BudgetReAppropriationSearchEntity budgetReAppropriationSearchEntity = new BudgetReAppropriationSearchEntity();
        budgetReAppropriationSearchEntity.toEntity(domain);

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

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

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

        String orderBy = "order by id";
        if (budgetReAppropriationSearchEntity.getSortBy() != null
                && !budgetReAppropriationSearchEntity.getSortBy().isEmpty())
            orderBy = "order by " + budgetReAppropriationSearchEntity.getSortBy();

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

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

        // implement jdbc specfic search
        if (budgetReAppropriationSearchEntity.getTenantId() != null) {
			if (params.length() > 0) {
				params.append(" and ");
			}
			params.append("tenantId =:tenantId");
			paramValues.put("tenantId", budgetReAppropriationSearchEntity.getTenantId());
		}
        if (budgetReAppropriationSearchEntity.getId() != null) {
            if (params.length() > 0)
                params.append(" and ");
            params.append("id =:id");
            paramValues.put("id", budgetReAppropriationSearchEntity.getId());
        }
        if (budgetReAppropriationSearchEntity.getBudgetDetailId() != null) {
            if (params.length() > 0)
                params.append(" and ");
            params.append("budgetDetailid =:budgetDetail");
            paramValues.put("budgetDetail", budgetReAppropriationSearchEntity.getBudgetDetailId());
        }
        if (budgetReAppropriationSearchEntity.getAdditionAmount() != null
                && 0 != budgetReAppropriationSearchEntity.getAdditionAmount().compareTo(BigDecimal.ZERO)) {
            if (params.length() > 0)
                params.append(" and ");
            params.append("additionAmount =:additionAmount");
            paramValues.put("additionAmount", budgetReAppropriationSearchEntity.getAdditionAmount());
        }
        if (budgetReAppropriationSearchEntity.getDeductionAmount() != null
                && 0 != budgetReAppropriationSearchEntity.getDeductionAmount().compareTo(BigDecimal.ZERO)) {
            if (params.length() > 0)
                params.append(" and ");
            params.append("deductionAmount =:deductionAmount");
            paramValues.put("deductionAmount", budgetReAppropriationSearchEntity.getDeductionAmount());
        }
        if (budgetReAppropriationSearchEntity.getOriginalAdditionAmount() != null
                && 0 != budgetReAppropriationSearchEntity.getOriginalAdditionAmount().compareTo(BigDecimal.ZERO)) {
            if (params.length() > 0)
                params.append(" and ");
            params.append("originalAdditionAmount =:originalAdditionAmount");
            paramValues.put("originalAdditionAmount", budgetReAppropriationSearchEntity.getOriginalAdditionAmount());
        }
        if (budgetReAppropriationSearchEntity.getOriginalDeductionAmount() != null
                && 0 != budgetReAppropriationSearchEntity.getOriginalDeductionAmount().compareTo(BigDecimal.ZERO)) {
            if (params.length() > 0)
                params.append(" and ");
            params.append("originalDeductionAmount =:originalDeductionAmount");
            paramValues.put("originalDeductionAmount", budgetReAppropriationSearchEntity.getOriginalDeductionAmount());
        }
        if (budgetReAppropriationSearchEntity.getAnticipatoryAmount() != null
                && 0 != budgetReAppropriationSearchEntity.getAnticipatoryAmount().compareTo(BigDecimal.ZERO)) {
            if (params.length() > 0)
                params.append(" and ");
            params.append("anticipatoryAmount =:anticipatoryAmount");
            paramValues.put("anticipatoryAmount", budgetReAppropriationSearchEntity.getAnticipatoryAmount());
        }
        if (budgetReAppropriationSearchEntity.getStatusId() != null) {
            if (params.length() > 0)
                params.append(" and ");
            params.append("statusid =:status");
            paramValues.put("status", budgetReAppropriationSearchEntity.getStatusId());
        }
        if (budgetReAppropriationSearchEntity.getAsOnDate() != null) {
            if (params.length() > 0)
                params.append(" and ");
            params.append("asOnDate =:asOnDate");
            paramValues.put("asOnDate", budgetReAppropriationSearchEntity.getAsOnDate());
        }

        Pagination<BudgetReAppropriation> page = new Pagination<>();
        if (budgetReAppropriationSearchEntity.getOffset() != null)
            page.setOffset(budgetReAppropriationSearchEntity.getOffset());
        if (budgetReAppropriationSearchEntity.getPageSize() != null)
            page.setPageSize(budgetReAppropriationSearchEntity.getPageSize());

        if (params.length() > 0)
            searchQuery = searchQuery.replace(":condition", " where " + params.toString());
        else
            searchQuery = searchQuery.replace(":condition", "");

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

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

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

        final BeanPropertyRowMapper row = new BeanPropertyRowMapper(BudgetReAppropriationEntity.class);

        final List<BudgetReAppropriationEntity> budgetReAppropriationEntities = namedParameterJdbcTemplate
                .query(searchQuery.toString(), paramValues, row);

        page.setTotalResults(budgetReAppropriationEntities.size());

        final List<BudgetReAppropriation> budgetreappropriations = new ArrayList<BudgetReAppropriation>();
        for (final BudgetReAppropriationEntity budgetReAppropriationEntity : budgetReAppropriationEntities)
            budgetreappropriations.add(budgetReAppropriationEntity.toDomain());
        page.setPagedData(budgetreappropriations);

        return page;
    }

    public  BudgetReAppropriationJdbcRepository(final NamedParameterJdbcTemplate namedParameterJdbcTemplate, JdbcTemplate jdbcTemplate);

}