org.apache.deltaspike.jpa.api.transaction.Transactional Java Examples

The following examples show how to use org.apache.deltaspike.jpa.api.transaction.Transactional. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransactionContext.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
public <T> T get(Contextual<T> component)
{
    Map<Contextual, TransactionBeanEntry> transactionBeanEntryMap =
            TransactionBeanStorage.getInstance().getActiveTransactionContext();

    if (transactionBeanEntryMap == null)
    {
        TransactionBeanStorage.close();

        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;
}
 
Example #2
Source File: TransactionContext.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
public <T> T get(Contextual<T> component, CreationalContext<T> creationalContext)
{
    Map<Contextual, TransactionBeanEntry> transactionBeanEntryMap =
        TransactionBeanStorage.getInstance().getActiveTransactionContext();

    if (transactionBeanEntryMap == null)
    {
        TransactionBeanStorage.close();

        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;
}
 
Example #3
Source File: FirstLevelTransactionBean.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
@Transactional
public void executeInTransaction()
{
    try
    {
        nestedTransactionBean.executeInTransaction();
    }
    catch (TestException e)
    {
        //expected -> do nothing
    }
}
 
Example #4
Source File: RepositoryMethodMetadataInitializer.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
public RepositoryMethodMetadata init(RepositoryMetadata repositoryMetadata, Method method, BeanManager beanManager)
{
    RepositoryMethodMetadata repositoryMethodMetadata = new RepositoryMethodMetadata();
    
    repositoryMethodMetadata.setMethod(method);

    repositoryMethodMetadata.setReturnsOptional(Optional.class.isAssignableFrom(method.getReturnType()));
    repositoryMethodMetadata.setReturnsStream(Stream.class.isAssignableFrom(method.getReturnType()));
    
    repositoryMethodMetadata.setQuery(method.isAnnotationPresent(Query.class)
            ? method.getAnnotation(Query.class) : null);
    repositoryMethodMetadata.setModifying(method.isAnnotationPresent(Modifying.class)
            ? method.getAnnotation(Modifying.class) : null);
    
    repositoryMethodMetadata.setTransactional(AnnotationUtils.extractAnnotationFromMethodOrClass(
            beanManager, method, repositoryMetadata.getRepositoryClass(), Transactional.class));

    repositoryMethodMetadata.setMethodPrefix(new RepositoryMethodPrefix(
                repositoryMetadata.getRepositoryClass().getAnnotation(Repository.class).methodPrefix(),
                method.getName()));
    repositoryMethodMetadata.setMethodType(
            extractMethodType(repositoryMetadata, repositoryMethodMetadata));
    
    repositoryMethodMetadata.setQueryProcessor(queryProcessorFactory.build(repositoryMethodMetadata));
    
    repositoryMethodMetadata.setQueryInOutMapperClass(
            extractMapper(method, repositoryMetadata));

    initQueryRoot(repositoryMetadata, repositoryMethodMetadata);
    initQueryInOutMapperIsNormalScope(repositoryMethodMetadata, beanManager);

    initSingleResultType(repositoryMethodMetadata);
    initRequiresTransaction(repositoryMethodMetadata);

    
    return repositoryMethodMetadata;
}
 
Example #5
Source File: TransactionStrategyHelper.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
/**
 * @return the &#064;Transactional annotation from either the method or class
 *         or <code>null</code> if none present.
 */
protected Transactional extractTransactionalAnnotation(InvocationContext context)
{
    Class targetClass = context.getTarget() != null ? context.getTarget().getClass() :
        context.getMethod().getDeclaringClass();
    return AnnotationUtils
        .extractAnnotationFromMethodOrClass(beanManager, context.getMethod(), targetClass, Transactional.class);
}
 
Example #6
Source File: EntityManagerMetadata.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
public boolean readFrom(AnnotatedElement method, BeanManager beanManager)
{
    EntityManagerConfig entityManagerConfig = method.getAnnotation(EntityManagerConfig.class);
    boolean processed = processEntityManagerConfig(beanManager, entityManagerConfig);

    Transactional transactional = method.getAnnotation(Transactional.class);

    processed = processTransactional(processed, transactional);

    return processed;
}
 
Example #7
Source File: EntityManagerMetadata.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
private boolean processTransactional(boolean processed, Transactional transactional)
{
    if (transactional != null && this.qualifiers == null)
    {
        processed = true;
        this.setQualifiers(transactional.qualifier());
    }

    if (transactional != null)
    {
        this.readOnly = transactional.readOnly();
    }
    return processed;
}
 
Example #8
Source File: FirstLevelTransactionBean.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
@Transactional
public void executeInTransaction()
{
    try
    {
        nestedTransactionBean.executeInTransaction();
    }
    catch (TestException e)
    {
        //catch to test that the transaction doesn't get rolled back
        //do nothing
    }
}
 
Example #9
Source File: TransactionalBean.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
/**
 * This methods requests a transaction for the EntityManager qualified with {@link Second} although there is no
 * producer for such an {@link EntityManager}.
 */
@Transactional
@EntityManagerConfig(qualifier = Second.class)
public void executeInTransaction()
{
    // no need to do anything
}
 
Example #10
Source File: NestedTransactionBean.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Transactional
public void executeInTransaction()
{
    secondEntityManager.getTransaction().setRollbackOnly();
}
 
Example #11
Source File: NestedTransactionBean.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Transactional
public void executeInTransaction()
{
}
 
Example #12
Source File: FirstLevelTransactionBean.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Transactional
public void executeInTransaction()
{
    nestedTransactionBean.executeInTransaction();
}
 
Example #13
Source File: MultiTransactionBean.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Transactional
public void executeInTransactionRollback2()
{
    this.secondEntityManager.getTransaction().setRollbackOnly();
}
 
Example #14
Source File: MultiTransactionBean.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Transactional
public void executeInTransactionRollback1()
{
    this.firstEntityManager.getTransaction().setRollbackOnly();
}
 
Example #15
Source File: MultiTransactionBean.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Transactional
public void executeInTransactionRollbackDefault()
{
    this.defaultEntityManager.getTransaction().setRollbackOnly();
}
 
Example #16
Source File: NestedTransactionBean.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Transactional
public void executeInTransaction()
{
    throw new TestException();
}
 
Example #17
Source File: FirstLevelTransactionBean.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Transactional
public void executeInTransaction()
{
    nestedTransactionBean.executeInTransaction();
}
 
Example #18
Source File: MultiTransactionBean.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Transactional
public void executeInTransaction()
{
    throw new TestException();
}
 
Example #19
Source File: NestedTransactionBean.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Transactional
public void executeInTransaction()
{
}
 
Example #20
Source File: FirstLevelTransactionBean.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Transactional
public void executeInTransaction()
{
    nestedTransactionBean.executeInTransaction();
}
 
Example #21
Source File: MultiTransactionBean.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Transactional
public void executeInTransaction()
{
}
 
Example #22
Source File: FirstLevelTransactionBean.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Transactional
public void executeInTransaction()
{
    nestedTransactionBean.executeInTransaction();
}
 
Example #23
Source File: NestedTransactionBean.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Transactional
public void executeInTransaction()
{
}
 
Example #24
Source File: FirstLevelTransactionBean.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Transactional
public void executeInTransaction()
{
    nestedTransactionBean.executeInTransaction();
}
 
Example #25
Source File: NestedTransactionBean.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Transactional
public void executeInTransaction()
{
    throw new TestException();
}
 
Example #26
Source File: ManualTransactionBean.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Transactional(qualifier = Default.class)
public void executeInDefaultTransaction()
{
}
 
Example #27
Source File: ManualTransactionBean.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Transactional(qualifier = First.class)
public void executeInFirstTransaction()
{
}
 
Example #28
Source File: ManualTransactionBean.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Transactional(qualifier = Second.class)
public void executeInSecondTransaction()
{
}
 
Example #29
Source File: ManualTransactionBean.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Transactional
public void executeInTransaction()
{
}
 
Example #30
Source File: MultiTransactionBean.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Transactional
public void executeInTransaction()
{
}