File Source: ReIndexEntryOperation.java

     1  /*
     2   * Licensed to the Apache Software Foundation (ASF) under one or more
     3   *  contributor license agreements.  The ASF licenses this file to You
     4   * under the Apache License, Version 2.0 (the "License"); you may not
     5   * use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.  For additional information regarding
    15   * copyright in this work, please see the NOTICE file in the top level
    16   * directory of this distribution.
    17   */
    18  /* Created on Jul 16, 2003 */
    19  package org.apache.roller.weblogger.business.search.operations;
    20  
    21  import java.io.IOException;
    22  
    23  import org.apache.commons.logging.Log;
    24  import org.apache.commons.logging.LogFactory;
    25  import org.apache.lucene.index.IndexReader;
    26  import org.apache.lucene.index.IndexWriter;
    27  import org.apache.lucene.index.Term;
    28  import org.apache.roller.weblogger.WebloggerException;
    29  import org.apache.roller.weblogger.business.search.IndexManagerImpl;
    30  import org.apache.roller.weblogger.business.search.FieldConstants;
    31  import org.apache.roller.weblogger.business.Weblogger;
    32  import org.apache.roller.weblogger.business.WeblogManager;
    33  import org.apache.roller.weblogger.pojos.WeblogEntry;
    34  
    35  /**
    36   * An operation that adds a new log entry into the index.
    37   * @author Mindaugas Idzelis (min@idzelis.com)
    38   */
    39  public class ReIndexEntryOperation extends WriteToIndexOperation {
    40      
    41      //~ Static fields/initializers =============================================
    42      
             /* 
    P/P       *  Method: org.apache.roller.weblogger.business.search.operations.ReIndexEntryOperation__static_init
              * 
              *  Presumptions:
              *    org.apache.commons.logging.LogFactory:getFactory(...)@43 != null
              * 
              *  Postconditions:
              *    init'ed(mLogger)
              */
    43      private static Log mLogger =
    44              LogFactory.getFactory().getInstance(AddEntryOperation.class);
    45      
    46      //~ Instance fields ========================================================
    47      
    48      private WeblogEntry data;
    49      private Weblogger roller;
    50      
    51      //~ Constructors ===========================================================
    52      
    53      /**
    54       * Adds a web log entry into the index.
    55       */
    56      public ReIndexEntryOperation(Weblogger roller, IndexManagerImpl mgr,WeblogEntry data) {
                 /* 
    P/P           *  Method: void org.apache.roller.weblogger.business.search.operations.ReIndexEntryOperation(Weblogger, IndexManagerImpl, WeblogEntry)
                  * 
                  *  Postconditions:
                  *    this.data == data
                  *    init'ed(this.data)
                  *    this.manager == mgr
                  *    init'ed(this.manager)
                  *    this.roller == roller
                  *    init'ed(this.roller)
                  */
    57          super(mgr);
    58          this.roller = roller;
    59          this.data = data;
    60      }
    61      
    62      //~ Methods ================================================================
    63      
    64      public void doRun() {
    65          
    66          // since this operation can be run on a separate thread we must treat
    67          // the weblog object passed in as a detached object which is proned to
    68          // lazy initialization problems, so requery for the object now
    69          try {
                     /* 
    P/P               *  Method: void doRun()
                      * 
                      *  Preconditions:
                      *    (soft) mLogger != null
                      *    (soft) this.data != null
                      *    (soft) init'ed(this.reader)
                      *    (soft) init'ed(this.writer)
                      *    (soft) org/apache/roller/weblogger/business/WebloggerImpl.log != null
                      *    (soft) org/apache/roller/weblogger/business/search/IndexManagerImpl.mLogger != null
                      *    (soft) org/apache/roller/weblogger/business/search/operations/IndexOperation.mLogger != null
                      *    (soft) org/apache/roller/weblogger/config/WebloggerConfig.config != null
                      *    (soft) org/apache/roller/weblogger/config/WebloggerConfig.log != null
                      *    (soft) this.manager != null
                      *    ...
                      * 
                      *  Presumptions:
                      *    javax.persistence.EntityManager:find(...)@216 != null
                      * 
                      *  Postconditions:
                      *    (soft) this.data != null
                      *    init'ed(this.reader)
                      *    this.writer == One-of{old this.writer, &new IndexWriter(beginWriting#1)}
                      *    init'ed(this.writer)
                      *    new IndexWriter(beginWriting#1) num objects <= 1
                      */
    70              WeblogManager wMgr = roller.getWeblogManager();
    71              this.data = wMgr.getWeblogEntry(this.data.getId());
    72          } catch (WebloggerException ex) {
    73              mLogger.error("Error getting weblogentry object", ex);
    74              return;
    75          }
    76          
    77          IndexReader reader = beginDeleting();
    78          try {
    79              if (reader != null) {
    80                  Term term = new Term(FieldConstants.ID, data.getId());
    81                  reader.delete(term);
    82              }
    83          } catch (IOException e) {
    84              mLogger.error("Error deleting doc from index", e);
    85          } finally {
    86              endDeleting();
    87          }
    88          
    89          IndexWriter writer = beginWriting();
    90          try {
    91              if (writer != null) {
    92                  writer.addDocument(getDocument(data));
    93              }
    94          } catch (IOException e) {
    95              mLogger.error("Problems adding doc to index", e);
    96          } finally {
    97              if (roller != null) roller.release();
    98              endWriting();
    99          }
   100      }
   101  }








SofCheck Inspector Build Version : 2.18479
ReIndexEntryOperation.java 2009-Jan-02 14:24:58
ReIndexEntryOperation.class 2009-Sep-04 03:12:31