📄 othersserviceimp.java
字号:
/*
* Copyright 2007 the original author or jdon.com
*
* 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.others;
import java.util.ArrayList;
import java.util.Collection;
import javax.transaction.TransactionManager;
import org.apache.log4j.Logger;
import com.jdon.controller.events.EventModel;
import com.jdon.controller.model.PageIterator;
import com.jdon.controller.pool.Poolable;
import com.jdon.jivejdon.Constants;
import com.jdon.jivejdon.model.ForumMessage;
import com.jdon.jivejdon.model.ForumThread;
import com.jdon.jivejdon.model.HotKeys;
import com.jdon.jivejdon.model.ThreadTag;
import com.jdon.jivejdon.repository.HotKeysRepository;
import com.jdon.jivejdon.repository.MessageRepository;
import com.jdon.jivejdon.repository.TagRepository;
import com.jdon.jivejdon.service.OthersService;
import com.jdon.jivejdon.service.util.JtaTransactionUtil;
public class OthersServiceImp implements OthersService, Poolable {
private final static Logger logger = Logger.getLogger(OthersServiceImp.class);
private HotKeysRepository hotKeysRepository;
private TagRepository tagRepository;
private MessageRepository messageRepository;
protected JtaTransactionUtil jtaTransactionUtil;
public OthersServiceImp(HotKeysRepository hotKeysFactory, TagRepository tagRepository, MessageRepository messageRepository, JtaTransactionUtil jtaTransactionUtil) {
super();
this.hotKeysRepository = hotKeysFactory;
this.tagRepository = tagRepository;
this.messageRepository = messageRepository;
this.jtaTransactionUtil = jtaTransactionUtil;
}
public Collection tags(String s) {
Collection tags = new ArrayList();
for (Long tagID : tagRepository.searchTitle(s)) {
ThreadTag tag = tagRepository.getThreadTag(tagID);
tags.add(tag);
}
return tags;
}
public PageIterator getTaggedThread(Long tagID, int start, int count) {
return tagRepository.getTaggedThread(tagID, start, count);
}
public PageIterator getTaggedRandomThreads(Long tagID, int start, int count) {
PageIterator pi = tagRepository.getTaggedThread(tagID, start, count);
if ((pi.getAllCount() == 0) || (count == 0))
return new PageIterator();
int pageCount = pi.getAllCount() / count;
int nowPage = (int) (Math.random() * pageCount);
start = nowPage * count;
return tagRepository.getTaggedThread(tagID, start, count);
}
public void updateThreadTag(EventModel em) {
ThreadTag threadTag = (ThreadTag) em.getModelIF();
ThreadTag threadTagOld = tagRepository.getThreadTag(threadTag.getTagID());
if (threadTag == null)
return;
TransactionManager tx = jtaTransactionUtil.getTransactionManager();
try {
tx.begin();
threadTagOld.setTitle(threadTag.getTitle());
tagRepository.updateThreadTag(threadTagOld);
tx.commit();
} catch (Exception e) {
logger.error(e);
jtaTransactionUtil.rollback(tx);
em.setErrors(Constants.ERRORS);
}
}
public void deleteThreadTag(EventModel em) {
ThreadTag threadTag = (ThreadTag) em.getModelIF();
threadTag = tagRepository.getThreadTag(threadTag.getTagID());
if (threadTag == null)
return;
TransactionManager tx = jtaTransactionUtil.getTransactionManager();
try {
tx.begin();
tagRepository.deleteThreadTag(threadTag);
tx.commit();
} catch (Exception e) {
logger.error(e);
jtaTransactionUtil.rollback(tx);
em.setErrors(Constants.ERRORS);
}
}
public PageIterator getThreadTags(int start, int count) {
return tagRepository.getThreadTags(start, count);
}
public ThreadTag getThreadTag(Long tagID) {
return tagRepository.getThreadTag(tagID);
}
public void saveTag(Long threadId, String[] tagTitle) {
if ((tagTitle == null) || (tagTitle.length == 0)) {
return;
}
try {
ForumThread thread = messageRepository.getForumBuilder().getThread(threadId);
thread.getRootMessage().setTagTitle(tagTitle);
ForumMessage rootMessage = thread.getRootMessage();
messageRepository.updateMessage(rootMessage);
} catch (Exception e) {
logger.error(e);
}
}
public void saveHotKeys(HotKeys hotKeys) {
hotKeysRepository.saveHotKeys(hotKeys);
}
public HotKeys getHotKeys() {
return hotKeysRepository.getHotKeys();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -