Hi Andrey,
Your suggestion to store the document does not work as expected when the
inner document is created within a transaction. I have provided a test
example attached to this post. Please note that when a document is created
within a transaction (i.e., eveDOC) and then provided as an inner document
inside the same transaction, there are two copies of the document saved to
the DB upon the commit instead of 1.
Thanks in advance.
--
---
You received this message because you are subscribed to the Google Groups
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.orientechnologies.orient.core.tx.OTransaction.TXTYPE;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
class NestedInnerDocTX {
public static void main(String[] args) {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:test");
db.create();
db.getMetadata().getSchema().createClass("PersonTest");
db.getMetadata().getSchema().createClass("EventTest");
ODocument adamDoc = new ODocument("PersonTest");
adamDoc.field("name", "adam");
adamDoc.save();
System.out.println("Adam has been saved outside of the transaction scope");
db.begin(TXTYPE.OPTIMISTIC);
ODocument eveDoc = new ODocument("PersonTest");
eveDoc.field("name", "eve");
eveDoc.save();
System.out.println("Eve has been saved within a transaction");
ODocument nestedWithTypeD = new ODocument("EventTest");
nestedWithTypeD
.fromJSON("{\"@type\":\"d\",\"event_name\":\"world cup 2014\",\"admin\":["
+ eveDoc.toJSON() + "," + adamDoc.toJSON() + "]}");
nestedWithTypeD.save();
db.commit();
System.out.println("The count of class PersonTest is: " + db.countClass("PersonTest"));
for (ODocument o : db.browseClass("PersonTest")) {
System.out.println(o);
}
for (ODocument o : db.browseClass("EventTest")) {
System.out.println(o.toJSON());
for (OIdentifiable id : new OSQLSynchQuery<ODocument>(
"traverse * from " + o.getIdentity().toString())) {
System.out.println(id.getIdentity());
}
}
db.close();
}
}