use of com.orientechnologies.orient.core.serialization.OSerializableStream in project orientdb by orientechnologies.
the class OTransactionRealAbstract method serializeIndexChangeEntry.
protected ODocument serializeIndexChangeEntry(OTransactionIndexChangesPerKey entry, final ODocument indexDoc) {
// SERIALIZE KEY
ODocument keyContainer = new ODocument();
keyContainer.setTrackingChanges(false);
try {
if (entry.key != null) {
if (entry.key instanceof OCompositeKey) {
final List<Object> keys = ((OCompositeKey) entry.key).getKeys();
keyContainer.field("key", keys, OType.EMBEDDEDLIST);
keyContainer.field("binary", false);
} else if (!(entry.key instanceof ORecordElement) && (entry.key instanceof OSerializableStream)) {
keyContainer.field("key", OStreamSerializerAnyStreamable.INSTANCE.toStream(entry.key), OType.BINARY);
keyContainer.field("binary", true);
} else {
keyContainer.field("key", entry.key);
keyContainer.field("binary", false);
}
} else
keyContainer = null;
} catch (IOException ioe) {
throw OException.wrapException(new OTransactionException("Error during index changes serialization. "), ioe);
}
final List<ODocument> operations = new ArrayList<ODocument>();
// SERIALIZE VALUES
if (entry.entries != null && !entry.entries.isEmpty()) {
for (OTransactionIndexEntry e : entry.entries) {
final ODocument changeDoc = new ODocument().setAllowChainedAccess(false);
ODocumentInternal.addOwner((ODocument) changeDoc, indexDoc);
// SERIALIZE OPERATION
changeDoc.field("o", e.operation.ordinal());
if (e.value instanceof ORecord && e.value.getIdentity().isNew()) {
final ORecord saved = getRecord(e.value.getIdentity());
if (saved != null)
e.value = saved;
else
((ORecord) e.value).save();
}
changeDoc.field("v", e.value != null ? e.value.getIdentity() : null);
operations.add(changeDoc);
}
}
ODocument res = new ODocument();
res.setTrackingChanges(false);
ODocumentInternal.addOwner(res, indexDoc);
return res.setAllowChainedAccess(false).field("k", keyContainer, OType.EMBEDDED).field("ops", operations, OType.EMBEDDEDLIST);
}
Aggregations