Methods Summary |
---|
public void | ejbActivate()
|
public java.lang.Long | ejbCreate(java.lang.Long newId)
pat_no = newId;
homeAddress.addressType = "Home";
workAddress.addressType = "Work";
return newId;
|
public java.lang.Long | ejbFindByPrimaryKey(java.lang.Long primaryKey)
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
con = getConnection(); // local method for JNDI Lookup
ps = con.prepareStatement("select pat_no from patient where pat_no = ?");
ps.setLong(1, primaryKey.longValue());
rs = ps.executeQuery();
if(!rs.next())
throw (new ObjectNotFoundException("Patient does not exist"));
} catch (SQLException e) {
throw new EJBException(e);
} finally {
try {
if(rs != null) rs.close();
if(ps != null) ps.close();
if(con != null) con.close();
} catch (SQLException e) {}
}
// We found it, so return it
return primaryKey;
|
public void | ejbLoad()
Long load_pat_no = (Long)context.getPrimaryKey();
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
con = getConnection(); // local method for JNDI Lookup
ps = con.prepareStatement("select * from patient where pat_no = ?");
ps.setLong(1, load_pat_no.longValue());
rs = ps.executeQuery();
if(!rs.next())
throw (new EJBException("Unable to load patient information"));
pat_no = new Long(rs.getLong("pat_no"));
fname = rs.getString("fname");
lname= rs.getString("lname");
ps.close();
rs.close();
ps = con.prepareStatement(
"select * from patient_address where pat_no = ? and address_label in " +
"('Home', 'Work')");
ps.setLong(1, load_pat_no.longValue());
rs = ps.executeQuery();
// Load any work or home
while(rs.next()) {
String addrType = rs.getString("ADDRESS_LABEL");
if("Home".equals(addrType)) {
homeAddress.address1 = rs.getString("addr1");
homeAddress.address2 = rs.getString("addr2");
homeAddress.city = rs.getString("city");
homeAddress.province = rs.getString("province");
homeAddress.postcode = rs.getString("postcode");
} else if ("Work".equals(addrType)) {
workAddress.address1 = rs.getString("addr1");
workAddress.address2 = rs.getString("addr2");
workAddress.city = rs.getString("city");
workAddress.province = rs.getString("province");
workAddress.postcode = rs.getString("postcode");
}
}
} catch (SQLException e) {
throw new EJBException(e);
} finally {
try {
if(rs != null) rs.close();
if(ps != null) ps.close();
if(con != null) con.close();
} catch (SQLException e) {}
}
|
public void | ejbPassivate()
|
public void | ejbPostCreate(java.lang.Long newId)
|
public void | ejbRemove()
|
public void | ejbStore()
|
private java.sql.Connection | getConnection()
try {
Context jndiContext = new InitialContext();
DataSource ds = (DataSource)jndiContext.lookup("java:comp/env/jdbc/PatientDS");
return ds.getConnection();
} catch (NamingException ne) {
throw new SQLException (ne.getMessage());
}
|
public Address | getHomeAddress()
return homeAddress;
|
public Address | getWorkAddress()
return workAddress;
|
private void | setAddress(Address target, Address source)
target.address1 = source.address1;
target.address2 = source.address2;
target.city = source.city;
target.province = source.province;
target.postcode = source.postcode;
|
public void | setEntityContext(EntityContext entityContext)
|
public void | setHomeAddress(Address addr)
setAddress(homeAddress, addr);
|
public void | setWorkAddress(Address addr)
setAddress(workAddress, addr);
|
public void | unsetEntityContext()
|