/** Searches for objects to return based on the filter provided with offset and limit features. */
  public void executeQuery(
      ObjectClass oclass, String query, ResultsHandler handler, OperationOptions options) {
    /** Track the number of lines processed. */
    long lines = 0;

    /** Text qualifier character. */
    final char textQualifier = cfg.getTextQualifier();

    /** Field delimiter. */
    final char fieldSeparator = cfg.getFieldDelimiter();

    /** Unique identifier field. */
    final String uniqueIdField = cfg.getUniqueAttributeName();

    /** Internal reader initialized in the constructor. */
    BufferedReader rdr = null;

    try {
      rdr = cfg.newFileReader();
      /** Fields names read from the header. */
      List<String> fieldNames =
          FlatFileConnector.readHeader(rdr, fieldSeparator, textQualifier, uniqueIdField);

      String line;
      while ((line = rdr.readLine()) != null) {
        ++lines;
        if (line.trim().length() == 0) {
          LOG.info(MSG_SKIPPING);
          continue;
        }
        LOG.ok("Processing Data Line: {0}", line);
        List<String> fieldValues = StringUtil.parseLine(line, fieldSeparator, textQualifier);
        if (fieldValues == null) {
          LOG.error("Error: {0}", line);
          break;
        } else {
          ConnectorObjectBuilder bld = new ConnectorObjectBuilder();
          for (int i = 0; i < fieldValues.size(); ++i) {
            String name = fieldNames.get(i);
            String value = fieldValues.get(i);
            if (name.equals(uniqueIdField)) {
              bld.setUid(value);
              bld.setName(value);
            } else {
              bld.addAttribute(name, value);
            }
          }
          // create the connector object..
          ConnectorObject ret = bld.build();
          if (!handler.handle(ret)) {
            break;
          }
        }
      }
    } catch (IOException e) {
      throw new ConnectorIOException(e);
    } finally {
      IOUtil.quietClose(rdr);
    }
  }
 /**
  * Simply return everything don't bother optimizing.
  *
  * @see SearchOp#executeQuery(org.identityconnectors.framework.common.objects.ObjectClass, Object,
  *     org.identityconnectors.framework.common.objects.ResultsHandler,
  *     org.identityconnectors.framework.common.objects.OperationOptions)
  */
 public void executeQuery(
     ObjectClass objectClass, String query, ResultsHandler handler, OperationOptions options) {
   Iterator<ConnectorObject> iter = objects.iterator();
   while (iter.hasNext()) {
     if (!handler.handle(iter.next())) {
       break;
     }
   }
 }
  public void executeQuery(
      ObjectClass objClass, String query, ResultsHandler handler, OperationOptions options) {
    // TODO Auto-generated method stub
    LOG.ok("Query {0} ", query);

    if (!isAccount(objClass)) {
      throw new UnsupportedOperationException(
          "Could not execute query. Object class not supported: " + objClass);
    }

    try {
      String repoId = getFoundationRepoId();

      String template = "<Templates>" + "<Person>" + "</Person>" + "</Templates>";

      int flags = MdOMIUtil.OMI_GET_METADATA | MdOMIUtil.OMI_ALL | MdOMIUtil.OMI_TEMPLATE;
      List objects =
          connection
              .getFactory()
              .getOMIUtil()
              .getMetadataObjects(repoId, MetadataObjects.PERSON, flags, template);

      Iterator iterator = objects.iterator();
      while (iterator.hasNext()) {
        Object obj = iterator.next();
        RootImpl p = (RootImpl) obj;
        ConnectorObjectBuilder cob = new ConnectorObjectBuilder();

        cob.addAttribute(Name.NAME, p.getName());
        cob.addAttribute(Uid.NAME, p.getId());

        Set<Entry<String, String>> attrs = p.getAttrs().entrySet();
        Iterator<Entry<String, String>> attrIterator = attrs.iterator();
        while (attrIterator.hasNext()) {
          Entry<String, String> attr = attrIterator.next();
          // skip id and name..it was set before (icf_name and icf_uid)
          if (attr.getKey().equals(CMetadata.ATTRIBUTE_ID_NAME)) {
            continue;
          }

          if (attr.getKey().equals(CMetadata.ATTRIBUTE_NAME_NAME)) {
            continue;
          }
          if (StringUtil.isEmpty(attr.getValue())) {
            LOG.ok("Skipping setting attribute {0}. Attribute value is blank", attr.getKey());
          } else {
            LOG.ok("Setting attribute {0} with value {1}", attr.getKey(), attr.getValue());
            cob.addAttribute(attr.getKey(), attr.getValue());
          }
        }

        handler.handle(cob.build());
      }

    } catch (RemoteException e) {
      // TODO Auto-generated catch block
      throw new ConnectorException(e);
    } catch (MdException e) {
      // TODO Auto-generated catch block
      throw new ConnectorException(e);
    }
  }
  public void executeQuery(
      ObjectClass objectClass, Filter query, ResultsHandler handler, OperationOptions options) {

    SortKey[] sortKeys = options.getSortKeys();
    if (null == sortKeys) {
      sortKeys = new SortKey[] {new SortKey(Name.NAME, true)};
    }

    // Rebuild the full result set.
    TreeSet<ConnectorObject> resultSet =
        new TreeSet<ConnectorObject>(new ResourceComparator(sortKeys));

    if (null != query) {
      for (ConnectorObject co : collection.values()) {
        if (query.accept(co)) {
          resultSet.add(co);
        }
      }
    } else {
      resultSet.addAll(collection.values());
    }

    // Handle the results
    if (null != options.getPageSize()) {
      // Paged Search
      final String pagedResultsCookie = options.getPagedResultsCookie();
      String currentPagedResultsCookie = options.getPagedResultsCookie();
      final Integer pagedResultsOffset =
          null != options.getPagedResultsOffset()
              ? Math.max(0, options.getPagedResultsOffset())
              : 0;
      final Integer pageSize = options.getPageSize();

      int index = 0;
      int pageStartIndex = null == pagedResultsCookie ? 0 : -1;
      int handled = 0;

      for (ConnectorObject entry : resultSet) {
        if (pageStartIndex < 0 && pagedResultsCookie.equals(entry.getName().getNameValue())) {
          pageStartIndex = index + 1;
        }

        if (pageStartIndex < 0 || index < pageStartIndex) {
          index++;
          continue;
        }

        if (handled >= pageSize) {
          break;
        }

        if (index >= pagedResultsOffset + pageStartIndex) {
          if (handler.handle(entry)) {
            handled++;
            currentPagedResultsCookie = entry.getName().getNameValue();
          } else {
            break;
          }
        }
        index++;
      }

      if (index == resultSet.size()) {
        currentPagedResultsCookie = null;
      }

      if (handler instanceof SearchResultsHandler) {
        ((SearchResultsHandler) handler)
            .handleResult(new SearchResult(currentPagedResultsCookie, resultSet.size() - index));
      }
    } else {
      // Normal Search
      for (ConnectorObject entry : resultSet) {
        if (!handler.handle(entry)) {
          break;
        }
      }
      if (handler instanceof SearchResultsHandler) {
        ((SearchResultsHandler) handler).handleResult(new SearchResult());
      }
    }
  }