2012-03-29 1 views
0

Nach ist die Methode in meinem Session-BeanWenn Entriegelung in Oracle wählt für Update-Abfrage in Session-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; 
    } 

Meine Frage ist, wie ich für Update-Abfrage, wenn Sperrfreigabe von Feld wählen habe?

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. 

Antwort

0

Die Transaktionsgrenze ist die oberste Ebene, ejb-Methode, also 2).