2012-03-29 45 views
0

以下是我的會話bean的方法當甲骨文解鎖選擇在會話Bean更新查詢

public pin() {// session bean method with @@ejb.transaction type="Requires" 

    update() 
} 

private update(){ 

    query = select id from test for update where id = 'ttt' for update; 
    execute(strSelectQuery); 
} 

public ResultObject execute(String statement) { 
     ResultObject ro = new ResultObject(0,null); 
     if(ds == null){ 
      try { 
       InitialContext ctx = new javax.naming.InitialContext(); 
       ds = (javax.sql.DataSource) ctx.lookup(getDataSourceName()); 
       debugLog("Got ds"); 
      } catch(NamingException e) { 
       ro.setResponseCode(-1); 
       e.printStackTrace(); 
      } 
     } 

     OracleCachedRowSet rowSet = null; 
     if(!ro.isError()){ 
      Connection con = null; 
      PreparedStatement pstmt = null; 
      try{ 
       con = ds.getConnection(); 
       pstmt = con.prepareStatement(statement); 
       rowSet = new OracleCachedRowSet(); 
       debugLog("Query :"+ statement); 
       rowSet.populate(pstmt.executeQuery()); 
       rowSet.beforeFirst(); 
       ro.setResponseObject(rowSet); 
      }catch(SQLException e) { 
       errorLog("SqException "+e); 
       ro.setResponseCode(-1); 
       ro.setResponseObject("Error while firing query"); 
       e.printStackTrace(); 
      }finally{ 
       try{ 
        if(pstmt != null) pstmt.close(); 
        if(con != null) con.close(); 
       }catch(Exception e1){ 
        errorLog("Exception "+e1); 
        ro.setResponseCode(-1); 
        ro.setResponseObject("Error while firing query"); 
        e1.printStackTrace(); 
       } 
      } 
     } 
     return ro; 
    } 

我的問題是,因爲我有利用選擇更新查詢從現場時鎖定釋放?

1) When execute method exit ? (as it close connection open for select query). 
or 
2) When pin method exit as pin is session bean method. 

回答

0

事務邊界是頂級ejb方法,所以2)。