final byte recordStatus = channel.readByte();
final ORecordId rid = channel.readRID();
final byte recordType = channel.readByte();
final ORecordOperation entry = new OTransactionEntryProxy(recordType);
entry.type = recordStatus;
switch (recordStatus) {
case ORecordOperation.CREATED:
oNetworkProtocolBinary.fillRecord(rid, channel.readBytes(), OVersionFactory.instance().createVersion(),
entry.getRecord(), database);
// SAVE THE RECORD TO RETRIEVE THEM FOR THE NEW RID TO SEND BACK TO THE REQUESTER
createdRecords.put(rid.copy(), entry.getRecord());
break;
case ORecordOperation.UPDATED:
ORecordVersion version = channel.readVersion();
byte[] bytes = channel.readBytes();
oNetworkProtocolBinary.fillRecord(rid, bytes, version, entry.getRecord(), database);
if (protocolVersion >= 23)
ORecordInternal.setContentChanged(entry.getRecord(), channel.readBoolean());
break;
case ORecordOperation.DELETED:
ORecordInternal.fill(entry.getRecord(), rid, channel.readVersion(), null, false);
break;
default:
throw new OTransactionException("Unrecognized tx command: " + recordStatus);
}
// PUT IN TEMPORARY LIST TO GET FETCHED AFTER ALL FOR CACHE
tempEntries.put(entry.getRecord().getIdentity(), entry);
}
if (lastTxStatus == -1)
// ABORT TX
throw new OTransactionAbortedException("Transaction aborted by the client");
final ODocument remoteIndexEntries = new ODocument(channel.readBytes());
fillIndexOperations(remoteIndexEntries);
// FIRE THE TRIGGERS ONLY AFTER HAVING PARSED THE REQUEST
for (Entry<ORID, ORecordOperation> entry : tempEntries.entrySet()) {
if (entry.getValue().type == ORecordOperation.UPDATED) {
// SPECIAL CASE FOR UPDATE: WE NEED TO LOAD THE RECORD AND APPLY CHANGES TO GET WORKING HOOKS (LIKE INDEXES)
final ORecord record = entry.getValue().record.getRecord();
final ORecord loadedRecord = record.getIdentity().copy().getRecord();
if (loadedRecord == null)
throw new ORecordNotFoundException(record.getIdentity().toString());
if (ORecordInternal.getRecordType(loadedRecord) == ODocument.RECORD_TYPE
&& ORecordInternal.getRecordType(loadedRecord) == ORecordInternal.getRecordType(record)) {
((ODocument) loadedRecord).merge((ODocument) record, false, false);
loadedRecord.getRecordVersion().copyFrom(record.getRecordVersion());
entry.getValue().record = loadedRecord;
// SAVE THE RECORD TO RETRIEVE THEM FOR THE NEW VERSIONS TO SEND BACK TO THE REQUESTER
updatedRecords.put((ORecordId) entry.getKey(), entry.getValue().getRecord());
}
}
addRecord(entry.getValue().getRecord(), entry.getValue().type, null);
}
tempEntries.clear();
// UNMARSHALL ALL THE RECORD AT THE END TO BE SURE ALL THE RECORD ARE LOADED IN LOCAL TX
for (ORecord record : createdRecords.values())