?? teachersbean.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.teacher;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
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.ejb.cmp.admin.Admin;
import cn.edu.zucc.research.ejb.cmp.teacher.Teacher;
import cn.edu.zucc.research.ejb.cmp.teacher.TeacherHome;
import cn.edu.zucc.research.exception.ResearchException;
import cn.edu.zucc.research.model.AdminLogin;
import cn.edu.zucc.research.model.TeacherLogin;
/**
*
* <!-- 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>TeacherS</j2ee:display-name>
<j2ee:ejb-name>TeacherSEjb</j2ee:ejb-name>
<j2ee:ejb-class>cn.edu.zucc.research.ejb.session.teacher.TeacherSBean</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="TeacherS"
* jndi-name="TeacherSEjb"
* type="Stateless"
* transaction-type="Container"
*
* <!-- end-xdoclet-definition -->
* @generated
*/
public abstract class TeacherSBean implements javax.ejb.SessionBean {
protected Connection conn = null;
protected Statement st = null;
private TeacherHome getTeacherHome() throws NamingException {
return (TeacherHome) getContext().lookup(TeacherHome.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 TeacherLogin bean(String userId, String userName, String userPass,Date registerDate,
String newPwd ,String checkPwd ){
TeacherLogin teacher = new TeacherLogin();
teacher.setUserId(userId);
teacher.setUserName(userName);
teacher.setUserPass(userPass);
teacher.setCheckpwd(checkPwd);
teacher.setNewpwd(newPwd);
return teacher;
}
//核對登入信息
/**
* @ejb.interface-method
* view-type="remote"
**/
public synchronized void checkLogin(TeacherLogin teacher)throws ResearchException {
try {
Teacher t = (Teacher)this.getTeacherHome().findByPrimaryKey(teacher.getUserId());
if(!teacher.getUserPass().equals(t.getUserPass())){
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(teacher.getUserId()+" is not exist!");
}
}
//查找用戶是否存在 ,存在返回true
/**
* @ejb.interface-method
* view-type="remote"
**/
public synchronized boolean userExist(TeacherLogin teacher){
try {
Teacher t = (Teacher)this.getTeacherHome().findByPrimaryKey(teacher.getUserId());
} 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 ResearchException
* @ejb.interface-method
* view-type="remote"
**/
public synchronized void usersetpwd(TeacherLogin teacher) throws ResearchException{
try {
if(!teacher.getNewpwd().equals(teacher.getCheckpwd())){
throw new ResearchException("The checked password is wrong!");
}
Teacher t = (Teacher)this.getTeacherHome().findByPrimaryKey(teacher.getUserId());
t.setUserPass(teacher.getCheckpwd());
} 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 ResearchException
* @ejb.interface-method
* view-type="remote"
**/
public synchronized void changePwd(TeacherLogin teacher) throws ResearchException{
try {
if(teacher.getCheckpwd()==""||teacher.getNewpwd()==""||teacher.getUserPass()==""||
teacher.getCheckpwd()==null||teacher.getNewpwd()==null||teacher.getUserPass()==null){
throw new ResearchException("some informations are null!");
}
if(!teacher.getNewpwd().equals(teacher.getCheckpwd())){
throw new ResearchException("The checked password is wrong!");
}
Teacher t = (Teacher)this.getTeacherHome().findByPrimaryKey(teacher.getUserId());
if(!t.getUserPass().equals(teacher.getUserPass())){
throw new ResearchException("The old password is wrong!");
}
t.setUserPass(teacher.getCheckpwd());
} 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();
}
}
//刪除用戶信息
/**
* @ejb.interface-method
* view-type="remote"
**/
public synchronized void deleteTeacher(TeacherLogin teacher) {
try {
Teacher t = (Teacher)this.getTeacherHome().findByPrimaryKey(teacher.getUserId());
t.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();
}
}
//批量刪除用戶信息
/**
* @ejb.interface-method
* view-type="remote"
**/
public synchronized void deleteMoreTeacher(TeacherLogin teacher[]) {
for(int i=0;i<teacher.length;i++){
Teacher t;
try {
t = (Teacher)this.getTeacherHome().findByPrimaryKey(teacher[i].getUserId());
t.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();
}
}
}
//初始化密碼
/**
* @ejb.interface-method
* view-type="remote"
**/
public synchronized void initUserPwd(TeacherLogin teacher){
try {
Teacher t = (Teacher) this.getTeacherHome().findByPrimaryKey(teacher.getUserId());
t.setUserPass(t.getUserId());
} 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();
}
}
//添加用戶帳號
/**
* @ejb.interface-method
* view-type="remote"
**/
public synchronized void addteacher(TeacherLogin teacher){
try {
this.getTeacherHome().create(teacher.getUserId(),teacher.getUserName(),
teacher.getUserPass(),teacher.getRegisterDate());
} 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();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -