【Java开源代码栏目提醒】:网学会员--在 Java开源代码编辑为广大网友搜集整理了:ApplicantBean.java绩等信息,祝愿广大网友取得需要的信息,参考学习。
package data;
import java.rmi.*;
import java.sql.*;
import java.util.*;
import javax.ejb.*;
import javax.naming.*;
import javax.sql.*;
public class ApplicantBean implements EntityBean
{
private DataSource dataSource;
private SkillLocalHome skillHome;
private LocationLocalHome locationHome;
private String login;
private String name;
private String email;
private String summary;
private LocationLocal location;
// vector attribute; List of SkillLocal ref's.
private List skills;
public String getLogin () {
return login;
}
public String getName () {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail () {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getSummary () {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public LocationLocal getLocation () {
return location;
}
public void setLocation(LocationLocal location) {
this.location = location;
}
/** returns (copy of) the list of skills. */
public Collection getSkills () {
return new ArrayList(this.skills);
}
public void setSkills(Collection skills) {
// just validate that the collection holds references to SkillLocal's
for(Iterator iter = getSkills().iterator(); iter.hasNext(); ) {
SkillLocal skill = (SkillLocal)iter.next();
}
// replace the list of skills with that defined.
this.skills = new ArrayList(skills);
}
// EJB methods start here
public void ejbPostCreate (String login, String name, String email) {}
public String ejbCreate (String login, String name, String email) throws CreateException {
try {
// workaround; should call ejbHome.findByPrimaryKey, but
// ctx.getEJBHome() returns null...
/*
ApplicantLocalHome applicantHome = (ApplicantLocalHome)ctx.getEJBHome();
System.out.println("ApplicantHome = " + applicantHome + ", login = " + login);
applicantHome.findByPrimaryKey(login);
*/
ejbFindByPrimaryKey(login);
throw new CreateException("Duplicate applicant name: "+login);
}
catch (FinderException ex) {}
Connection con = null;
PreparedStatement stmt = null;
try {
con = dataSource.getConnection();
stmt = con.prepareStatement(
"INSERT INTO Applicant (login,name,email) VALUES (?,?,?)");
stmt.setString(1, login);
stmt.setString(2, name);
stmt.setString(3, email);
stmt.executeUpdate();
}
catch (SQLException e) {
error("Error creating applicant "+login,e);
}
finally {
closeConnection(con, stmt, null);
}
this.login = login;
this.name = name;
this.email = email;
this.summary = null;
this.location = null;
this.skills = new ArrayList();
return login;
}
public String ejbFindByPrimaryKey(String login) throws FinderException {
Connection con = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
con = dataSource.getConnection();
stmt = con.prepareStatement(
"SELECT login FROM Applicant WHERE login = ?");
stmt.setString(1, login);
rs = stmt.executeQuery();
if (!rs.next()) {
throw new FinderException("Unknown applicant: "+login);
}
return login;
}
catch (SQLException e) {
error("Error in findByPrimaryKey for "+login,e);
}
finally {
closeConnection(con, stmt, rs);
}
return null;
}
public Collection ejbFindAll() throws FinderException {
Connection con = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
con = dataSource.getConnection();
stmt = con.prepareStatement(
"SELECT login FROM Applicant ORDER By login");
rs = stmt.executeQuery();
Collection col = new ArrayList();
while (rs.next()) {
col.add(rs.getString(1));
}
return col;
}
ca