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

📄 projectbo.java

📁 icome
💻 JAVA
字号:
package com.icome.bo;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import com.icome.dao.*;
import com.icome.entity.*;
import com.icome.dalfactory.*;

public class ProjectBO {
	
	private static final ProjectDAO projectdao = DataAccess.createProjectDAO();
	
	public  boolean  save(Project transientInstance)
	{
		try{
			projectdao.save(transientInstance);
			return true;
		}catch(Exception e)
		{
			return false;
		}
	}
	
	public boolean delete(Project persistentInstance)
	{
		try{
			projectdao.delete(persistentInstance);
			return true;
		}catch(Exception e)
		{
			return false;
		}
	}
	
	public Project retrieve(int pid)
	{
		try{
			return projectdao.findById(pid);
		}catch(Exception e)
		{
			return null;
		}
	}
	
	/**
	 * Get The projects List By the State
	 * @param state
	 * @return Linked list of the projects of State <param:state>
	 */
	public LinkedList  getProjectsByState(Integer state)
	{
		try
		{
			LinkedList list = new LinkedList(projectdao.findByState(state));
			return list;
		}catch(Exception e)
		{
			e.printStackTrace();
			return null;
		}
	}
	
	/**
	 * the parameter of the standard is Integer 0
	 * @return  LinkedList of the active projects
	 */
	public LinkedList  getActiveProjects()
	{
		Integer state = new Integer(0);
		
		return  this.getProjectsByState(state);
		
	}
	
	/**
	 * the state flag of finished 
	 * projects is Integer 1 
	 * @return the finished projects 
	 */
	public LinkedList getFinishedProjects()
	{
		Integer state = new Integer(1);
		
		return this.getProjectsByState(state);
		
	}
	
	/**
	 * Save the project using the parameter transisted
	 * @param name
	 * @param developer
	 * @param about
	 * @param state
	 * @param manager
	 * @return the pid of the updated Project 
	 * @return 0 if save failed
	 */
	public int saveProject(String name,String developer,String about,
			              int state, String manager,int pid)
	{
		if(manager==null)  return 0;
		
		Project transientInstance = null;
		
		if(pid!=0)
		{
			transientInstance=this.retrieve(pid);
		}
		
		if(transientInstance == null)
		{
			transientInstance = new Project();
			transientInstance.setCdt(new Date());
		}
		
		Account managerAccount = null;
	    AccountBO accountbo = new AccountBO();
	    managerAccount  = accountbo.retrieve(manager);
	    
		if(managerAccount==null)
		{
			return 0;
		}
		
		transientInstance.setAccount(managerAccount);
		transientInstance.setName(name);
		transientInstance.setDeveloper(developer);
		transientInstance.setAbout(about);
		
		if(this.save(transientInstance)) 
		{
			return transientInstance.getPid();
		}
		else
		{
			return 0;
		}
	}
}

⌨️ 快捷键说明

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