|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Question about implementation decision |
« View previous topic :: View next topic » |
Author |
Message
|
lfrestrepog |
Posted: Thu Apr 16, 2015 2:43 pm Post subject: Question about implementation decision |
|
|
Novice
Joined: 08 Jul 2014 Posts: 22
|
Hello everyone.
Here's the scenario: I wanted to check the existence of a field in a message and came up with two ideas, they both work and the result is pretty much the same, but I'd like to receive comments on which would be preferable and why.
1. The obvious option:
Code: |
DECLARE aux REFERENCE TO InputRoot.XMLNSC.doc.field;
IF LASTMOVE(aux) THEN
-- Do stuff...
END IF;
|
2. A little more creative:
Create a procedure...
Code: |
CREATE PROCEDURE alt_exists(IN field REFERENCE) RETURNS BOOLEAN
BEGIN
RETURN LASTMOVE(field);
END;
|
Then in the module...
Code: |
IF alt_exists(InputRoot.XMLNSC.doc.field) THEN
-- Do stuff...
END IF; |
The only benefit I find in the second option is that it prevents the use of an unnecessary reference, so it got me thinking if that should be considered an advantage or if actually the procedure call would be more expensive than the reference.
Any comments would be much appreciated.
Thanks!
--
Luis Fernando Restrepo |
|
Back to top |
|
 |
shashivarungupta |
Posted: Thu Apr 16, 2015 3:17 pm Post subject: |
|
|
 Grand Master
Joined: 24 Feb 2009 Posts: 1343 Location: Floating in space on a round rock.
|
lfrestrepog wrote: |
.. I wanted to check the existence of a field in a message.. |
I am not sure if you have got a chance to look at FIELDTYPE function (at InfoCentre)
IF FIELDTYPE(InputRoot.XMLNS.Message1.Name)
IS NULL THEN
// Name field does not exist, take error
action....
... more ESQL ...
ELSE
// Name field does exist, continue....
... more ESQL ...
END IF
I've used it in one of my applications, where 'reference to' input message (element) was used and that declared reference variable was used in the FIELDTYPE function, which worked effectively.
The first scenario where you've used reference to some field of InputRoot, should be effective than the scenario 2. (AFAIK).
{Sometimes it also matters that how deep and how far you are navigating into the message tree. If the element is deep then it would take more time/efforts to find it, than the element which is up on the tree and not that deep.}
Hope this will serve your purpose.
 _________________ *Life will beat you down, you need to decide to fight back or leave it. |
|
Back to top |
|
 |
kimbert |
Posted: Fri Apr 17, 2015 3:46 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Any reason why nobody is recommending this?
Code: |
IF EXISTS (InputRoot.XMLNSC.Message1.Name[])
-- do stuff that depends on the field
ELSE
-- field does not exist
... more ESQL ...
END IF |
Two things to highlight here:
- don't forget to add the [] on the end of the path reference
- I never post examples that use XMLNS. XMLNSC should be used in all new message flows. _________________ Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too. |
|
Back to top |
|
 |
shashivarungupta |
Posted: Sun Apr 19, 2015 5:51 pm Post subject: |
|
|
 Grand Master
Joined: 24 Feb 2009 Posts: 1343 Location: Floating in space on a round rock.
|
kimbert wrote: |
- I never post examples that use XMLNS. XMLNSC should be used in all new message flows. |
and thanks for your notice on this. ( it was my bad while taking a quick reference from info center and its sample old example.. It should by XMLNSC. ). _________________ *Life will beat you down, you need to decide to fight back or leave it. |
|
Back to top |
|
 |
lfrestrepog |
Posted: Mon Apr 27, 2015 10:49 am Post subject: |
|
|
Novice
Joined: 08 Jul 2014 Posts: 22
|
Thank you for your replies.
Another follow up question, considering the different options available to check whether or not a field is present in the message (and assuming I create references to prevent unnecessary path navigation, and so on); is there any reason to prefer one way over the rest?
I'm asking because, for practical purposes they all seem to work the same (am I missing something?).
The two options I proposed in the first post where chosen arbitrarily (I usually try to avoid any comparison with "null", hence the lastmove preference).
About the "EXISTS" option, suggested by kimbert, I notice it does prevent the use of unnecessary references, should that be the preferred way to check fields?
Just to be clear, we are not facing any problems regarding this topic at the moment, but we are trying to standardise our code conventions...
Thanks again... any further comments would be much appreciated. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|