0

ibatis-sqlmap-2.3.4 を読むと、どちらも SqlMapExecutor を実装していることがわかりました。

SqlMapClientImpl は、スレッド セーフを提供する localSqlMapSession を挿入します。

しかし、spring2.5.6 では、SqlMapClientTemplate の execute メソッドは、次のように SqlMapClientImpl を使用します。

  SqlMapSession session = this.sqlMapClient.openSession();
  ...
  return action.doInSqlMapClient(session);

openSession メソッドは、毎回新しい SqlMapSessionImpl を返します。

私の質問は次のとおりです。

SqlMapClientTemplate が sqlMapClient の代わりに sqlMapSeesion を使用するのはなぜですか?

sqlMapClient の localSqlMapSession が SqlMapClientTemplate で使用されないのはなぜですか? 次のように使用します。

 return action.doInSqlMapClient(this.sqlMapClient);

SqlMapClient と SqlMapSeesion の違いは何ですか?

4

1 に答える 1

3

最初の質問については、コメントで spring-orm を説明してください。

// We always need to use a SqlMapSession, as we need to pass a Spring-managed
// Connection (potentially transactional) in. This shouldn't be necessary if
// we run against a TransactionAwareDataSourceProxy underneath, but unfortunately
// we still need it to make iBATIS batch execution work properly: If iBATIS
// doesn't recognize an existing transaction, it automatically executes the
// batch for every single statement...

Ibatis の SqlMapClient と SqlMapSession の違いに対する答えは、インターフェイス SqlMapClient のコメントにあります。

/**
* Returns a single threaded SqlMapSession implementation for use by
* one user.  Remember though, that SqlMapClient itself is a thread safe SqlMapSession
* implementation, so you can also just work directly with it.  If you do get a session
* explicitly using this method <b>be sure to close it!</b>  You can close a session using
* the sqlMapSession.close() method.
* <p/>
*
* @return An SqlMapSession instance.
*/
public SqlMapSession openSession();
于 2012-08-24T18:38:43.600 に答える