cancel
Showing results for 
Search instead for 
Did you mean: 

Difference between node.invalidate() and node.removeElement()

Former Member
0 Kudos

Hi,

I was going through some code recently and came across the concept of removing the elements from a node to clear the node as a substitute for node.invalidate().

For eg:

If we have a node X which we need to clear, the following is the code user for removing the elements:

CASE 1:

if (wdContext.nodeX() != null && wdContext.nodeX().size() > 0) {

for (int iCtr = (wdContext.X.size() - 1); iCtr >= 0; iCtr--)

wdContext.nodeX().removeElement( wdContext.nodeX().getElementAt(iCtr));

}

CASE 2:

wdContext.nodeX().invalidate();

I am not sure I fully understand how this would help and in what way the two cases would be different. It would be great if someone could throw some light on the same.

Also, as you can see in CASE 1, the if() condition checks for

---> wdContext.nodeX() != null

---> wdContext.nodeX().size() > 0

Wouldn't checking just one of the above conditions be sufficient? How are the 2 conditions different when there are no elements in the node.

Thanks in advance.

Regards,

Priyanka Parmar.

View Entire Topic
former_member185086
Active Contributor
0 Kudos

Hi

Both has different use cases let go one by one

1. Remove : A node filled with set of element and want to remove particular based on certain conditions.

2. Invalidate : It does the same thing but all at once ,This method invalidates all elements of the node. i.e all elements and subnode instances are deleted. after this the status of the node is as it is in its initial state.

you can say that How to empty a value node now if some condition is there with particular value then we use remove else invalidate .

Example : Whenever we deal with Model Node(rfc/ejb) we always invalidate the response node so that it will ready to hold new values .

Best Regards

Satish Kumar

Former Member
0 Kudos

Hi Satish,

I was going through the post as even I had same question in my mind but I got bit confused

we invalidate the model node after we executing the RFC model no not before that mean after the model node data is populated in that case how come we get the return values in same node after invalidating the node.

Thanks

former_member185086
Active Contributor
0 Kudos

Hi

Good questions guys

We invalidate the response node so that it will adapt the change and return the latest values there in data base

consider one example : You call a model node which create one record by using say

createEmployees(name,age...),before this call getAllEmployess() method contain say 3 record

now once we execute the createEmployees method one record is added to the database , and we have invalidate the

response node so that whenever next time we will call getAllEmp method we will get 4 records

Second point : we never deal with response node either for creation or deletion edit of get all, we can say its internally

synchronize the values which is there in database.

Priyanka: I think u r confused with attribute and element , A node having attribute (similar a table has some Column)

which contain values that could be 0--100 and if i clear the values attribute will be there which will ready to hold new

values (create analogy with table and its column).

Yes , when we call invalidate it remove 10 element and of course in terms of table rows

Hope it clear now

Best Regards

Satish Kumar