File Source: AddEntryOperation.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.IndexWriter;
26 import org.apache.roller.weblogger.WebloggerException;
27 import org.apache.roller.weblogger.business.search.IndexManagerImpl;
28 import org.apache.roller.weblogger.business.Weblogger;
29 import org.apache.roller.weblogger.business.WeblogManager;
30 import org.apache.roller.weblogger.pojos.WeblogEntry;
31
32 /**
33 * An operation that adds a new log entry into the index.
34 * @author Mindaugas Idzelis (min@idzelis.com)
35 */
36 public class AddEntryOperation extends WriteToIndexOperation {
37
38 //~ Static fields/initializers =============================================
39
/*
P/P * Method: org.apache.roller.weblogger.business.search.operations.AddEntryOperation__static_init
*
* Presumptions:
* org.apache.commons.logging.LogFactory:getFactory(...)@40 != null
*
* Postconditions:
* init'ed(mLogger)
*/
40 private static Log mLogger =
41 LogFactory.getFactory().getInstance(AddEntryOperation.class);
42
43 //~ Instance fields ========================================================
44
45 private WeblogEntry data;
46 private Weblogger roller;
47
48 //~ Constructors ===========================================================
49
50 /**
51 * Adds a web log entry into the index.
52 */
53 public AddEntryOperation(Weblogger roller, IndexManagerImpl mgr,WeblogEntry data) {
/*
P/P * Method: void org.apache.roller.weblogger.business.search.operations.AddEntryOperation(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() {
/*
P/P * Method: void doRun()
*
* Preconditions:
* (soft) mLogger != null
* (soft) this.data != null
* (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
* (soft) init'ed(this.manager.fRAMindex)
* ...
*
* Presumptions:
* javax.persistence.EntityManager:find(...)@216 != null
* wMgr.strategy.emf@62 != null
* wMgr.strategy.threadLocalEntityManager@62 != null
* wMgr.strategy@62 != null
*
* Postconditions:
* (soft) this.data != null
* this.writer == One-of{&new IndexWriter(beginWriting#1), old this.writer}
* (soft) init'ed(this.writer)
* new IndexWriter(beginWriting#1) num objects <= 1
*/
62 IndexWriter writer = beginWriting();
63
64 // since this operation can be run on a separate thread we must treat
65 // the weblog object passed in as a detached object which is proned to
66 // lazy initialization problems, so requery for the object now
67 try {
68 WeblogManager wMgr = roller.getWeblogManager();
69 this.data = wMgr.getWeblogEntry(this.data.getId());
70 } catch (WebloggerException ex) {
71 mLogger.error("Error getting weblogentry object", ex);
72 return;
73 }
74
75 try {
76 if (writer != null) {
77 writer.addDocument(getDocument(data));
78 }
79 } catch (IOException e) {
80 mLogger.error("Problems adding doc to index", e);
81 } finally {
82 if (roller != null) roller.release();
83 endWriting();
84 }
85 }
86 }
SofCheck Inspector Build Version : 2.18479
| AddEntryOperation.java |
2009-Jan-02 14:24:54 |
| AddEntryOperation.class |
2009-Sep-04 03:12:32 |