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

📄 researchcatesbean.java

📁 基于strurs架构+servlet+jsp+javabean架构科研管理系统
💻 JAVA
字号:
/*
 * Created on 2008-6-9
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package cn.edu.zucc.research.ejb.session.cate;

import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;

import javax.ejb.CreateException;
import javax.ejb.FinderException;
import javax.ejb.RemoveException;
import javax.ejb.SessionBean;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import cn.edu.zucc.research.model.ResearchCate;
import cn.edu.zucc.research.ejb.cmp.cate.*;
import cn.edu.zucc.research.exception.ResearchException;


/**
 *
 * <!-- begin-user-doc --> A generated session bean <!-- end-user-doc --> *
 <!-- lomboz.beginDefinition -->
 <?xml version="1.0" encoding="UTF-8"?>
 <lomboz:EJB xmlns:j2ee="http://java.sun.com/xml/ns/j2ee" xmlns:lomboz="http://lomboz.objectlearn.com/xml/lomboz">
 <lomboz:session>
 <lomboz:sessionEjb>
 <j2ee:display-name>ResearchCateS</j2ee:display-name>
 <j2ee:ejb-name>ResearchCateSEjb</j2ee:ejb-name>
 <j2ee:ejb-class>cn.edu.zucc.research.ejb.session.cate.ResearchCateSBean</j2ee:ejb-class>
 <j2ee:session-type>Stateless</j2ee:session-type>
 <j2ee:transaction-type>Container</j2ee:transaction-type>
 </lomboz:sessionEjb>
 </lomboz:session>
 </lomboz:EJB>
 <!-- lomboz.endDefinition -->
 *
 * <!-- begin-xdoclet-definition --> 
 * @ejb.bean name="ResearchCateS"	
 *           jndi-name="ResearchCateSEjb"
 *           type="Stateless" 
 *           transaction-type="Container"
 * 
 * <!-- end-xdoclet-definition --> 
 * @generated
 */
public abstract class ResearchCateSBean implements javax.ejb.SessionBean {

	private CateHome getHome()throws NamingException {
		return  (CateHome)getContext().lookup(cn.edu.zucc.research.ejb.cmp.cate.CateHome.JNDI_NAME);
		}

		private InitialContext getContext() throws NamingException {
		Hashtable props = new Hashtable();

		props.put(InitialContext.INITIAL_CONTEXT_FACTORY,
				"org.jnp.interfaces.NamingContextFactory");
		props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");

//		 This establishes the security for authorization/authentication
//		 props.put(InitialContext.SECURITY_PRINCIPAL,"username");
//		 props.put(InitialContext.SECURITY_CREDENTIALS,"password");

		InitialContext initialContext = new InitialContext(props);
		return initialContext;
		}
		
		public ResearchCate bean(String categoryId, String categoryName) {
			ResearchCate researchCate=new ResearchCate();
			researchCate.setCategoryId(categoryId);
			researchCate.setCategoryName(categoryName);
			return researchCate;
		}

/** * @ejb.interface-method *	view-type="remote" **/public synchronized List loadAll() throws ResearchException, CreateException{ 	List result= new ArrayList();
	try{		
		Collection ca=this.getHome().findAll();
		Iterator i=ca.iterator();
		while(i.hasNext()){
			Cate cate=(Cate)i.next();
			ResearchCate rcate=new ResearchCate();
			rcate.setCategoryId(cate.getCategoryId());
			rcate.setCategoryName(cate.getCategoryName());
			result.add(rcate);
		}
	}catch (RemoteException e) {
        e.printStackTrace();
    } catch (NamingException e) {
        e.printStackTrace();
    }catch (FinderException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
	return result; 
}
/** * @ejb.interface-method *	view-type="remote" **/public synchronized void mergeCate(ResearchCate researchCate) throws CreateException, ResearchException{ 	try{
		Cate ca=(Cate) this.getHome().findByPrimaryKey(researchCate.getCategoryId());
		//ca.setCategoryId(researchCate.getCategoryId()); 主键不能修改
		ca.setCategoryName(researchCate.getCategoryName());
	}catch (RemoteException e) {
        e.printStackTrace();
    } catch (NamingException e) {
        e.printStackTrace();
    }catch (FinderException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}/** * @ejb.interface-method *	view-type="remote" **/public synchronized void saveCate(ResearchCate researchCate) throws CreateException, FinderException{ 	try{		
		Cate ca=(Cate) this.getHome().create(researchCate.getCategoryId(),researchCate.getCategoryName());
	}catch (RemoteException e) {
        e.printStackTrace();
    } catch (NamingException e) {
        e.printStackTrace();
    }
}/** * @ejb.interface-method *	view-type="remote" **/public synchronized void deleteCate(ResearchCate researchCate) throws CreateException, ResearchException{ 	try{
		Cate c=(Cate) this.getHome().findByPrimaryKey(researchCate.getCategoryId());
		c.remove();
	}catch (RemoteException e) {
        e.printStackTrace();
    } catch (NamingException e) {
        e.printStackTrace();
    }catch (FinderException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (RemoveException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}/** * @ejb.interface-method *	view-type="remote" **/public synchronized ResearchCate readCate(String categoryId) throws CreateException, FinderException, RemoveException{ 	ResearchCate result=new ResearchCate();
	try{
		Cate c=(Cate)this.getHome().findByPrimaryKey(categoryId);
		//System.out.println("c--"+c.getCategoryId());
		result.setCategoryId(c.getCategoryId());
		//System.out.println("result--"+result.getCategoryId());
		result.setCategoryName(c.getCategoryName());
	}catch (RemoteException e) {
        e.printStackTrace();
    } catch (NamingException e) {
        e.printStackTrace();
    }catch (FinderException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
	return result;
}}

⌨️ 快捷键说明

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