Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code examples for link querying/updates #7

Open
sumanyu opened this issue Aug 19, 2015 · 6 comments
Open

Code examples for link querying/updates #7

sumanyu opened this issue Aug 19, 2015 · 6 comments

Comments

@sumanyu
Copy link

sumanyu commented Aug 19, 2015

I read the docs on links and MV fields, but I'm not sure how to use doradus session (java client) to either link one object to another or query for example: "Find me all people whose manager is Bob". Code examples would be wonderful.

@sumanyu
Copy link
Author

sumanyu commented Aug 20, 2015

@RandyGuck Ok, so I was able to set up linking (link one entity to another) by using addFieldValues method of DbObject and I can confirm that it sets up the bidirectional link.

I was hoping removeFieldValues method would allow me to unlink entities, but the link still exists when I query for the object. Is this a known issue?

@RandyGuck
Copy link

Hi Sumanyu. Sorry for the delayed reply, but I was heads-down getting some new client features checked-in that you might be interested in. Check out the HelloDory app in the doradus-client project for an example that uses the new "Dory" client, which supports the builder pattern for constructing schema and object updates.

DBObject.removeFieldValues() is indeed the method that should remove existing values from an MV scalar or link field. For links, be sure to use the raw, unencoded object IDs you want to remove. If you're still having trouble, perhaps send me a code snippet that I can look at. I'll also do some checking from my side. BTW, values can also be removed using the new DBObject.Builder methods removeFieldValues().

@sumanyu
Copy link
Author

sumanyu commented Aug 25, 2015

@RandyGuck

Given an object with ID "SOME_PARENT_ID" and another object with ID "SOME_CHILD_ID" already in Doradus and linked, the following code example in scala should unlink the object:

val dBObject = new DBObject("SOME_PARENT_ID", SOME_PARENT_TABLE)
dBObject.removeFieldValues("CHILD_IDS", new util.ArrayList[String]("SOME_CHILD_ID"))

@RandyGuck
Copy link

Hi Sumanyu. I need to learn Scala some day, but your code looks correct. However, you need to place the DBObject in a DBObjectBatch and post it with an "add batch" command. Here's the Java code using the com.dell.doradus.client.Client:

    SpiderSession session = (SpiderSession)Client.openApplication("HelloSpider", "localhost", 1123, null, null);
    DBObject dbObj = new DBObject("Spidy1", "Movies");
    dbObj.removeFieldValues("Leads", Arrays.asList("KDunst"));
    DBObjectBatch batch = new DBObjectBatch();
    batch.addObject(dbObj);
    BatchResult result = session.addBatch("Movies", batch);

Because an object with ID "Spidy1" object already exists, the DBObject becomes an "update" (instead of an "add"), so the existing object is updated. In this case, "KDunst" is removed from the link "Leads".

@sumanyu
Copy link
Author

sumanyu commented Aug 26, 2015

So spider session has a nice method called addObject which behind the scenes creates the batch, so I don't have to. (at least that's my understanding of it). Given the dBObject, I then use the spider session as follows:

spiderSession.addObject(SOME_PARENT_TABLE, dBObject)

@RandyGuck, can you confirm unlinking works on release 2.3? Also, when are you doing the next release?

@RandyGuck
Copy link

I just tried the removeFieldValues() example above using a 2.3 client and server and it works.

Our next release is v2.4: the code is checked into the master branch and is fairly stable. There are many new features--I'm putting together documentation for this release now and should have it posted within a week or so. We're also restructuring the wiki pages and documentation, so you should be seeing those updates within a week or two as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants