Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion How to Pass Java List of POJO to Oracle Stored Procedure using MyBatis?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
AntPort  
View profile  
 More options Oct 4 2012, 4:57 pm
From: AntPort <antonioporto...@gmail.com>
Date: Thu, 4 Oct 2012 13:57:38 -0700 (PDT)
Local: Thurs, Oct 4 2012 4:57 pm
Subject: Re: How to Pass Java List of POJO to Oracle Stored Procedure using MyBatis?

I don't know about  table of records, but you can send array of types as an
input parameter, but you must create specific typeHandler. That goes
something like this (for Oracle):

create or replace
TYPE "I_REZERVATION_TYPE" AS OBJECT
(
    ID_REZERVATION NUMBER,
      ID_BRANCH     NUMBER,
      I_AGN        VARCHAR2 (1 CHAR),
      NAP_AGN      VARCHAR2 (100 CHAR),
    CONSTRUCTOR FUNCTION I_REZERVATION_TYPE
         RETURN SELF AS RESULT);

create or replace
TYPE "I_REZERVATION_ARRAY" AS TABLE OF I_REZERVATION_TYPE;

 --------------------------------------------------------------------------- --------------------------------------------------------------------------- -

 --------------------------------------------------------------------------- --------------------------------------------------------------------------- -

         TypeHandler:

public void setParameter(PreparedStatement ps, int argNum,
Object passedValue, JdbcType jdbcType) throws SQLException {

Connection conn;

                // list of maps
                // every map contains type field names as a key and field
values as a value
List<LinkedHashMap<String,Object>> inParams =
(List<LinkedHashMap<String,Object>>) passedValue;

STRUCT[] structArray = new STRUCT[inParams.size()];
conn = ps.getConnection();
StructDescriptor structDesc = StructDescriptor.createDescriptor(
"I_REZERVATION_TYPE", conn);
ArrayDescriptor arrayDesc = ArrayDescriptor.createDescriptor(
"I_REZERVATION_ARRAY", conn);

int valueCounter = 0;
for (Map<String, Object> properties : inCollection) {

structArray[valueCounter] = new STRUCT(structDesc, conn, properties);
valueCounter++;

}

ARRAY arrayOfType = new ARRAY(arrayDesc, conn, structArray);
ps.setArray(argNum, arrayOfType);
       }

Map input parameter:procedure_call(#{listOfMaps,mode=IN,typeHandler=yourTypeHandler})
The downside of this approach is that you have to map all your properties
from pojos to the keys in map. Key values must correspond to database type
properties.
Also you will have to create special typehandler for every type from the
database (or you can wrap the List<Map>, arrayName, typeName in another
pojo and use one generic typehandler for all calls).

Dana srijeda, 3. listopada 2012. 03:55:06 UTC+2, korisnik grimmel97 napisao
je:

> Hi,

> I have been googling this for a while and cannot seem to find any real
> answers.

> I have an Oracle stored procedure that has a number of in parameters that
> have a type that is table of the table rowtype.  So for example:

> *Declared in the pacakge:*
> TYPE param1_type_t IS TABLE OF table1%ROWTYPE;
> TYPE param2_type_t IS TABLE OF table2%ROWTYPE;
> TYPE param3_type_t IS TABLE OF table3%ROWTYPE;

> *Procedure:*
> PROCEDURE my_proc
> (
>    parameter1    IN param1_type_t,
>    parameter2    IN param2_type_t,
>    parameter3    IN param3_type_t
> )

> On the java side, I have 3 corresponding POJO objects representing each of
> the parameters and the code creates a java List of each of the POJOs.  Is
> it possible to call the Oracle procedure using MyBatis in this scenario?

> If so, how would the SQLMap be written?  Or do I need to write more
> objects to cater for this scenario?

> Thanks in advance.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.