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

📄 catalogserviceimpl.java

📁 Jaoso新闻文章发布系统 0.9.1final 程序架构: Struts+Spring+Hibernate 主要功能:   ·新闻采用在线编辑器,可以象使用word一样编辑新闻,可简繁
💻 JAVA
字号:
package jaoso.guestbook.service.impl;

import jaoso.framework.dao.MyQuery;

import jaoso.framework.service.impl.BaseService;

import jaoso.framework.util.MyBeanUtils;
import jaoso.framework.util.MyUtils;

import jaoso.guestbook.dao.CatalogDAO;
import jaoso.guestbook.dao.MessageDAO;

import jaoso.guestbook.domain.GbCatalog;
import jaoso.guestbook.domain.Message;

import jaoso.guestbook.service.CatalogService;

import jaoso.news.exception.CatalogExistException;

import java.io.Serializable;

import java.lang.reflect.InvocationTargetException;

import java.sql.Types;

/**
 * @author Edgeloner edgeloner@163.com
 * @since 2004-7-2
 */
public class CatalogServiceImpl extends BaseService implements CatalogService {
	/** DOCUMENT ME! */
	private CatalogDAO catalogDAO;

	/** DOCUMENT ME! */
	private MessageDAO messageDAO;

	/**
	 * (non-Javadoc)
	 * 
	 * @see jaoso.guestbook.service.CatalogService#getCatalog(java.io.Serializable)
	 */
	public final GbCatalog getCatalog(final Serializable id) {
		return catalogDAO.getCatalog(id);
	}

	/**
	 * @param arg0
	 *            catalogDAO
	 */
	public final void setCatalogDAO(final CatalogDAO arg0) {
		this.catalogDAO = arg0;
	}

	/**
	 * @param messageDAO
	 */
	public final void setMessageDAO(final MessageDAO messageDAO) {
		this.messageDAO = messageDAO;
	}

	/**
	 * (non-Javadoc)
	 * 
	 * @see jaoso.guestbook.service.CatalogService#getMessage(java.lang.String[])
	 */
	public final Message[] getMessages(final String[] args) {
		String title = args[0];
		String catalog = args[1];
		String order = args[2];
		String sort = args[3];
		String page = args[4];
		Message[] ls = null;
		String sqlStr = "from Message a where 1=1 and a.parent is null";
		sqlStr += ((!MyUtils.isBlank(title)) ? " and a.title like ? " : "");

		sqlStr += ((!MyUtils.isBlank(catalog) && (catalog.trim().length() > 10)) ? " and a.catalog like ? "
				: "");

		MyQuery query = new MyQuery();
		query.setQueryString(sqlStr);

		if (!MyUtils.isBlank(title)) {
			query.addPara("%" + title + "%", Types.VARCHAR);
		}

		if (!MyUtils.isBlank(catalog) && (catalog.trim().length() > 10)) {
			query.addPara(catalog, Types.VARCHAR);
		}

		if (!MyUtils.isBlank(order)) {
			if (order.trim().equalsIgnoreCase("author")) {
				query.setOrderby(" order by a.author " + sort);
			} else if (order.trim().equalsIgnoreCase("title")) {
				query.setOrderby(" order by a.title " + sort);
			} else if (order.trim().equalsIgnoreCase("date")) {
				query.setOrderby(" order by a.createDate " + sort);
			}
		} else {
			query.setOrderby(" order by a.createDate desc");
		}

		if (MyUtils.isNumeric(page)) {
			query.setPageStartNo(Integer.parseInt(page));
		}

		ls = messageDAO.findMessage(query);

		return ls;
	}

	/**
	 * (final non-Javadoc)
	 * 
	 * @see jaoso.guestbook.service.CatalogService#createCatalog(final
	 *      jaoso.guestbook.domain.GbCatalog)
	 */
	public final void createCatalog(final GbCatalog arg0)
			throws CatalogExistException {
		if (catalogDAO.isExist(arg0.getTitle())) {
			throw new CatalogExistException("catalog already exist!");
		}

		catalogDAO.createCatalog(arg0);
	}

	/**
	 * (non-Javadoc)
	 * 
	 * @see jaoso.guestbook.service.CatalogService#findAll()
	 */
	public final GbCatalog[] findAll() {
		return catalogDAO.findAllCatalog();
	}

	/**
	 * (final non-Javadoc)
	 * 
	 * @see jaoso.guestbook.service.CatalogService#removeCatalog(final
	 *      java.io.Serializable)
	 */
	public final void removeCatalog(final Serializable id) {
		catalogDAO.removeCatalog(id);
	}

	/**
	 * (final non-Javadoc)
	 * 
	 * @see jaoso.guestbook.service.CatalogService#updateCatalog(final
	 *      jaoso.guestbook.domain.GbCatalog)
	 */
	public final void updateCatalog(final GbCatalog arg0)
			throws CatalogExistException {
		if (catalogDAO.isExist(arg0.getTitle(), arg0.getId())) {
			throw new CatalogExistException("catalog title already exist!");
		}

		GbCatalog entity = getCatalog(arg0.getId());

		try {
			MyBeanUtils.copyProperties(entity, arg0);
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}

		catalogDAO.updateCatalog(entity);
	}

	/**
	 * (non-Javadoc)
	 * 
	 * @see jaoso.guestbook.service.CatalogService#getResultCount(java.lang.String[])
	 */
	public Integer getResultCount(final String[] args) {
		String title = args[0];
		String catalog = args[1];

		Integer ls = new Integer(0);
		String sqlStr = "select count(*) from Message a where 1=1 ";
		sqlStr += ((!MyUtils.isBlank(title)) ? " and a.title like ? " : "");

		sqlStr += ((!MyUtils.isBlank(catalog) && (catalog.trim().length() > 10)) ? " and a.catalog like ? "
				: "");

		MyQuery query = new MyQuery();
		query.setQueryString(sqlStr);

		if (!MyUtils.isBlank(title)) {
			query.addPara("%" + title + "%", Types.VARCHAR);
		}

		if (!MyUtils.isBlank(catalog)) {
			query.addPara(catalog, Types.VARCHAR);
		}

		return ls;
	}

	/**
	 * (non-Javadoc)
	 * 
	 * @see jaoso.guestbook.service.CatalogService#addMessage(java.io.Serializable,
	 *      jaoso.guestbook.domain.Message, Serializable)
	 */
	public final void addMessage(final Serializable arg0, final Message arg1,
			final Serializable arg2) {
		GbCatalog catalog = getCatalog(arg0);

		if (!MyUtils.isBlank(arg2)) {
			Message parent = messageDAO.getMessage(arg2);
			parent.getReplay().add(arg1);
			arg1.setParent(parent);
		}

		arg1.setCatalog(catalog);
		catalog.getMessages().add(arg1);

		//catalogDAO.updateCatalog(catalog);
		messageDAO.createMessage(arg1);
	}

	/**
	 * (non-Javadoc)
	 * 
	 * @see jaoso.guestbook.service.CatalogService#removeMessage(java.io.Serializable)
	 */
	public final void removeMessage(final Serializable arg0) {
		Message msg = messageDAO.getMessage(arg0);

		if (msg.getParent() != null) {
			msg.getParent().getReplay().remove(msg);
		}

		msg.getCatalog().getMessages().remove(msg);
		catalogDAO.updateCatalog(msg.getCatalog());
	}
}

⌨️ 快捷键说明

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