I built sources PRE-2.1 from cvs on 12/3
The findByPrimaryKey method in my BMP implimentation is not being called
when I issue the call from the client. It appears that ejbLoad is
getting called instead.
It works fine in jBoss-2.0_FINAL. The findByPrimaryKey method gets
called but not the ejbStore.
In a possible unrelated observation, my beans are benig passivated with
id = null in jBoss-2.0_FINAL.
In PRE-2.1, passivated beans the have the id = primary key class id.
I was wondering if i'm doing something wrong.
below is one of my BMP bean implemntation
----------------------------------------------------------------------------------
ackage net.qspasp.ejbs.ar.tbh3lst;
import javax.ejb.*;
import javax.naming.Context;
import javax.sql.DataSource;
import javax.naming.InitialContext;
import java.rmi.*;
import java.sql.*;
import java.util.Collection;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import net.qspasp.ejbs.common.EntityBase;
public class Tbh3LstBean extends EntityBase implements EntityBean {
// Keep the reference on the EntityContext
private EntityContext entityContext;
//used in BMP
private Connection connection;
private DataSource dataSource;
//declare class level variables
private Tbh3LstPk pk;
private String cmpy;
private int btch_num;
public Tbh3LstPk ejbCreate(Map dbMap) throws RemoteException,
CreateException {
//set class level variables
this.cmpy = (String)dbMap.get("CMPY");
this.btch_num = ( (Integer)dbMap.get("BTCH_NUM") ).intValue();
PreparedStatement ps = null;
try {
connection = dataSource.getConnection();
String sql =
"INSERT INTO "
+ "TBH3LST("
+ "CMPY,"
+ "BTCH_NUM) "
+ "Values("
+ "'" + cmpy + "',"
+ " " + btch_num + " )";
log(sql);
ps = connection.prepareStatement(sql);
if (ps.executeUpdate() != 1) {
String err = "No row created in the database!";
log(err);
throw new CreateException (err);
}
} catch (SQLException sqe) {
throw new CreateException(sqe.getMessage());
} finally {
try {
ps.close();
connection.close();
} catch (Exception e) {e.printStackTrace();}
}
return new Tbh3LstPk(cmpy,btch_num);
}
/**
* Each ejbCreate method should have a matching ejbPostCreate method
*/
public void ejbPostCreate (Map dbMap) throws RemoteException {
}
/**
* Container calls to synchronize bean state by reading from
database
*/
public void ejbLoad() throws RemoteException {
if (this.modified == false)
return;
log("ejbLoad");
Tbh3LstPk pk = (Tbh3LstPk) entityContext.getPrimaryKey();
PreparedStatement ps = null;
//set class level variables to primary key values
this.cmpy = pk.cmpy;
this.btch_num = pk.btch_num;
try {
connection = dataSource.getConnection();
String sql =
"SELECT "
+ "CMPY, "
+ "BTCH_NUM "
+ "FROM TBH3LST "
+ "WHERE "
+ "CMPY= '" + pk.cmpy + "' "
+ "AND BTCH_NUM= " + pk.btch_num + " ";
log (sql);
ps = connection.prepareStatement(sql);
//set primary key in prepared statement
ps.executeQuery();
ResultSet rs = ps.getResultSet();
if (rs.next()) {
this.cmpy = rs.getString(1);
this.btch_num = rs.getInt(2);
} else {
String error = "ejbLoad: Tbh3LstBean not found";
log(error);
throw new RemoteException(error);
}
} catch (SQLException sqe) {
log("SQLException: " + sqe);
throw new EJBException(sqe);
} finally {
try {
ps.close();
connection.close();
} catch (Exception e) {e.printStackTrace();}
}
this.modified = false;
}
/**
* Container calls to synchronize bean state by storing data to
database
*/
public void ejbStore() throws RemoteException {
if (this.modified == false)
return;
log("ejbStore");
PreparedStatement ps = null;
try {
connection = dataSource.getConnection();
String sql =
"UPDATE TBH3LST "
+ "SET "
+ "CMPY='" + this.cmpy + "', "
+ "BTCH_NUM= " + this.btch_num + " "
+ "WHERE "
+ "CMPY= '" + this.cmpy + "' "
+ "AND BTCH_NUM= " + this.btch_num + " ";
log(sql);
ps = connection.prepareStatement(sql);
//set prepared statment variables
if (!(ps.executeUpdate() > 0)) {
String error = "ejbStore: Tbh3LstBean not updated";
log(error);
throw new RemoteException (error);
}
} catch(SQLException sqe) {
log("SQLException: " + sqe);
throw new EJBException (sqe);
} finally {
try {
ps.close();
connection.close();
} catch (Exception e) {e.printStackTrace();}
}
this.modified = false;
}
/**
* Container calls when client call remove for the bean
*/
public void ejbRemove() throws RemoteException, RemoveException {
log("ejbRemove");
PreparedStatement ps = null;
try {
connection = dataSource.getConnection();
Tbh3LstPk pk = (Tbh3LstPk) entityContext.getPrimaryKey();
//set class level variables to primary key values
this.cmpy = pk.cmpy;
this.btch_num = pk.btch_num;
String sql =
"DELETE FROM TBH3LST "
+ "WHERE "
+ "CMPY= '" + pk.cmpy + "' "
+ "AND BTCH_NUM= " + pk.btch_num + " ";
log(sql);
ps = connection.prepareStatement(sql);
//set prepared statement primary key values
if (!(ps.executeUpdate() > 0)) {
String error = "Tbh3LstBean not found";
log(error);
throw new RemoteException (error);
}
} catch (SQLException sqe) {
log("SQLException: " + sqe);
throw new EJBException (sqe);
} finally {
try {
ps.close();
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* Container calls retrive passivative bean from disk
*/
public void ejbActivate() throws RemoteException {
log("ejbActivate");
this.pk = (Tbh3LstPk)entityContext.getPrimaryKey();
}
/**
* Container calls store bean to disk
*/
public void ejbPassivate() throws RemoteException {
log("ejbPassivate");
pk = null;
}
/**
* Container calls pass bean EntityContext reference
*/
public void setEntityContext(EntityContext ctx) throws
RemoteException {
this.entityContext = ctx;
log("setEntityContext");
try {
Context namingContext = new InitialContext();
//java:comp/env/PoolName
dataSource = ((DataSource)
namingContext.lookup("java:/xa.QspDBPool"));
} catch (Exception e) {
e.printStackTrace();
System.out.println("Entity BMP Could not find the database
connection, check settings");
throw new RemoteException("Entity BMP Could not find the database
connection");
}
}
/**
* Container calls unset EntityContext reference
*/
public void unsetEntityContext() {
log("unsetEntityContext");
if (connection != null) {
try {
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
dataSource = null;
connection = null;
entityContext = null;
}
/************************************************************
* finder methods
************************************************************/
/**
* Find by a primary key
*/
public Tbh3LstPk ejbFindByPrimaryKey(Tbh3LstPk pk)
throws FinderException, RemoteException {
log("ejbFindByPrimaryKey");
PreparedStatement ps = null;
//set class level variables to primary key values
this.cmpy = pk.cmpy;
this.btch_num = pk.btch_num;
try {
connection = dataSource.getConnection();
String sql =
"SELECT "
+ "CMPY, "
+ "BTCH_NUM "
+ "FROM TBH3LST "
+ "WHERE "
+ "CMPY= '" + pk.cmpy + "' "
+ "AND BTCH_NUM= " + pk.btch_num + " ";
ps = connection.prepareStatement(sql);
//set primary key in prepared statement
log(sql);
ps.executeQuery();
ResultSet rs = ps.getResultSet();
if (rs.next()) {
//set class level variables
this.cmpy = rs.getString(1);
this.btch_num = rs.getInt(2);
log("ejbFindByPrimaryKey: found");
} else {
log("ejbFindByPrimaryKey: not found");
throw new FinderException();
}
} catch (SQLException sqe) {
log("SQLException: " + sqe);
throw new EJBException(sqe);
} finally {
try {
ps.close();
connection.close();
} catch (Exception e) {e.printStackTrace();}
}
this.modified = false;
return pk;
}
/************************************************************
* get methods
************************************************************/
public String getCmpy() throws RemoteException {
return cmpy.trim();
}
public int getBtch_num() throws RemoteException {
return btch_num;
}
/************************************************************
* set methods
************************************************************/
public void setCmpy(String cmpy) throws RemoteException {
this.cmpy = cmpy;
}
public void setBtch_num(int btch_num) throws RemoteException {
this.btch_num = btch_num;
}
public void setModified(boolean modified) throws RemoteException {
this.modified = modified;
}
}
--
--------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Problems?: [EMAIL PROTECTED]