【Java开源代码栏目提醒】:网学会员,鉴于大家对Java开源代码十分关注,论文会员在此为大家搜集整理了“ChannelService.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;
}
}
上一篇:
ChannelDAOImpl.java
下一篇:
关联分类方法在铝电解中的应用研究