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

📄 channelservice.java

📁 jsp+servlet实现的标准MVC系统 jsp-servlet-service-DAO-DBMS
💻 JAVA
字号:
/*
 * Created on 2005-11-10
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.mycompany.news.service;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

import com.mycompany.database.Database;
import com.mycompany.news.dao.ChannelDAO;
import com.mycompany.news.dao.impl.ChannelDAOImpl;
import com.mycompany.news.dto.Channel;
import com.mycompany.news.dto.Column;

/**
 * @author Administrator
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class ChannelService extends BaseService{

	private ChannelDAO channelDAO=new ChannelDAOImpl();

	public List getChildrenColumns(Channel channel){
		Connection connection = null;
		try {
			connection = Database.getConnection();
			channelDAO.setConnection(connection);
			return channelDAO.getChildren(channel.getChannelID());
		} catch (Exception e) {
			e.printStackTrace();
			message = e.getMessage();
		} finally {
			Database.releaseConnection(connection);
		}
		return new ArrayList();

	}

	public boolean addChannel(Channel channel) {
		Connection connection = null;
		try {
			connection = Database.getConnection();
			channelDAO.setConnection(connection);
			channelDAO.addChannel(channel);
			Database.commit();
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			message = e.getMessage();
			Database.rollback();
			return false;
		} finally {
			Database.releaseConnection(connection);
		}
	};//添加Channel信息
//
	public boolean updateChannel(Channel channel) {
		Connection conn=null;
		try{
			conn = Database.getConnection();
			channelDAO.setConnection(conn);
			channelDAO.updateChannel(channel);
			conn.commit();
			return true;
		}catch(Exception e){
			e.printStackTrace();
			message = e.getMessage();
			Database.rollback();
			return false;
		}finally{
			Database.releaseConnection(conn);
		}

	};//修改Channel信息
//
	public boolean deleteChannel(Channel channel) {
		Connection conn=null;
		try{
			conn = Database.getConnection();
			channelDAO.setConnection(conn);
			List columns = channelDAO.getChildren(channel.getChannelID());
			if(columns.size()!=0){
				message="已经存在下属栏目,不允许删除";
				return false;
			}
			channelDAO.deleteChannel(channel);
			conn.commit();
			return true;
		}catch(Exception e){
			e.printStackTrace();
			message = e.getMessage();
			Database.rollback();
			return false;
		}finally{
			Database.releaseConnection(conn);
		}
	}
//
	public List listAllChannels() {
		Connection conn=null;
		try {
			conn = Database.getConnection();
			channelDAO.setConnection(conn);
			return channelDAO.listAllChannels();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			Database.releaseConnection(conn);
		}
		return null;
	}
//
	public List listChannels(Channel channelCondition) {
		Connection conn =null;
		try{
		conn = Database.getConnection();
		channelDAO.setConnection(conn);
		return channelDAO.listChannels(channelCondition);
		}catch(Exception e){
			e.printStackTrace();
			message = e.getMessage();
			return null;
		}finally{
		Database.releaseConnection(conn);	
		}	
	};//组合条件查询
//
	public Channel getByID(int id) {
		Connection connection = null;
		try {
			connection = Database.getConnection();
			channelDAO.setConnection(connection);
			return channelDAO.getByID(id);
		} catch (Exception e) {
			e.printStackTrace();
			setMessage(e.getMessage());
		} finally {
			Database.releaseConnection(connection);
		}
		return null;
		
	};//根据主键获取对象

	public StringBuffer getTreeString(String url,Long channelid){
		StringBuffer ret = new StringBuffer();
		ColumnService cs = new ColumnService();
		Channel channel = new Channel();
		channel.setChannelID(channelid);
		List topColumns = getChildrenColumns(channel);
		for(int i=0;i<topColumns.size();i++){
			
			Column c = (Column )topColumns.get(i);
			System.out.println("TOP--"+c.getColumnId());
			List allSubColumns = cs.listSublings(c);
			System.out.println("ALLSUB--"+allSubColumns);
			StringBuffer treeString = cs.getTreeString(url,c,allSubColumns);
			ret.append(treeString);
			if(i!=topColumns.size()){
				ret.append(",");
			}
		}
		return ret;
	}
	/**
	 * @return Returns the channelDAO.
	 */
	public ChannelDAO getChannelDAO() {
		return channelDAO;
	}

	/**
	 * @param channelDAO
	 *            The channelDAO to set.
	 */
	public void setChannelDAO(ChannelDAO channelDAO) {
		this.channelDAO = channelDAO;
	}

}

⌨️ 快捷键说明

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