Eclipse rap 富用戶端開發總結(11) -rcp/rap與spring ibatis整合

來源:互聯網
上載者:User

註: Eclipse rap 富用戶端開發總結-系列文章是從本人   Iteye部落格中移植過來.後續會直接在此更新     http://jlins.iteye.com/
1. rcp/rap 與 spring 整合

Activator 是rcp/rap 啟動時需要載入的類, 只需要載入一遍,所以與spring 整合的時候一般是在這個類裡面載入spring 的ApplicationContext

具體如下:

在 Activator 裡添加如下代碼:

private ApplicationContext context ;

this. context = new ClassPathXmlApplicationContext( "config/aplicationContext.xml" );

在 common.xml 中,載入如下資訊:

1.1           載入資料來源

舉例:

<bean id="dataSource"class="org.springframework.jdbc.datasource.DriverManagerDataSource"><property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property><property name="url" value="jdbc:oracle:thin:@xx.xx.xx.xx:xxxxxx"></property><property name="username" value="xxxx"></property><property name="password" value="xxxx"></property></bean>
1.2 載入 ibatis 的 sqlMapConfig

舉例:

<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"><property name="dataSource" ref="dataSource"></property><property name="configLocation" value="sqlMapConfig.xml"></property></bean>

1.3 載入與資料庫相關的:串連資料庫、關閉資料庫、釋放 ResultSet ,對資料庫的增刪改查等操作的類或設定檔

舉例:

<bean id="eeeDao" class="com.jlins.dao.xxxDao"><property name="sqlMapClient" ref="sqlMapClient"></property></bean>引入一些具體的設定檔<import resource="xxx/xxx.xml" />

2. rcp/rap 與 ibatis 整合

這個對象是iBatis 操作資料庫的介面(執行CRUD 等操作),它也可以執行交易管理等操作。這個類是我們使用iBATIS 的最主要的類。它是安全執行緒的。通常,將它定義為單例。(與hibernate 中sessionFactory 的定義類似)

SqlMapClient 提供了如下的一些功能:

顯式的調用事務。

執行對資料庫的常規操作。

批量處理非查詢的SQL 陳述式。

<sqlMapConfig><sqlMap resource="xxx.xml"/></sqlMapConfig>  其中xxxxxxx.xml定義了一些資料庫增刪改查如:<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE sqlMapPUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN""http://www.ibatis.com/dtd/sql-map-2.dtd"><sqlMap namespace="people"><typeAlias alias="person" type="Person" /><update id="updateNameById" parameterClass="person">updatepersonset name =#name#where id =#id# </update></sqlMap>

 

特殊的:如果傳入的參數是一個變數,比如如下這種情況,要在資料庫裡查詢一個序列,但是序列名不是一個常量,而是一個變數,這時候不能前後加# ,而用$ 符。

<select id="getSequenceValue"  resultMap="allResultMap"><![CDATA[select $seqName$.NEXTVAL||'' sequenceid  from dual   ]]></select>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.