class InstrumentTypeJdbcRepository extends JdbcRepository {

    public Pagination<InstrumentType> search(InstrumentTypeSearch domain) {
        InstrumentTypeSearchEntity instrumentTypeSearchEntity = new InstrumentTypeSearchEntity();
        instrumentTypeSearchEntity.toEntity(domain);

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

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

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

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

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

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

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

        if (instrumentTypeSearchEntity.getIds() != null) {
            if (params.length() > 0)
                params.append(" and ");
            params.append("id in (:ids)");
            paramValues.put("ids", instrumentTypeSearchEntity.getIds());
        }

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

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

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

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

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

        BeanPropertyRowMapper row = new BeanPropertyRowMapper(InstrumentTypeEntity.class);

        /*
         * searchQuery= "select * from egf_instrumenttype egf_instrumenttype, egf_instrumenttypeproperty properties where " +
         * "egf_instrumenttype.name=properties.instrumentTypeId";
         */

        List<InstrumentTypeEntity> instrumentTypeEntities = namedParameterJdbcTemplate.query(searchQuery.toString(),
                paramValues, row);

        page.setTotalResults(instrumentTypeEntities.size());

        List<InstrumentType> instrumenttypes = new ArrayList<>();
        for (InstrumentTypeEntity instrumentTypeEntity : instrumentTypeEntities)
            instrumenttypes.add(instrumentTypeEntity.toDomain());
        page.setPagedData(instrumenttypes);

        return page;
    }

    public  InstrumentTypeJdbcRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate, JdbcTemplate jdbcTemplate);

}