달력

32024  이전 다음

  • 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

Spring 가지고 놀다보니... JdbcDaoSupport 가 눈에 띤다..

자세한 내용은 Spring doc 를 참고하면 되고...   오늘 신경 거슬리게 만든것 하나..

 

Select Count(*) from tbl_xxx  <-- 이 쿼리 날려야 하는데..

도큐먼트에 SqlFunction 이라는 넘을 쓰면 된단다..

해보니... 잘 된다 ^^

 

그런데!!!!!!

 

Select Count(*) from tbl_xxx where xx > ? and yy < ?                 

이넘~!~! 안된다 ㅜㅜ

 

왜 안되지??

파람 넘겨주는 데가 없다.. 아무래도 PreparedStatement 를 생성하는것 같지 않다.

그래서리... API 찾아보니.. 허거걱...

queryForInt(String arg0, Object arg1)  <-- 요런넘이 있네 ^^

 

Object[] params = new Object[]{new Integer(xx), new Integer(yy)};

return getJdbcTemplate().queryForInt(query, params);

 

간단하게 끝남...

그냥 JDBC 코딩 하는것 보다.. 무지 편리함..

Transaction 처리도.. 설정에서 끝남...

    <!--  Transaction Manager -->
 <bean id="transactionManager"
     class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
     <property name="dataSource"><ref bean="dataSource"/></property>
 </bean>

 

   <bean id="xxxService"
     class = "org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager"><ref local="transactionManager" /></property>
    <property name="target"><ref local="xxxServiceTarget" /></property>
    <property name="transactionAttributes">
       <props>
       <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="list*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="create*">PROPAGATION_REQUIRED,-xxxException</prop>
    <prop key="read*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="update*">PROPAGATION_REQUIRED</prop> 
    <prop key="delete*">PROPAGATION_REQUIRED</prop>
       </props>
    </property>
   </bean> 

 

이런식으로... 트랜잭션 매니저 셋팅하고... 프락시 셋팅하고..

설정에서... - 표시로 익셉션을 발생시키면.. 된다..

 

근데.. DataSource 를 반드시 이용해야 하는데..

테스트 할때 proxool 을 사용했다...

데이터 소스 없다 ㅡㅡ

소스포지 가서 proxool cvs 보니... dev 에 테스트 있네 ㅡㅡ

소스 받아서 컴팔하고 해서 성공..

 

 

Posted by tornado
|