ibatis对存储过程的调用

来源:互联网 发布:软件开发基础 编辑:程序博客网 时间:2024/05/21 10:46

IBatis映射文件:

[xhtml] view plaincopy
  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2. <!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >  
  3. <sqlMap namespace="BUSSINESS_B_T_PRODUCT" >  
  4.     
  5.   <parameterMap id="hasAuthParam" class="java.util.HashMap" >  
  6.     <parameter property="p_productCode" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/>  
  7.     <parameter property="p_customerId" jdbcType="NUMBER" javaType="java.lang.Long" mode="IN"/>  
  8.     <parameter property="p_callType" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/>  
  9.     <parameter property="p_total" jdbcType="NUMBER" javaType="java.lang.Long" mode="IN"/>  
  10.     <parameter property="result" jdbcType="INTEGER" javaType="java.lang.Integer" mode="INOUT"/>  
  11.   </parameterMap>  
  12.   
  13.   <procedure id="hasAuth" parameterMap="hasAuthParam" >  
  14.   <!--[CDATA[  
  15.       {call BUSINESSES_HAS_AUTH(?,?,?,?,?)}  
  16.   ]]-->  
  17.   </procedure>  
  18.     
  19. </sqlMap>  

 

DAO层代码:

[java] view plaincopy
  1. public Integer hasAuth(String productCode, Long customerId,String callType,Long total){  
  2.         Map<String,Object> map = new HashMap<String,Object>();  
  3.         map.put("p_productCode", productCode);  
  4.         map.put("p_customerId", customerId);  
  5.         map.put("p_callType", callType);  
  6.         map.put("p_total", total);  
  7.         map.put("result", -1);  
  8.         queryData("BUSSINESS_B_T_PRODUCT.hasAuth", map);  
  9.         Integer result = (Integer)map.get("result");  
  10.         System.out.println(result);  
  11.         return Integer.valueOf(result);  
  12.     }  

 

存储过程:

[java] view plaincopy
  1. CREATE OR REPLACE PROCEDURE GBOSS.BUSINESSES_HAS_AUTH  
  2. (p_productCode IN VARCHAR2, p_customerId IN number, p_callType IN VARCHAR2,p_total in number,result out integer)  
  3. is  
  4. v_count  integer;  
  5. v_stateCount integer;  
  6. v_seviceTypeState varchar(1);  
  7. v_outstanding C_T_CUSTOMER.OUTSTANDING%type;     
  8. v_billingModel C_T_CUSTOMER_PRODUCT.CP_BILLING_MODEL%type;  v_unitPrice C_T_CUSTOMER_PRODUCT.UNIT_PRICE%type;  
  9. v_cpId C_T_CUSTOMER_PRODUCT.CP_ID%type;            
  10. v_currConsu C_T_CUSTOMER_PRODUCT.Curr_Consu%type;    
  11. v_q C_T_BLXS_PRICING.q%type;      
  12. v_p2 C_T_BLXS_PRICING.P2%type;     
  13. BEGIN  
  14.   result:=0;                     
  15.   select count(1) into v_count from C_T_CUSTOMER_PRODUCT cp,B_T_PRODUCT p,C_T_SERVICE_TYPE t  
  16.   where p.PRODUCT_ID=cp.PRODUCT_ID and cp.CP_ID=t.CP_ID and cp.OPER_STATE='1' and t.ST_SERVICE_TYPE=p_callType    
  17.   and p.PRODUCT_CODE=p_productCode and cp.CUSTOMER_ID=p_customerId;  
  18.     
  19.   if v_count=0 then result:=41 ;        
  20.   elsif v_count>1 then result:=42 ;    
  21.   elsif v_count=1 then   
  22.   
  23.      select t.ST_SERVICE_TYPE_STATE,c.OUTSTANDING,cp.CP_BILLING_MODEL,cp.UNIT_PRICE,cp.cp_id,cp.curr_consu    
  24.      into v_seviceTypeState,v_outstanding,v_billingModel,v_unitPrice,v_cpId,v_currConsu   
  25.      from C_T_CUSTOMER_PRODUCT cp,B_T_PRODUCT p,C_T_SERVICE_TYPE t,C_T_CUSTOMER c  
  26.      where p.PRODUCT_ID=cp.PRODUCT_ID and cp.CP_ID=t.CP_ID and cp.OPER_STATE='1' and t.ST_SERVICE_TYPE=p_callType  and p.PRODUCT_CODE=p_productCode and cp.CUSTOMER_ID=p_customerId  
  27.             and c.CUSTOMER_ID=cp.CUSTOMER_ID;  
  28.               
  29.      if v_seviceTypeState='2' then       
  30.          select count(1) into v_stateCount from C_T_CUSTOMER_PRODUCT cp,B_T_PRODUCT p,C_T_SERVICE_TYPE t  
  31.          where p.PRODUCT_ID=cp.PRODUCT_ID and cp.CP_ID=t.CP_ID and cp.OPER_STATE='1' and t.ST_SERVICE_TYPE=p_callType  and p.PRODUCT_CODE=p_productCode  
  32.                 and cp.CUSTOMER_ID=p_customerId and t.ST_SERVICE_TYPE_STATE ='2' and cp.CP_INF_BONUS>cp.CP_INF_USE;  
  33.          if v_stateCount>0 then result:=3;      
  34.          else result:=43;                       
  35.          end if;  
  36.   
  37.      elsif v_seviceTypeState='3' then    
  38.          select count(1) into v_stateCount from C_T_CUSTOMER_PRODUCT cp,B_T_PRODUCT p,C_T_SERVICE_TYPE t  
  39.          where p.PRODUCT_ID=cp.PRODUCT_ID and cp.CP_ID=t.CP_ID and cp.OPER_STATE='1' and t.ST_SERVICE_TYPE=p_callType  and p.PRODUCT_CODE=p_productCode  
  40.                 and cp.CUSTOMER_ID=p_customerId and t.ST_SERVICE_TYPE_STATE ='3' and cp.CP_DATA_BONUS>cp.CP_DATA_USE;  
  41.          if v_stateCount>0 then result:=4;     
  42.          else result:=44;                      
  43.          end if;  
  44.      end if;  
  45.   
  46.   end if;  
  47. exception  
  48.  when others then  
  49.   result := 48;  
  50. END;  

 

0 0
原创粉丝点击