create class Doc
create class ParentDoc
create property ParentDoc.children LINKLIST
insert into Doc set name="doc1" #12:0
insert into Doc set name="doc2" #12:1
insert into ParentDoc set name="pd", children = [#12:0] #13:0
update #13:0 add children = #12:1
For what I understood you want a piece of code that replaces the last four commands using Java Document API.
try (ODatabaseDocument db = new ODatabaseDocumentTx("remote:localhost/DB")) {
db.open("admin", "admin");
ODocument doc1 = new ODocument("Doc");
doc1.field("name", "doc1");
doc1.save();
List<OIdentifiable> linklist = new ArrayList();
linklist.add(doc1);
ODocument parent = new ODocument("ParentDoc");
parent.field("children", linklist, OType.LINKLIST);
parent.save();
// ...
ODocument doc2 = new ODocument("Doc");
doc2.field("name", "doc2");
doc2.save();
List children = parent.field("children");
children.add(doc2);
parent.field("children", children);
parent.save();
}
5
solved How do I add a linked document to a linked list using the Java API for OrientDB?