当oracle中的锁定释放选择会话bean中的更新查询时

时间:2012-03-29 11:51:04

标签: java oracle ejb

以下是我的会话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;
    }

我的问题是,当我从字段锁定释放时,我使用select for update query吗?

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.

1 个答案:

答案 0 :(得分:0)

事务边界是顶级的ejb方法,所以2)。