Methods Summary |
---|
public void | ejbActivate()
|
public ShipPK | ejbCreate(int id, java.lang.String name, int capacity, double tonnage)
this.id = id;
this.name = name;
this.capacity = capacity;
this.tonnage = tonnage;
Connection con = null;
PreparedStatement ps = null;
try {
con = getConnection();
ps = con.prepareStatement(
"insert into Ship (id, name, capacity, tonnage) " +
"values (?,?,?,?)");
ps.setInt(1, id);
ps.setString(2, name);
ps.setInt(3,capacity);
ps.setDouble(4,tonnage);
if (ps.executeUpdate() != 1) {
throw new CreateException ("Failed to add Ship to database");
}
ShipPK primaryKey = new ShipPK();
primaryKey.id = id;
return primaryKey;
}
catch (SQLException se) {
throw new CreateException (se.getMessage());
}
finally {
try {
if (ps != null) ps.close();
if (con!= null) con.close();
}catch(SQLException se){
se.printStackTrace();
}
}
|
public ShipPK | ejbCreate(int id, java.lang.String name)
return ejbCreate(id,name,0,0);
|
public java.util.Enumeration | ejbFindByCapacity(int capacity)
Connection con = null;
PreparedStatement ps = null;
ResultSet result = null;
try {
con = getConnection();
ps = con.prepareStatement(
"select id from Ship where capacity = ?");
ps.setInt(1,capacity);
result = ps.executeQuery();
Vector keys = new Vector();
while(result.next()){
ShipPK shipPk = new ShipPK();
shipPk.id = result.getInt("id");
keys.addElement(shipPk);
}
if(keys.size() > 0 )
return keys.elements();
else
return null;
}
catch (SQLException se) {
throw new FinderException (se.getMessage());
}
finally {
try {
if (result != null) result.close();
if (ps != null) ps.close();
if (con!= null) con.close();
}catch(SQLException se){
se.printStackTrace();
}
}
|
public ShipPK | ejbFindByPrimaryKey(ShipPK primaryKey)
loadUsingId(primaryKey.id);
return primaryKey;
|
public void | ejbLoad()
try{
ShipPK pk = (ShipPK) context.getPrimaryKey();
loadUsingId(pk.id);
}catch(FinderException fe)
{
throw new RemoteException("Cannot load Ship (id = "+
id+") state from database");
}
|
public void | ejbPassivate()
|
public void | ejbPostCreate(int id, java.lang.String name, int capacity, double tonnage)
// do something useful with the primary key
|
public void | ejbPostCreate(int id, java.lang.String name)
// do something useful with the EJBObject reference
|
public void | ejbRemove()
Connection con = null;
PreparedStatement ps = null;
try {
con = getConnection();
ps = con.prepareStatement("delete from Ship where id = ?");
ps.setInt(1, id);
if (ps.executeUpdate() != 1) {
throw new RemoteException (
"Failed to remove Ship from database");
}
}
catch (SQLException se) {
throw new RemoteException (se.getMessage());
}
finally {
try {
if (ps != null) ps.close();
if (con!= null) con.close();
}catch(SQLException se){
se.printStackTrace();
}
}
|
public void | ejbStore()
Connection con = null;
PreparedStatement ps = null;
try {
con = getConnection();
ps = con.prepareStatement(
"update Ship set name = ?, capacity = ?, " +
"tonnage = ? where id = ?");
ps.setString(1,name);
ps.setInt(2,capacity);
ps.setDouble(3,tonnage);
ps.setInt(4,id);
if (ps.executeUpdate() != 1) {
throw new RemoteException ("Failure occurred saving the Ship");
}
}
catch (SQLException se) {
throw new RemoteException (se.getMessage());
}
finally {
try {
if (ps != null) ps.close();
if (con!= null) con.close();
}catch(SQLException se){
se.printStackTrace();
}
}
|
public int | getCapacity()
return capacity;
|
private java.sql.Connection | getConnection()
Properties environmentProps = context.getEnvironment();
String url = environmentProps.getProperty("jdbcURL");
return DriverManager.getConnection(url);
|
public java.lang.String | getName()
return name;
|
public double | getTonnage()
return tonnage;
|
private void | loadUsingId(int id)
Connection con = null;
PreparedStatement ps = null;
ResultSet result = null;
try {
con = getConnection();
ps = con.prepareStatement(
"select name, capacity, tonnage from Ship where id = ?");
ps.setInt(1,id);
result = ps.executeQuery();
if(result.next()){
this.id = id;
name = result.getString("name");
capacity = result.getInt("capacity");
tonnage = result.getDouble("tonnage");
}else{
throw new ObjectNotFoundException(
"Cannot find Ship with id = "+id);
}
}
catch (SQLException se) {
throw new FinderException (se.getMessage());
}
finally {
try {
if (result != null) result.close();
if (ps != null) ps.close();
if (con!= null) con.close();
}catch(SQLException se){
se.printStackTrace();
}
}
|
public void | setCapacity(int cap)
capacity = cap;
|
public void | setEntityContext(javax.ejb.EntityContext ctx)
context = ctx;
|
public void | setName(java.lang.String n)
name = n;
|
public void | setTonnage(double tons)
tonnage = tons;
|
public void | unsetEntityContext()
context = null;
|