Distributed Transaction
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   karthik_murugesan
Posted On:   Wednesday, February 13, 2002 01:02 AM

Hello All, I would like to ask to one question regarding your connection pooling. Please check the following code: The getConnection method returns me the free connections from my pool. Since I already have a connection to Database in the same transaction context, should the second getConnection throw any error or return a new connection. Or should I return the same connection forever till the transaction is committed. please tell me what application servers general do for this in CMP? public Integer ejbCreate(String name) throws javax.ejb.CreateException{ try{ StringTokenizer st = new StringTokenizer(name, " "); firstName = st.nextToken(); lastName    More>>

Hello All,
I would like to ask to one question regarding your connection pooling.

Please check the following code:
The getConnection method returns me the free connections from my pool. Since I already have a connection to Database in the same transaction context, should the second getConnection throw any error or return a new connection. Or should I return the same connection forever till the transaction is committed.
please tell me what application servers general do for this in CMP?



public Integer ejbCreate(String name) throws javax.ejb.CreateException{
try{
StringTokenizer st = new StringTokenizer(name, " ");
firstName = st.nextToken();
lastName = st.nextToken();
Connection con = getConnection();
PreparedStatement stmt = con.prepareStatement("insert into EmployeeTable (EmployeeID, FirstName, LastName) values (?,?,?)");
stmt.setInt(1, newPrimaryKey++);
stmt.setString(2, firstName);
stmt.setString(3, lastName);
stmt.executeUpdate();
con=getConnection();
stmt = con.prepareStatement("select EmployeeID from EmployeeTable where FirstName = ? AND LastName = ?");
stmt.setString(1, firstName);
stmt.setString(2, lastName);
ResultSet set = stmt.executeQuery();
while(set.next())
primaryKey = set.getInt("EmployeeID");
stmt.close();
con.close();
return new Integer(primaryKey);
}catch(Exception e){
e.printStackTrace();
throw new javax.ejb.CreateException("can't create");
}
}


How do the connections in a transaction in server 1 is associated to the same transaction in server 2.How can I get the same connection in the server 2. Does the propagation Context holds all the connections serialized and sent to server 2.


Karthik

   <<Less
About | Sitemap | Contact