일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- WebLogic
- node.js
- jsr 296
- Android
- jQuery
- 가우스
- Struts
- phonegap
- Google Map
- GPS
- swingx
- MySQL
- 선택적조인
- JDOM
- ibsheet
- iBATIS
- MFC
- 전자정부프레임워크
- dock
- Spring
- PLSQL
- appspresso
- PHP
- Ajax
- JSON
- rowspan
- oracle
- tomcat
- Eclipse
- sencha touch
Archives
- Today
- Total
Where The Streets Have No Name
SQL strings out of Interface 본문
Step 1 : Mofify Spring-Config.xml
<import resource="Spring-DAO-SQL-Config.xml"/>
<bean id="EMP_DAO" class="com.bea.dev2dev.dao.EmployeeDAOImpl">
<property name="dataSource">
<ref bean="FIREBIRD_DATASOURCE"></ref>
</property>
<property name="sqlBean">
<ref bean="SQL_REPOSITORY"></ref>
</property>
</bean>
Step 2 : Include the Spring-DAO-SQL-Config.xml
<beans>
<!-- Configure SQL Cache Bean -->
<bean id="SQL_REPOSITORY" class="com.bea.dev2dev.dao.helper.SQLCacheBean">
<property name="sqlCache">
<props>
<prop key="FIND_BY_SAL_RNG">
<![CDATA[
SELECT
EMP_NAME,EMP_NO,SALARY
FROM
EMP
WHERE
SALARY >= :MIN_SALARY AND SALARY <=:MAX_SALARY
]]>
</prop>
<prop key="FIND_BY_EMP_PK">
SELECT
*
FROM
EMP
WHERE
EMP_NO = :EMP_NO
</prop>
</props>
</property>
</bean>
</beans>
Step 3 : Introduce AbsBaseDAO.java
Step 5 : Remove the SQL string from the IEmployeeDAO interface
<import resource="Spring-DAO-SQL-Config.xml"/>
<bean id="EMP_DAO" class="com.bea.dev2dev.dao.EmployeeDAOImpl">
<property name="dataSource">
<ref bean="FIREBIRD_DATASOURCE"></ref>
</property>
<property name="sqlBean">
<ref bean="SQL_REPOSITORY"></ref>
</property>
</bean>
Step 2 : Include the Spring-DAO-SQL-Config.xml
<beans>
<!-- Configure SQL Cache Bean -->
<bean id="SQL_REPOSITORY" class="com.bea.dev2dev.dao.helper.SQLCacheBean">
<property name="sqlCache">
<props>
<prop key="FIND_BY_SAL_RNG">
<![CDATA[
SELECT
EMP_NAME,EMP_NO,SALARY
FROM
EMP
WHERE
SALARY >= :MIN_SALARY AND SALARY <=:MAX_SALARY
]]>
</prop>
<prop key="FIND_BY_EMP_PK">
SELECT
*
FROM
EMP
WHERE
EMP_NO = :EMP_NO
</prop>
</props>
</property>
</bean>
</beans>
Step 3 : Introduce AbsBaseDAO.java
package com.bea.dev2dev.dao.helper;Step 4 : Modify the DAO Implementation class it now extends the AbsBaseDAO
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcDaoSupport;
/**
*
* @author Dhrubo
*/
public class AbsBaseDAO extends NamedParameterJdbcDaoSupport{
private SQLCacheBean sqlCache;
public void setSqlBean(SQLCacheBean sqlCache)
{
this.sqlCache = sqlCache;
}
public String getSQL(String key)
{
return sqlCache.getSQL(key);
}
}
public class EmployeeDAOImpl extends AbsBaseDAO implements IEmployeeDAO{
public List findBySalaryRange(Map salaryMap){
NamedParameterJdbcTemplate daoTmplt = getNamedParameterJdbcTemplate();
return daoTmplt.query(getSQL("FIND_BY_SAL_RNG"),salaryMap,new EmployeeTOMapper());
}
}
Step 5 : Remove the SQL string from the IEmployeeDAO interface