繁体   English   中英

在Oracle中释放锁定时,在会话bean中选择更新查询

[英]When lock release in oracle select for update query in session 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;
    }

我的问题是,当从字段中释放锁时,我已经使用select进行更新查询了吗?

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.

事务边界是顶级ejb方法,因此2)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM