public static EntryVersionsMap performWriteSkewCheckAndReturnNewVersions(VersionedPrepareCommand prepareCommand,
DataContainer dataContainer,
VersionGenerator versionGenerator,
TxInvocationContext context,
KeySpecificLogic ksl) {
EntryVersionsMap uv = new EntryVersionsMap();
for (WriteCommand c : prepareCommand.getModifications()) {
for (Object k : c.getAffectedKeys()) {
if (ksl.performCheckOnKey(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());
}
}