Using setUserConnection will work.   It's thread safe, so don't worry about concurrent access.  Just make sure to "unset" it by calling setUserConnection (null) -- which reminds me, we should add a clearUserConnection() to make this code nicer.

The other way to do it is with openSession (Connection conn).  But I don't see a reason for you to do that here.

As for accessing the SQL statements themselves -- be warned, it will not be easy.  iBATIS 2.0 does a lot more to keep you away from the guts of the framework to avoid upgrade issues...as you're experiencing now.  ;-)

Let us know when you get to that point, we'll see what we can do.

public final List getList(DbConnection dbCon, String mapKey, Object param)
    throws DatabaseException { 
  boolean handleTransactionLocally = false;

  try {
    if (dbCon == null) {
      handleTransactionLocally = true;
      dbCon = connectionFactory.getConnectio n();
      dbCon.setReadOnlyConnection(true);
    }
    sqlMap.setUserConnection (dbCon.getConnection());
    return sqlMap.queryForList(mapKey, param);
  } catch (SQLException e) {
    // log.error("Error during sql: " + e.getMessage(), e);

    ExceptionAdaptor.instance(exceptionAdaptorKey).getMappe dException(e,
      "getList: " + e.getMessage(), true, ExceptionAdaptor.ACTION_SEARCH, param);
  } finally {
    sqlMap.setUserConnection(null);

    if (dbCon != null) {
      dbCon.closeAll(handleTransactionLocally);
    }
  }

}

Clinton




On 8/16/06, David Gagnon <[EMAIL PROTECTED]> wrote:
Hi all,

I'm having a lot of fun trying to convert my code to 2.1.7.  There is
still a lot of things I didn`t figured out yet.

Can you please tell me how to convert the following function.?


    public final List getList(DbConnection dbCon, String mapKey, Object
param) throws DatabaseException {

        List list = null;
        boolean handleTransactionLocally = false;
        try {
            if (dbCon == null) {
                handleTransactionLocally = true;
                dbCon = connectionFactory.getConnection();
                dbCon.setReadOnlyConnection(true);
            }

            MappedStatement statement = sqlMap.getMappedStatement(mapKey);
            list = statement.executeQueryForList(dbCon.getConnection(),
param);
        } catch (SQLException e) {
//            log.error("Error during sql: " + e.getMessage(), e);

ExceptionAdaptor.instance(exceptionAdaptorKey).getMappedException(e,
"getList: " + e.getMessage(), true, ExceptionAdaptor.ACTION_SEARCH, param);
        } finally {
            if (dbCon != null) {
                dbCon.closeAll(handleTransactionLocally);
            }
        }
        return list;
    }



I saw a sqlMap.setUserConnection() but this method can be called by
simultaneously so setting the connection in the sqlMap doesn`t make
sense to me.  There is probably something that I don`t understand!

Please help :-)

Best Regards.
/David
P.S.: Also I do need to get the SQL string from a map to play with it
myself.  I'm not there yet but I hope there a way to get it!  Thanks





Reply via email to