KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > business > search > operations > AddEntryOperation


1 /*
2  * Created on Jul 16, 2003
3  *
4  * Authored by: Mindaugas Idzelis (min@idzelis.com)
5  */

6 package org.roller.business.search.operations;
7
8 import java.io.IOException JavaDoc;
9
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12 import org.apache.lucene.index.IndexWriter;
13 import org.roller.business.IndexManagerImpl;
14 import org.roller.model.Roller;
15 import org.roller.model.RollerFactory;
16 import org.roller.pojos.WeblogEntryData;
17
18
19 /**
20  * @author aim4min
21  *
22  * An operation that adds a new log entry into the index.
23  */

24 public class AddEntryOperation extends WriteToIndexOperation
25 {
26     //~ Static fields/initializers =============================================
27

28     private static Log mLogger =
29         LogFactory.getFactory().getInstance(AddEntryOperation.class);
30
31     //~ Instance fields ========================================================
32

33     private WeblogEntryData data;
34
35     //~ Constructors ===========================================================
36

37     /**
38      * Adds a web log entry into the index.
39      */

40     public AddEntryOperation(IndexManagerImpl mgr, WeblogEntryData data)
41     {
42         super(mgr);
43         this.data = data;
44     }
45
46     //~ Methods ================================================================
47

48     /* (non-Javadoc)
49      * @see java.lang.Runnable#run()
50      */

51     public void doRun()
52     {
53         IndexWriter writer = beginWriting();
54         Roller roller = RollerFactory.getRoller();
55         try
56         {
57             if (writer != null)
58             {
59                 writer.addDocument(getDocument(data));
60             }
61         }
62         catch (IOException JavaDoc e)
63         {
64             mLogger.error("Problems adding doc to index", e);
65         }
66         finally
67         {
68             if (roller != null) roller.release();
69             endWriting();
70         }
71     }
72     
73 }
74
Popular Tags