public <T> T get(Contextual<T> component) { Map<Contextual, TransactionBeanEntry> transactionBeanEntryMap = getBeanStorage().getActiveTransactionContext(); if (transactionBeanEntryMap == null) { throw new ContextNotActiveException( "Not accessed within a transactional method - use @" + Transactional.class.getName()); } TransactionBeanEntry transactionBeanEntry = transactionBeanEntryMap.get(component); if (transactionBeanEntry != null) { return (T) transactionBeanEntry.getContextualInstance(); } return null; }
public <T> T get(Contextual<T> component, CreationalContext<T> creationalContext) { Map<Contextual, TransactionBeanEntry> transactionBeanEntryMap = getBeanStorage().getActiveTransactionContext(); if (transactionBeanEntryMap == null) { throw new ContextNotActiveException( "Not accessed within a transactional method - use @" + Transactional.class.getName()); } TransactionBeanEntry transactionBeanEntry = transactionBeanEntryMap.get(component); if (transactionBeanEntry != null) { return (T) transactionBeanEntry.getContextualInstance(); } // if it doesn't yet exist, we need to create it now! T instance = component.create(creationalContext); transactionBeanEntry = new TransactionBeanEntry(component, instance, creationalContext); transactionBeanEntryMap.put(component, transactionBeanEntry); return instance; }