コード例 #1
0
  private int completeUpdate(
      SearchIndexBuilderWorker worker, Connection connection, List runtimeToDo) throws Exception {
    try {

      for (Iterator tditer = runtimeToDo.iterator(); worker.isRunning() && tditer.hasNext(); ) {
        SearchBuilderItem sbi = (SearchBuilderItem) tditer.next();
        if (SearchBuilderItem.STATE_COMPLETED.equals(sbi.getSearchstate())) {
          if (SearchBuilderItem.ACTION_DELETE.equals(sbi.getSearchaction())) {
            delete(connection, sbi);
            connection.commit();
          } else {
            updateOrSave(connection, sbi);
            connection.commit();
          }
        }
      }
      return runtimeToDo.size();
    } catch (Exception ex) {
      log.warn(
          "Failed to update state in database due to " //$NON-NLS-1$
              + ex.getMessage()
              + " this will be corrected on the next run of the IndexBuilder, no cause for alarm"); //$NON-NLS-1$
    }
    return 0;
  }
コード例 #2
0
  private void processDeletes(
      SearchIndexBuilderWorker worker, Connection connection, List<SearchBuilderItem> runtimeToDo)
      throws SQLException, IOException {

    if (indexStorage.indexExists()) {
      IndexReader indexReader = null;
      try {
        indexReader = indexStorage.getIndexReader();

        // Open the index
        for (Iterator<SearchBuilderItem> tditer = runtimeToDo.iterator();
            worker.isRunning() && tditer.hasNext(); ) {
          SearchBuilderItem sbi = (SearchBuilderItem) tditer.next();
          if (!SearchBuilderItem.STATE_LOCKED.equals(sbi.getSearchstate())) {
            // should only be getting pending
            // items
            log.warn(
                " Found Item that was not pending " //$NON-NLS-1$
                    + sbi.getName());
            continue;
          }
          if (SearchBuilderItem.ACTION_UNKNOWN.equals(sbi.getSearchaction())) {
            sbi.setSearchstate(SearchBuilderItem.STATE_COMPLETED);
            updateOrSave(connection, sbi);

            continue;
          }
          // remove document
          // if this is mult segment it might not work.
          try {
            indexReader.deleteDocuments(new Term(SearchService.FIELD_REFERENCE, sbi.getName()));
            if (SearchBuilderItem.ACTION_DELETE.equals(sbi.getSearchaction())) {
              sbi.setSearchstate(SearchBuilderItem.STATE_COMPLETED);
              updateOrSave(connection, sbi);

            } else {
              sbi.setSearchstate(SearchBuilderItem.STATE_PENDING_2);
            }

          } catch (IOException ex) {
            log.warn("Failed to delete Page ", ex); // $NON-NLS-1$
          }
        }
      } finally {
        if (indexReader != null) {
          indexStorage.closeIndexReader(indexReader);
          indexReader = null;
        }
      }
    }
  }