How to Get Shared TeaObject Along with All the References
A TeaObject has references to all its members. When you get a TeaObject from the database, you have the option to get the high-level object or you can request the object with all the references included (Closure).
To retrieve a TeaObject Closure use the following code:
@TeaOperation(name = "getJohnClosure", description = "getJohnClosure")
public String getJohnClosure() throws IOException {
TeaPersistence persistence = ShareReaderAgent.server.getPersistence();
Map<String, JSONObject> johnClosure = persistence.getObjectClosure("ShareWriterAgent", "Person", "john");
return Joiner.on(",").join(johnClosure.values());
}
The object returned by this method is in JSON format. Below is an example that is returned by the sample code above:
[
{
"@objectId":"ShareWriterAgent::Person:Peter",
"name":"Peter",
"description":"Peter Person",
"key":"Peter",
"config":{
"status":"Single",
"address":"3303 Hillview Avenue"
},
"members":[
"ShareWriterAgent::Person:Adam",
"ShareWriterAgent::Person:Sarah"
],
"references":[
{
"name":"cousins",
"elements":[
"ShareWriterAgent::Person:Brian",
"ShareWriterAgent::Person:Anna"
]
},
{
"name":"parent",
"elements":[
"ShareWriterAgent::Person:John"
]
},
{
"name":"cars",
"elements":[
"ShareWriterAgent::Car:BMW"
]
}
]
},
{
"@objectId":"ShareWriterAgent::Person:Adam",
"name":"Adam",
"description":"Adam Person",
"key":"Adam",
"config":{
"status":"Single",
"address":"3303 Hillview Avenue"
}
},
{
"@objectId":"ShareWriterAgent::Person:Sarah",
"name":"Sarah",
"description":"Sarah Person",
"key":"Sarah",
"config":{
"status":"Single",
"address":"3303 Hillview Avenue"
}
},
{
"@objectId":"ShareWriterAgent::Person:Brian",
"name":"Brian",
"description":"Brian Person",
"key":"Brian",
"config":{
"status":"Single",
"address":"3303 Hillview Avenue"
}
},
{
"@objectId":"ShareWriterAgent::Person:Anna",
"name":"Anna",
"description":"Anna Person",
"key":"Anna",
"config":{
"status":"Single",
"address":"3303 Hillview Avenue"
}
},
{
"@objectId":"ShareWriterAgent::Person:John",
"name":"John",
"description":"John Person",
"key":"John",
"config":{
"status":"Single",
"address":"3303 Hillview Avenue"
}
},
{
"@objectId":"ShareWriterAgent::Car:BMW",
"name":"BMW",
"description":"BMW Car",
"key":"BMW",
"config":{
"color":"blue",
"license":"6VHM435"
}
}
]
Copyright © Cloud Software Group, Inc. All Rights Reserved.