ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » How to return mbElement[] from Java to ESQL?

Post new topic  Reply to topic
 How to return mbElement[] from Java to ESQL? « View previous topic :: View next topic » 
Author Message
bab
PostPosted: Thu Aug 04, 2016 3:28 am    Post subject: How to return mbElement[] from Java to ESQL? Reply with quote

Novice

Joined: 05 Jul 2016
Posts: 17

Hi I am new to IIB.

I want to pass REFERENCE as a argument to Java method and transform it then i want to return in the form of mbElement[].

Is there any way to do?

Kindly reply.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Thu Aug 04, 2016 3:46 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

The documentation should be clear on what things can be passed into and out of a Java method.
_________________
chmod -R ugo-wx /
Back to top
View user's profile Send private message
bab
PostPosted: Thu Aug 04, 2016 3:59 am    Post subject: Reply with quote

Novice

Joined: 05 Jul 2016
Posts: 17

Thanks for your reply.

I read the documentation available here They mentioned about REFERENCE type but i dont't know how to implement.

If u provide any sample solution it will be helpful.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Thu Aug 04, 2016 4:30 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

That says that if you put a REFERENCE as a parameter in your Java method, and in the DEFINE PROCEDURE statement, then your java code will get either an MbElement object (singular) or an array of MbElements - depending on if it's an IN or INOUT parameter.

Then you just pass the reference value in your CALL statement.
_________________
chmod -R ugo-wx /
Back to top
View user's profile Send private message
bab
PostPosted: Thu Aug 04, 2016 5:03 am    Post subject: Reply with quote

Novice

Joined: 05 Jul 2016
Posts: 17

I can able to pass REFERENCE type but i am unable to return mbElement[] type.
Back to top
View user's profile Send private message
bab
PostPosted: Mon Aug 08, 2016 2:32 am    Post subject: Error: SqlRoutine::clearDownChildEnv Reply with quote

Novice

Joined: 05 Jul 2016
Posts: 17

I am using the following code in ESQL

Code:
CALL retrieveData(CAST(AGE AS INTEGER),OutputRoot.XMLNSC.employees) into RESULT;



Calling java method as follows :
Code:
create function retrieveData(IN empId INTEGER,INOUT outputXML REFERENCE)
      returns integer
      language java
      external name "com.test.util.Database.retrieve";


Below is the java method:

Code:
public static Long retrieve(Long employeeAge,MbElement[] outputRoot)
{
MbElement xmlnsc = outputRoot[0].getFirstElementByPath("XMLNSC");
            MbElement employees = xmlnsc.createElementAsFirstChild(MbElement.TYPE_NAME, "employees", null);
MbElement employee =employees.createElementAsLastChild(MbElement.TYPE_NAME, "employee", "");
               employee.createElementAsLastChild(MbElement.TYPE_NAME, "emp-id", 1001);
               employee.createElementAsLastChild(MbElement.TYPE_NAME, "emp-name", "john");
               employee.createElementAsLastChild(MbElement.TYPE_NAME, "emp-age", 30);
               employee.createElementAsLastChild(MbElement.TYPE_NAME, "emp-city", "london");


 return new Long(0);
}



It is throwing SqlRoutine::clearDownChildEnv error.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Mon Aug 08, 2016 3:59 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

You're passing in a reference to OutputRoot.XMLNSC.employees...

Unless you're doing something very odd, this won't have a child element named XMLNSC. It will only have children that belong to the employees structure.

So
Code:
MbElement xmlnsc = outputRoot[0].getFirstElementByPath("XMLNSC");

Won't return anything, yes?
_________________
chmod -R ugo-wx /
Back to top
View user's profile Send private message
bab
PostPosted: Mon Aug 08, 2016 8:38 pm    Post subject: Reply with quote

Novice

Joined: 05 Jul 2016
Posts: 17

It is returning MbElement properly and I can able to add child element under OutputRoot->XMLNSC->employees and I can able to access the children of employees element in the Expressions tab while in debug mode.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Tue Aug 09, 2016 3:49 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Your ESQL Code
Code:
CALL retrieveData(CAST(AGE AS INTEGER),OutputRoot.XMLNSC.employees) into RESULT;


The reference you are passing in is to the employees structure, not to OutputRoot.

Your java code is trying to find the XMLNSC MbElement beneath the employees structure. It's not, or shouldn't be, there.

Run a usertrace. Use a tracenode with pattern ${Root.XMLNSC.employees} and ${Root} before the ComputeNode. Compare the two trees.
_________________
chmod -R ugo-wx /
Back to top
View user's profile Send private message
bab
PostPosted: Tue Aug 09, 2016 6:29 am    Post subject: Reply with quote

Novice

Joined: 05 Jul 2016
Posts: 17

Thanks for your reply.

I got output.

I have used in the following way:

Code:
SET OutputRoot.XMLNSC.employees=null;
      
      DECLARE outputref REFERENCE TO OutputRoot.XMLNSC.employees;
      
      CALL retrieveData(CAST(AGE AS INTEGER),outputref) into RESULT;


Its working fine.

Back to top
View user's profile Send private message
smdavies99
PostPosted: Tue Aug 09, 2016 9:30 am    Post subject: Reply with quote

Jedi Council

Joined: 10 Feb 2003
Posts: 6076
Location: Somewhere over the Rainbow this side of Never-never land.

May I humbly suggest that you take a usertrace of your flow and look at what happens when you execute
Code:

SET OutputRoot.XMLNSC.employees=null;
     
DECLARE outputref REFERENCE TO OutputRoot.XMLNSC.employees

You may well want to think again especially with regard to the first line of ESQL.
_________________
WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995

Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Tue Aug 09, 2016 10:01 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Also.

Were my remarks so obscure that changing your code from
Code:
CALL retrieveData(CAST(AGE AS INTEGER),OutputRoot.XMLNSC.employees) into RESULT;
to
Code:
CALL retrieveData(CAST(AGE AS INTEGER),OutputRoot) into RESULT;
didn't seem like a thing to try?
_________________
chmod -R ugo-wx /
Back to top
View user's profile Send private message
ghoshly
PostPosted: Tue Aug 09, 2016 2:05 pm    Post subject: Name / Value Reply with quote

Partisan

Joined: 10 Jan 2008
Posts: 327

bab - Please try as suggested by mqjeff.

I would also like to point another may be silly mistake -

You are using MbElement.TYPE_NAME even when you are populating name and value. I believe we have different argument as MbElement.TYPE_NAME_VALUE.

Please rectify me if I am wrong.
Back to top
View user's profile Send private message
bab
PostPosted: Tue Aug 09, 2016 9:20 pm    Post subject: Reply with quote

Novice

Joined: 05 Jul 2016
Posts: 17

Thanks for your suggestions.

@mqjeff - I tried whatever you specified in the following statement
Code:
CALL retrieveData(CAST(AGE AS INTEGER),OutputRoot) into RESULT;


But i didn't return even XMLNSC element also.

@ghoshly - Yes ghoshly you are correct. I have to use MbElement.TYPE_NAME_VALUE. Thanks for your correction.

May i know what is the difference between MbElement.TYPE_NAME and MbElement.TYPE_NAME_VALUE? . Because both producing the same output.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Wed Aug 10, 2016 3:57 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

If it's not returning XMLNSC, then have you done anything with the OutputRoot at all? Like create an XMLNSC tree?

If your ESQL code does
Code:
SET OutputRoot.XMLNSC.employees=null;
then this is *creating* the XMLNSC parser element, as well as the employees element, and setting the value of the employees element to Null.

If you pass in a reference to a field that doesn't exist, or otherwise create a reference in ESQL to a field that doesn't exist, the reference points to the first parent that does exist.
_________________
chmod -R ugo-wx /
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » How to return mbElement[] from Java to ESQL?
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.