存储过程返回结果转化为对象属性值的方法-bboss persistent o/r mapping机制应用

bboss persistent o/r mapping机制能够将存储过程调用过程中out参数转化为对象属性返回给应用程序。本文档举例说明这个功能。

java值对象Test_p,定义好属性及属性的set/get方法
public class Test_p {
        private String test;
        private String name;
        private String name1;
        private int count = 0;
        public String getName() {
                return name;
        }
        public void setName(String name) {
                this.name = name;
        }
        public String getName1() {
                return name1;
        }
        public void setName1(String name1) {
                this.name1 = name1;
        }
        public String toString()
        {
                return new StringBuffer().append("name=").append(name).append(",name1=").append(name1).append(",test=").append(test).toString();
        }
        public String getTest() {
                return test;
        }
        public void setTest(String test) {
                this.test = test;
        }
        public int getCount() {
                return count;
        }
        public void setCount(int count) {
                this.count = count;
        }

}

定义存储过程,存储过程中的out参数名称与java对象Test_p的属性保持一致,bboss persistent 提供的or mapping机制将自动在procedure的out参数名称和java对象的属性之间进行撮合,匹配上的属性和参数将会进行值与值的设置,如果二者之间的数据类型不一致,那么只要能够转换 框架将会进行自动转换。

CREATE OR REPLACE PROCEDURE test_p(id in number,
                                   name out varchar2 --本参数与Test_p对象中的name属性对应,并且类型一致,不需要类型转换
                                ,name1 out varchar2,--本参数在Test_p对象中的name1属性对应,并且类型一致,不需要类型转换                                  
                                   test out number,--本参数在Test_p对象中的test属性对应,但是类型不一致,一个是number,一个是String,需要类型转换,即number将被转换为String类型
                                   notmatch out number --本参数在Test_p对象中没有对应属性,将被忽略
) IS

/******************************************************************************
   NAME:       test
   PURPOSE:   

   REVISIONS:
   Ver        Date        Author           Description
   ---------  ----------  ---------------  ------------------------------------
   1.0        2008-10-27          1. Created this procedure.

   NOTES:

   Automatically available Auto Replace Keywords:
      Object Name:     test
      Sysdate:         2008-10-27
      Date and Time:   2008-10-27, 17:05:33, and 2008-10-27 17:05:33
      Username:         (set in TOAD Options, Procedure Editor)
      Table Name:       (set in the "New PL/SQL Object" dialog)

******************************************************************************/
BEGIN
   --tmpVar := 0;
   name := 'hello name';
   name1 := 'hello name1';
   test := id;
   notmatch := id;
   --insert into test(id,name) values(SEQ_TEST.nextval,'name1');
   --commit;
  
  
EXCEPTION
  WHEN NO_DATA_FOUND THEN
    NULL;
  WHEN OTHERS THEN
    -- Consider logging the error and then re-raise
    RAISE;
END test_p;
/

业务方法

CallableDBUtil callableDBUtil = new CallableDBUtil();
                try
                {
                        callableDBUtil.prepareCallable("{call test_p(?,?,?,?,?)}");
                        //不允许的操作: Ordinal binding and Named binding cannot be combined!
                        callableDBUtil.setInt("id", 10);
                        callableDBUtil.registerOutParameter("name", java.sql.Types.VARCHAR);
                        callableDBUtil.registerOutParameter("name1", java.sql.Types.VARCHAR);
                        callableDBUtil.registerOutParameter("test", java.sql.Types.INTEGER);
                        callableDBUtil.registerOutParameter("nomatch", java.sql.Types.INTEGER);
                        Test_p tets = (Test_p)callableDBUtil.executeCallableForObject(Test_p.class);
                       
                        System.out.println("Test_p is " + tets);
                                       
                }
                catch(Exception e)
                {
                        e.printStackTrace();
                } 

 

bboss项目下载列表 在sourceforge访问地址为:
https://sourceforge.net/project/showfiles.php?group_id=238653

     

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值