📄 adminsbean.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.admin;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.Statement;
import java.util.*;
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.ejb.cmp.admin.*;
import cn.edu.zucc.research.exception.ResearchException;
import cn.edu.zucc.research.model.AdminLogin;
/**
*
* <!-- 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>AdminS</j2ee:display-name>
<j2ee:ejb-name>AdminSEjb</j2ee:ejb-name>
<j2ee:ejb-class>cn.edu.zucc.research.ejb.session.admin.AdminSBean</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="AdminS"
* jndi-name="AdminSEjb"
* type="Stateless"
* transaction-type="Container"
*
* <!-- end-xdoclet-definition -->
* @generated
*/
public abstract class AdminSBean implements javax.ejb.SessionBean{
protected Connection conn = null;
protected Statement st = null;
private AdminHome getAdminHome() throws NamingException {
return (AdminHome) getContext().lookup(AdminHome.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");
InitialContext initialContext = new InitialContext(props);
return initialContext;
}
//把传输过来的数据封装成javaBean
/**
* @ejb.interface-method
* view-type="remote"
**/
public AdminLogin bean(String adminId, String adminName, String adminPass,String adminLevel,
String newPwd ,String checkPwd ){
AdminLogin admin = new AdminLogin();
admin.setAdminId(adminId);
admin.setAdminName(adminName);
admin.setAdminPass(adminPass);
admin.setAdminLevel(adminLevel);
admin.setNewPwd(newPwd);
admin.setCheckPwd(checkPwd);
return admin;
}
//核对登入信息
/**
* @throws ResearchException
* @throws NamingException
* @ejb.interface-method
* view-type="remote"
**/
public synchronized void checkAdmin(AdminLogin admin) throws ResearchException {
try {
Admin a = (Admin)this.getAdminHome().findByPrimaryKey(admin.getAdminId());
if(!admin.getAdminPass().equals(a.getAdminPass())){
throw new ResearchException("Password is wrong !");
}
}catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (FinderException e1) {
throw new ResearchException(admin.getAdminId()+" is not exist!");
}
}
//修改密码
/**
* @throws ResearchException
* @throws NamingException
* @ejb.interface-method
* view-type="remote"
**/
public synchronized void changePwd(AdminLogin admin) throws ResearchException {
try {
Admin a = (Admin)this.getAdminHome().findByPrimaryKey(admin.getAdminId());
if(admin.getAdminPass()==""||admin.getCheckPwd()==""||admin.getNewPwd()==""||
admin.getAdminPass()==null||admin.getCheckPwd()==null||admin.getNewPwd()==null){
throw new ResearchException("some informations are null!");
}
if(!a.getAdminPass().equals(admin.getAdminPass())){
throw new ResearchException("Old password is wrong!");
}
if(!admin.getNewPwd().equals(admin.getCheckPwd())){
throw new ResearchException("Checked password is wrong !");
}
a.setAdminPass(admin.getNewPwd());
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FinderException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//显示管理员信息
/**
* @throws NamingException
* @ejb.interface-method
* view-type="remote"
**/
public synchronized List AdminList() {
try {
Collection c = this.getAdminHome().findAll();
Iterator i = c.iterator();
List adminList = new ArrayList();
while(i.hasNext()){
Admin admin = (Admin)i.next();
AdminLogin a = new AdminLogin();
a.setAdminId(admin.getAdminId());
a.setAdminLevel(admin.getAdminLevel());
a.setAdminName(admin.getAdminName());
a.setAdminPass(admin.getAdminPass());
adminList.add(a);
}
return adminList;
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FinderException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
//查找用户是否存在
/**
* @throws NamingException
* @ejb.interface-method
* view-type="remote"
**/
public synchronized boolean adminExist(AdminLogin admin){
try {
Admin a = (Admin)this.getAdminHome().findByPrimaryKey(admin.getAdminId());
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FinderException e) {
return false;
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
//返回管理员信息
/**
* @throws NamingException
* @ejb.interface-method
* view-type="remote"
**/
public synchronized AdminLogin adminInfo(AdminLogin admin){
try {
Admin ad = (Admin)this.getAdminHome().findByPrimaryKey(admin.getAdminId());
AdminLogin a = new AdminLogin();
a.setAdminId(ad.getAdminId());
a.setAdminLevel(ad.getAdminLevel());
a.setAdminName(ad.getAdminName());
a.setAdminPass(ad.getAdminPass());
return a;
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FinderException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
//添加管理员信息
/**
* @throws ResearchException
* @throws NamingException
* @ejb.interface-method
* view-type="remote"
**/
public synchronized void adminAdd(AdminLogin admin)throws ResearchException {
try {
if(admin.getAdminId()==""||admin.getAdminLevel()==""||admin.getAdminName()==""||
admin.getAdminId()==null||admin.getAdminLevel()==null||admin.getAdminName()==null){
throw new ResearchException("some informations are null!");
}
Admin newA = this.getAdminHome().create(admin.getAdminId(),admin.getAdminName(),
admin.getAdminId(),admin.getAdminLevel());
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (CreateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//修改管理员信息
/**
* @throws NamingException
* @ejb.interface-method
* view-type="remote"
**/
public synchronized void updateAdmin(AdminLogin admin){
try {
Admin a = (Admin) this.getAdminHome().findByPrimaryKey(admin.getAdminId());
a.setAdminName(admin.getAdminName());
a.setAdminLevel(admin.getAdminLevel());
a.setAdminPass(admin.getAdminPass());
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FinderException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//删除管理员信息
/**
* @throws NamingException
* @ejb.interface-method
* view-type="remote"
**/
public synchronized void deleteAdmin(AdminLogin admin){
try {
Admin a = (Admin) this.getAdminHome().findByPrimaryKey(admin.getAdminId());
a.remove();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FinderException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoveException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//批量删除管理员信息
/**
* @throws NamingException
* @ejb.interface-method
* view-type="remote"
**/
public synchronized void deleteMoreAdmin(AdminLogin admin[]){
for(int i=0;i<admin.length;i++){
try {
Admin a = (Admin) this.getAdminHome().findByPrimaryKey(admin[i].getAdminId());
a.remove();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FinderException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoveException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
//初始化密码
/**
* @throws NamingException
* @ejb.interface-method
* view-type="remote"
**/
public synchronized void initAdmin(AdminLogin admin){
try {
Admin a = (Admin) this.getAdminHome().findByPrimaryKey(admin.getAdminId());
a.setAdminPass(a.getAdminId());
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FinderException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -