Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question

Change API: Add to collection of a specific member of embedded collection

I have an object with a Set of ClassA objects, and ClassA also has a Set of String objects. I would like to use the Change API to add a new String to the Set of a specific ClassA instance.

public class BaseObject {
   String baseInstanceName = null;
   Set<ClassA> set1 = null;
   // setters and getters

public class ClassA {
   String uniqueId = null;
   Set<String> externalObjIds = null;
   // setters and getters

What I want to do is identify a certain BaseClass by baseInstanceName and then identify a specific member of the ClassA set (set1). I then want to add a string to the "externalObjIds" set on that particular instance. Can I do that without resorting to using a Map<String, ClassA> in BaseObject? Another alternative is to use have ClassA objects not be embedded in BaseObject but this does not fit 100% with the logic of the model.

This thread was imported from the previous forum.
For your reference, the original is available here

asked 2013-07-16 09:07:01 -0500

dennisla gravatar image

updated 2013-08-08 09:52:00 -0500

jaissefsfex gravatar image
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

Why won't you query the objects (you can index fields within the nested object field if you need to) , get the ID (using projection to avoid the full object retrieval), and use the Change API with addToCollection change set operation?
You can also use a template to identify matching object and change these in one atomic operation , in case you don't want to break this into separate activities as described above.

answered 2013-07-16 13:22:45 -0500

shay hassidim gravatar image
edit flag offensive delete link more


Okay so I want to add "newExtId" to "externalObjIds" on the ClassA object with "uniqueId" = "uid1", which is a member of a BaseObject whose "baseInstanceId" = "base1". I can use an SQLQuery to get the correct BaseObject, but how do I specify a change on the "externalObjIds" set?

SQLQuery<BaseObject> getBaseObjQuery = new SQLQuery<BaseObject>(BaseObject.class, "baseInstanceName = ? AND set1.uniqueId?");
ChangeResult<BaseObject> propsWithNewChannelAdded = gigaSpace.change(getBaseObjQuery, new ChangeSet().addToCollection( "????", "newExtId"));

What syntax do I use to modify the exact instance of ClassA that I need? "set1.uniqueId=uid1.externalObjsId" (obviously this won't work).
If I had a map instead of a set then I can just use "set1.uid1.externalObjsId".

dennisla gravatar image dennisla  ( 2013-07-17 03:59:59 -0500 )edit

What you are asking is custom change operation, this is not exposed to the user. I think I would go for the map solution it is simpler. In any other way, at the minimum you will have to read the entire set using Projection API, you can use a task to do it and execute this code on the server and reduce the network and serialization over head. If you chose this way, then once you have the set in your code, and you located the object you want to modify. You could clone it and then do a change invocation which contains to change operations. removeFromCollection("set1",oldObject).addToCollection("set1",newObject)


eitany gravatar image eitany  ( 2013-07-17 08:11:35 -0500 )edit

Thanks Eitan, I had started to do this using the Map changes I had mentioned already, and I think it is okay so I will leave it as it is for now.

I haven't looked at the Projection API though so I will have a look at that as well.

dennisla gravatar image dennisla  ( 2013-07-17 08:57:01 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2013-07-16 09:07:01 -0500

Seen: 221 times

Last updated: Jul 16 '13