}
@Override
public EntryVersionsMap createNewVersionsAndCheckForWriteSkews(VersionGenerator versionGenerator, TxInvocationContext context, VersionedPrepareCommand prepareCommand) {
// Perform a write skew check on mapped entries.
EntryVersionsMap uv = new EntryVersionsMap();
for (WriteCommand c : prepareCommand.getModifications()) {
for (Object k : c.getAffectedKeys()) {
if (localNodeIsPrimaryOwner(k)) {
ClusteredRepeatableReadEntry entry = (ClusteredRepeatableReadEntry) context.lookupEntry(k);
if (!context.isOriginLocal()) {
// What version did the transaction originator see??
EntryVersion versionSeen = prepareCommand.getVersionsSeen().get(k);
if (versionSeen != null) entry.setVersion(versionSeen);
}
if (entry.performWriteSkewCheck(dataContainer)) {
IncrementableEntryVersion newVersion = entry.isCreated() ? versionGenerator.generateNew() : versionGenerator.increment((IncrementableEntryVersion) entry.getVersion());
uv.put(k, newVersion);
} else {
// Write skew check detected!
throw new CacheException("Write skew detected on key " + k + " for transaction " + context.getTransaction());
}
}
}
}
CacheTransaction cacheTransaction = context.getCacheTransaction();
EntryVersionsMap uvOld = cacheTransaction.getUpdatedEntryVersions();
if (uvOld != null && !uvOld.isEmpty()) {
uvOld.putAll(uv);
uv = uvOld;
}
cacheTransaction.setUpdatedEntryVersions(uv);
return (uv.isEmpty()) ? null : uv;
}