1 package org.javabb.quartz; 2 3 import java.util.List ; 4 5 import org.apache.commons.logging.Log; 6 import org.apache.commons.logging.LogFactory; 7 import org.javabb.transaction.PostTransaction; 8 import org.javabb.transaction.TopicTransaction; 9 import org.javabb.vo.PostText; 10 import org.javabb.vo.Topic; 11 import org.quartz.JobExecutionContext; 12 import org.quartz.JobExecutionException; 13 import org.springframework.scheduling.quartz.QuartzJobBean; 14 15 18 public class IndexPostsJob extends QuartzJobBean { 19 20 protected final Log _log = LogFactory.getLog(this.getClass()); 21 22 private PostTransaction postTransaction; 23 24 public void setPostTransaction(PostTransaction postTransaction) { 25 this.postTransaction = postTransaction; 26 } 27 28 private TopicTransaction topicTransaction; 29 30 public void setTopicTransaction(TopicTransaction topicTransaction) { 31 this.topicTransaction = topicTransaction; 32 } 33 34 private void indexPosts() throws Exception { 35 List topics = null; 36 try { 37 topics = topicTransaction.findAll(); 38 } catch (Exception e) { 39 _log.debug("Error retriving topics: " + e); 40 } 41 42 try { 43 for (int i = 0; i < topics.size(); i++) { 44 Topic topic = (Topic) topics.get(i); 45 try { 46 List posts = postTransaction.findAllByTopicDesc(topic); 47 for (int j = 0; j < posts.size(); j++) { 48 PostText post = (PostText) posts.get(i); 49 postTransaction.indexPost(post); 50 _log.debug("Posts indexed: " + i); 51 i++; 52 } 53 } catch (Exception e) { 54 _log.debug("Error retriving posts: " + e); 55 } 56 } 57 } catch (RuntimeException e) { 58 e.printStackTrace(); 60 } 61 } 62 63 protected void executeInternal(JobExecutionContext arg0) 64 throws JobExecutionException { 65 try { 66 _log.debug("Initializing index posts.."); 67 indexPosts(); 68 _log.debug("Done!"); 69 } catch (Exception e) { 70 e.printStackTrace(); 72 } 73 } 74 75 } 76 | Popular Tags |