KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > business > search > operations > RemoveEntryOperation


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.business.search.operations;
20
21 import java.io.IOException JavaDoc;
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.Term;
27 import org.apache.roller.business.IndexManagerImpl;
28 import org.apache.roller.business.search.FieldConstants;
29 import org.apache.roller.pojos.WeblogEntryData;
30
31
32 /**
33  * An operation that removes the weblog from the index.
34  * @author Mindaugas Idzelis (min@idzelis.com)
35  */

36 public class RemoveEntryOperation extends WriteToIndexOperation {
37     
38     //~ Static fields/initializers =============================================
39

40     private static Log mLogger =
41             LogFactory.getFactory().getInstance(RemoveEntryOperation.class);
42     
43     //~ Instance fields ========================================================
44

45     private WeblogEntryData data;
46     
47     //~ Constructors ===========================================================
48

49     public RemoveEntryOperation(IndexManagerImpl mgr, WeblogEntryData data) {
50         super(mgr);
51         this.data = data;
52     }
53     
54     //~ Methods ================================================================
55

56     public void doRun() {
57         IndexReader reader = beginDeleting();
58         try {
59             if (reader != null) {
60                 Term term = new Term(FieldConstants.ID, data.getId());
61                 reader.delete(term);
62             }
63         } catch (IOException JavaDoc e) {
64             mLogger.error("Error deleting doc from index", e);
65         } finally {
66             endDeleting();
67         }
68     }
69     
70     
71 }
72
Popular Tags