protected CacheEntry lookupEntryFromCurrentTransaction(TransactionTable transactionTable, TransactionManager transactionManager, Object key) {
// Prior to 5.1, this used to happen by grabbing any InvocationContext in ThreadLocal. Since ThreadLocals
// can no longer be relied upon in 5.1, we need to grab the TransactionTable and check if an ongoing
// transaction exists, peeking into transactional state instead.
try {
LocalTransaction localTransaction = transactionTable.getLocalTransaction(transactionManager.getTransaction());
// The stored localTransaction could be null, if this is the first call in a transaction. In which case
// we know that there is no transactional state to refer to - i.e., no entries have been looked up as yet.
return localTransaction == null ? null : localTransaction.lookupEntry(key);
} catch (SystemException e) {
return null;
}
}