class AccountEntityJdbcRepository extends JdbcRepository {

	public Pagination<AccountEntity> search(AccountEntitySearch domain) {
		AccountEntitySearchEntity accountEntitySearchEntity = new AccountEntitySearchEntity();
		accountEntitySearchEntity.toEntity(domain);

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

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

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

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

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

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

		// implement jdbc specfic search
		if (accountEntitySearchEntity.getTenantId() != null) {
                    if (params.length() > 0) {
                        params.append(" and ");
                    }
                    params.append("tenantId =:tenantId");
                    paramValues.put("tenantId", accountEntitySearchEntity.getTenantId());
                }
		if (accountEntitySearchEntity.getId() != null) {
			if (params.length() > 0) {
				params.append(" and ");
			}
			params.append("id =:id");
			paramValues.put("id", accountEntitySearchEntity.getId());
		}
	        if (accountEntitySearchEntity.getIds() != null) {
	              if (params.length() > 0) {
	                      params.append(" and ");
	              }
	              params.append("id in(:ids) ");
	              paramValues.put("ids", new ArrayList<String>(Arrays.asList(accountEntitySearchEntity.getIds().split(","))));
	        }
		if (accountEntitySearchEntity.getAccountDetailTypeId() != null) {
			if (params.length() > 0) {
				params.append(" and ");
			}
			params.append("accountDetailTypeId =:accountDetailType");
			paramValues.put("accountDetailType", accountEntitySearchEntity.getAccountDetailTypeId());
		}
		if (accountEntitySearchEntity.getCode() != null) {
			if (params.length() > 0) {
				params.append(" and ");
			}
			params.append("code =:code");
			paramValues.put("code", accountEntitySearchEntity.getCode());
		}
		if (accountEntitySearchEntity.getName() != null) {
			if (params.length() > 0) {
				params.append(" and ");
			}
			params.append("name =:name");
			paramValues.put("name", accountEntitySearchEntity.getName());
		}
		if (accountEntitySearchEntity.getActive() != null) {
			if (params.length() > 0) {
				params.append(" and ");
			}
			params.append("active =:active");
			paramValues.put("active", accountEntitySearchEntity.getActive());
		}
		if (accountEntitySearchEntity.getDescription() != null) {
			if (params.length() > 0) {
				params.append(" and ");
			}
			params.append("description =:description");
			paramValues.put("description", accountEntitySearchEntity.getDescription());
		}

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

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

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

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

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

		BeanPropertyRowMapper row = new BeanPropertyRowMapper(AccountEntityEntity.class);

		List<AccountEntityEntity> accountEntityEntities = namedParameterJdbcTemplate.query(searchQuery.toString(),
				paramValues, row);

		page.setTotalResults(accountEntityEntities.size());

		List<AccountEntity> accountentities = new ArrayList<>();
		for (AccountEntityEntity accountEntityEntity : accountEntityEntities) {

			accountentities.add(accountEntityEntity.toDomain());
		}
		page.setPagedData(accountentities);

		return page;
	}

	public  AccountEntityJdbcRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate);

}