? //SqlMapClientBuilder的buildSqlMapClient(Reader reader)方法
public static SqlMapClient buildSqlMapClient(Reader reader) {
??? return new SqlMapConfigParser().parse(reader);
? }
? //SqlMapConfigParser的parse(Reader reader)方法
? public SqlMapClient parse(Reader reader) {
??? try {
????? usingStreams = false;
????? parser.parse(reader);//此處的parser是NodeletParser
????? return state.getConfig().getClient();
??? } catch (Exception e) {
????? throw new RuntimeException("Error occurred.? Cause: " + e, e);
??? }
? }
?在new SqlMapConfigParser()時就預先對配置文件xml的各個節點上要執行哪些事件做了定義(就是一些回調方法),放在NodeletParser對象的一個HashMap屬性里,真正調用這些方法是在nodeletParser.parse(reader)里完成的。
執行上述操作后會把配置文件的詳細屬性存儲到該SqlMapConfigParser對象的XmlParserState對象、XmlParserState對象持有的SqlMapConfiguration對象以及(SqlMapConfiguration持有的SqlMapClientImpl和SqlMapExecutorDelegate)。
SqlMapExecutor接口定義了CRUD等方法,SqlMapTransactionManager接口定義了跟事務相關的方法,SqlMapClient接口和SqlMapSession接口都繼承了SqlMapExecutor和SqlMapTransactionManager。只是SqlMapClient增加了opensession等方法,SqlMapSession接口只增加了一個方法close()。
SqlMapSessionImpl對象和SqlMapClientImpl對象持有共同的委托對象SqlMapExecutorDelegate delegate.并且利用此委托對象實例化了一個sessionScope對象,然后對增刪改查的調用均委托對象執行處理并傳入這個跟線程綁定的sessionScope對象.
可在SqlMapConfig.xml里設置settings屬性,具體有哪些屬性,分別表示什么含義還不清楚。這些屬性在ibatis啟動后估計都保存在SqlMapExecutorDelegate對象里。
<settings
cacheModelsEnabled="false"
enhancementEnabled="false"
lazyLoadingEnabled="false"
/>
問題:
1,使用SqlMapClient的最佳實踐,應該用單例,并發如何處理
2,事務。單個操作不需要手動控制,如果是多個操作,先startTransaction,執行多個操作后commitTransaction,最后還要endTransaction
參考:
1,ibatis源碼簡析
2,實現ibatis的動態加載sqlmap配置文件
3,深入分析 iBATIS 框架之系統架構與映射原理
4,Spring集成ibatis問題
public static SqlMapClient buildSqlMapClient(Reader reader) {
??? return new SqlMapConfigParser().parse(reader);
? }
? //SqlMapConfigParser的parse(Reader reader)方法
? public SqlMapClient parse(Reader reader) {
??? try {
????? usingStreams = false;
????? parser.parse(reader);//此處的parser是NodeletParser
????? return state.getConfig().getClient();
??? } catch (Exception e) {
????? throw new RuntimeException("Error occurred.? Cause: " + e, e);
??? }
? }
?在new SqlMapConfigParser()時就預先對配置文件xml的各個節點上要執行哪些事件做了定義(就是一些回調方法),放在NodeletParser對象的一個HashMap屬性里,真正調用這些方法是在nodeletParser.parse(reader)里完成的。
執行上述操作后會把配置文件的詳細屬性存儲到該SqlMapConfigParser對象的XmlParserState對象、XmlParserState對象持有的SqlMapConfiguration對象以及(SqlMapConfiguration持有的SqlMapClientImpl和SqlMapExecutorDelegate)。
SqlMapExecutor接口定義了CRUD等方法,SqlMapTransactionManager接口定義了跟事務相關的方法,SqlMapClient接口和SqlMapSession接口都繼承了SqlMapExecutor和SqlMapTransactionManager。只是SqlMapClient增加了opensession等方法,SqlMapSession接口只增加了一個方法close()。
SqlMapSessionImpl對象和SqlMapClientImpl對象持有共同的委托對象SqlMapExecutorDelegate delegate.并且利用此委托對象實例化了一個sessionScope對象,然后對增刪改查的調用均委托對象執行處理并傳入這個跟線程綁定的sessionScope對象.
可在SqlMapConfig.xml里設置settings屬性,具體有哪些屬性,分別表示什么含義還不清楚。這些屬性在ibatis啟動后估計都保存在SqlMapExecutorDelegate對象里。
<settings
cacheModelsEnabled="false"
enhancementEnabled="false"
lazyLoadingEnabled="false"
/>
問題:
1,使用SqlMapClient的最佳實踐,應該用單例,并發如何處理
2,事務。單個操作不需要手動控制,如果是多個操作,先startTransaction,執行多個操作后commitTransaction,最后還要endTransaction
參考:
1,ibatis源碼簡析
2,實現ibatis的動態加載sqlmap配置文件
3,深入分析 iBATIS 框架之系統架構與映射原理
4,Spring集成ibatis問題