}
@Override
protected void checkIfKeyRead(InvocationContext context, Object key, VisitableCommand command) {
if (command instanceof AbstractDataWriteCommand) {
AbstractDataWriteCommand writeCommand = (AbstractDataWriteCommand) command;
//keep track is only need in a clustered and transactional environment to perform the write skew check
if (context.isInTxScope() && context.isOriginLocal()) {
TxInvocationContext txInvocationContext = (TxInvocationContext) context;
if (!writeCommand.hasFlag(Flag.PUT_FOR_STATE_TRANSFER) && writeCommand.isConditional() ||
!writeCommand.hasFlag(Flag.IGNORE_RETURN_VALUES)) {
//State transfer does not show the old value for the application neither with the IGNORE_RETURN_VALUES.
//on other hand, the conditional always read key!
txInvocationContext.getCacheTransaction().addReadKey(key);
}
writeCommand.setPreviousRead(txInvocationContext.getCacheTransaction().keyRead(key));
}
} else if (command instanceof GetKeyValueCommand) {
if (context.isInTxScope() && context.isOriginLocal()) {
//always show the value to the application
TxInvocationContext txInvocationContext = (TxInvocationContext) context;