File Source: RemoveEntryOperation.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.Term;
27 import org.apache.roller.weblogger.WebloggerException;
28 import org.apache.roller.weblogger.business.Weblogger;
29 import org.apache.roller.weblogger.business.WeblogManager;
30 import org.apache.roller.weblogger.business.search.IndexManagerImpl;
31 import org.apache.roller.weblogger.business.search.FieldConstants;
32 import org.apache.roller.weblogger.pojos.WeblogEntry;
33
34
35 /**
36 * An operation that removes the weblog from the index.
37 * @author Mindaugas Idzelis (min@idzelis.com)
38 */
39 public class RemoveEntryOperation extends WriteToIndexOperation {
40
41 //~ Static fields/initializers =============================================
42
/*
P/P * Method: org.apache.roller.weblogger.business.search.operations.RemoveEntryOperation__static_init
*
* Presumptions:
* org.apache.commons.logging.LogFactory:getFactory(...)@43 != null
*
* Postconditions:
* init'ed(mLogger)
*/
43 private static Log mLogger =
44 LogFactory.getFactory().getInstance(RemoveEntryOperation.class);
45
46 //~ Instance fields ========================================================
47
48 private WeblogEntry data;
49 private Weblogger roller;
50
51 //~ Constructors ===========================================================
52
53 public RemoveEntryOperation(Weblogger roller, IndexManagerImpl mgr,WeblogEntry data) {
/*
P/P * Method: void org.apache.roller.weblogger.business.search.operations.RemoveEntryOperation(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)
*/
54 super(mgr);
55 this.roller = roller;
56 this.data = data;
57 }
58
59 //~ Methods ================================================================
60
61 public void doRun() {
62
63 // since this operation can be run on a separate thread we must treat
64 // the weblog object passed in as a detached object which is proned to
65 // lazy initialization problems, so requery for the object now
66 try {
/*
P/P * Method: void doRun()
*
* Preconditions:
* (soft) mLogger != null
* (soft) this.data != null
* (soft) init'ed(this.reader)
* (soft) org/apache/roller/weblogger/business/search/IndexManagerImpl.mLogger != null
* (soft) org/apache/roller/weblogger/business/search/operations/IndexOperation.mLogger != null
* (soft) this.manager != null
* (soft) init'ed(this.manager.fRAMindex)
* (soft) init'ed(this.manager.indexDir)
* (soft) init'ed(this.manager.useRAMIndex)
* (soft) this.roller != null
* ...
*
* Presumptions:
* javax.persistence.EntityManager:find(...)@216 != null
*
* Postconditions:
* (soft) this.data != null
* init'ed(this.reader)
*/
67 WeblogManager wMgr = roller.getWeblogManager();
68 this.data = wMgr.getWeblogEntry(this.data.getId());
69 } catch (WebloggerException ex) {
70 mLogger.error("Error getting weblogentry object", ex);
71 return;
72 }
73
74 IndexReader reader = beginDeleting();
75 try {
76 if (reader != null) {
77 Term term = new Term(FieldConstants.ID, data.getId());
78 reader.delete(term);
79 }
80 } catch (IOException e) {
81 mLogger.error("Error deleting doc from index", e);
82 } finally {
83 endDeleting();
84 }
85 }
86
87
88 }
SofCheck Inspector Build Version : 2.18479
| RemoveEntryOperation.java |
2009-Jan-02 14:25:08 |
| RemoveEntryOperation.class |
2009-Sep-04 03:12:31 |