Results 1 to 3 of 3

Thread: Generic Oracle stored function class

  1. #1

    Default Generic Oracle stored function class

    Hi all,

    I would really appreciate some feedback on something I have been working on recently. I may have completely wasted my time doing this so let me know if thats the case.

    I work exclusively with Oracle (9i) and ALL db interaction is via stored procs (company rules).

    I have used the Spring StoredProcedure class extensively to wrap these calls to the Oracle db.

    I noticed after a while though a couple of things:

    1. A separate (usually inner) class for each stored procedure was becoming tedious to write.
    2. Alot of the calls dealt with scaler (ints and strings mostly) parameters, both IN and OUT.
    3. The next common return type was a cursor.

    So in the best tradition of TDD, I decided to refactor the code as much as possible and see where it led.

    I came up with a generic Oracle Stored Function class. Here's some example of its usage:

    Code:
        public int callFunctionTestCaseA() {
            // no input params, return type int
            OracleStoredFunction sp = new OracleStoredFunction(ds,
                    "testpkg.testfunc_a", Types.INTEGER);
    
            return sp.runForInt();
        }
    
        public String callFunctionTestCaseB() {
            // no input params, return type String
            OracleStoredFunction sp = new OracleStoredFunction(ds,
                    "testpkg.testfunc_b", Types.VARCHAR);
    
            return sp.runForString();
        }
    
        public int callFunctionTestCaseC(int i) {
            // one int input param, return int
            SqlParameter[] inparams = new SqlParameter[] {
                    new SqlParameter("int_in", Types.INTEGER)
                };
            OracleStoredFunction sf = new OracleStoredFunction(ds,
                    "testpkg.testfunc_c", inparams, Types.INTEGER);
            Map in = new HashMap(1);
            in.put("int_in", new Integer(i));
    
            return sf.runForInt(in);
        }
    
        public String callFunctionTestCaseD(int i, String string) {
            // input param (int, String), return type String
            SqlParameter[] inparams = new SqlParameter[] {
                    new SqlParameter("int_in", Types.INTEGER),
                    new SqlParameter("string_in", Types.VARCHAR)
                };
    
            OracleStoredFunction sf = new OracleStoredFunction(ds,
                    "testpkg.testfunc_d", inparams, Types.VARCHAR);
            Map in = new HashMap(2);
            in.put("int_in", new Integer(i));
            in.put("string_in", string);
    
            return sf.runForString(in);
        }
    
        public List callFunctiontestCaseE() {
            // no input params, return type cursor
            OracleStoredFunction sf = new OracleStoredFunction(ds,
                    "testpkg.testfunc_e", OracleTypes.CURSOR);
    
            return sf.runForList();
        }
    
        public List callFunctiontestCaseF(int i, String string) {
            // input params (int, String), return type cursor
            SqlParameter[] inparams = new SqlParameter[] {
                    new SqlParameter("int_in", Types.INTEGER),
                    new SqlParameter("string_in", Types.VARCHAR)
                };
            OracleStoredFunction sf = new OracleStoredFunction(ds,
                    "testpkg.testfunc_f", inparams, OracleTypes.CURSOR);
            Map in = new HashMap(2);
            in.put("int_in", new Integer(i));
            in.put("string_in", string);
    
            return sf.runForList(in);
        }
    As you can see it has a passing resemblance to the JdbcTemplate class!

    Before I post the actual class itself, do you think i've reinvented the wheel? Is it useful?

    Cheers

    Rakesh

  2. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    Interesting. I can see the motivation if you have many classes.

    Did you consider the following method on JdbcTemplate:

    Code:
     public Map call(CallableStatementCreator csc, final List declaredParameters)
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  3. #3

    Default

    Hi Rod,

    i believe Thomas R mentioned that in another thread.

    However, when I went looking for an example, I could not find one (i checked the pdf manual, the tests, this forum and all your books). I guess I lack the experience to work it out for myself so gave up!

    If you have a simple example you could post I would be grateful to see how it fits in with my needs and report back.

    Thanks

    Rakesh

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  3. Replies: 3
    Last Post: Sep 4th, 2005, 11:11 PM
  4. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  5. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •