⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 messagekernel.java

📁 用Hibernate开发的JiveJdon
💻 JAVA
字号:
/*
 * Copyright 2003-2005 the original author or authors.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package com.jdon.jivejdon.service.imp.message;

import org.apache.log4j.Logger;

import com.jdon.controller.events.EventModel;
import com.jdon.jivejdon.model.ForumMessage;
import com.jdon.jivejdon.model.ForumThread;
import com.jdon.jivejdon.repository.ForumBuilder;
import com.jdon.jivejdon.repository.MessageRepository;
import com.jdon.jivejdon.service.ForumMessageQueryService;


/**
 * @author <a href="mailto:banqiao@jdon.com">banq</a>
 *
 */
public class MessageKernel {
    private final static Logger logger = Logger.getLogger(MessageKernel.class);
    
    protected MessageRepository messageRepository;   
    protected ForumMessageQueryService forumMessageQueryService;
    protected ForumBuilder forumBuilder;
    
    public MessageKernel(MessageRepository messageRepository,
    		ForumMessageQueryService forumMessageQueryService,
    		ForumBuilder forumBuilder){
        this.messageRepository = messageRepository;
        this.forumMessageQueryService = forumMessageQueryService;
        this.forumBuilder = forumBuilder;
    }
    
    /**
     * get the full forum in forumMessage, and return it.
     */
    public ForumMessage initMessage(EventModel em) {
    	logger.debug("enter initMessage");
        return messageRepository.initMessage(em);
    }
    
    public ForumMessage initReplyMessage(EventModel em) {
    	logger.debug("enter initReplyMessage");
        return messageRepository.initReplyMessage(em);
    }    
  
    /*
     * return a full ForumMessage need solve the relations with Forum
     * ForumThread parentMessage
     */
    public ForumMessage getMessage(Long messageId) {
		logger.debug("enter MessageServiceImp's getMessage");
		return messageRepository.getMessage(messageId);
	}

    /**
	 * return a full ForumThread one ForumThread has one rootMessage need solve
	 * the realtion with Forum rootForumMessage lastPost
	 * 
	 * @param threadId
	 * @return
	 */
    public ForumThread getThread(Long threadId) {
    	logger.debug("enter getThread");
        return messageRepository.getThread(threadId);
      
    }
   
    /*
     * create the topic message
     */
    public void createTopicMessage(EventModel em) throws Exception{
    	logger.debug("enter createTopicMessage");
        ForumMessage forumMessage = (ForumMessage)em.getModelIF();
        messageRepository.createTopicMessage(em);
        logger.debug("createTopicMessage ok!");

    }
    
    
    
   
    /**
     * the relation about creating reply forumMessage only need a parameter : parent message.
     * we can get the Forum or ForumThread from the parent message.
     * the hypelink parameter in jsp must be a paremeter: the Id of parent message.
     * 
     */
    public void createReplyMessage(EventModel em) throws Exception{  
    	logger.debug("enter createReplyMessage");
        ForumMessage forumMessage = (ForumMessage)em.getModelIF();
        messageRepository.createReplyMessage(em);
        logger.debug("createReplyMessage ok!");
    }
  
    
    /* 
     * update the message, 
     * update the message's subject and body
     * we must mark the message that has been updated.
     * there are two kinds of parameters: the primary key /new entity data 
     * in DTO ForumMessage of the method patameter   
     * 
     */
    public void updateMessage(EventModel em) throws Exception{
    	logger.debug("enter updateMessage");
        messageRepository.updateMessage(em);
        logger.debug("updateMessage ok!");       
    }
    
    /*
     * delete a message and not inlcude its childern
     */
    public void deleteMessage(EventModel em) throws Exception{   
    	logger.debug("enter deleteMessage");
    	ForumMessage delforumMessage = (ForumMessage)em.getModelIF();
        if ((delforumMessage == null) || (delforumMessage.getMessageId() == null))
              return;
        
        delforumMessage = getMessage(delforumMessage.getMessageId());
        if (delforumMessage == null){
            logger.equals("the messageId that will be deleted don't existed: "+ delforumMessage.getMessageId());
            return;
        }
        messageRepository.deleteMessage(delforumMessage);	
         
        logger.debug("deleteMessage ok!");
    }
    
    
   
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -