当前位置: 首页>>代码示例>>Java>>正文


Java Transactional类代码示例

本文整理汇总了Java中org.apache.deltaspike.jpa.api.transaction.Transactional的典型用法代码示例。如果您正苦于以下问题:Java Transactional类的具体用法?Java Transactional怎么用?Java Transactional使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Transactional类属于org.apache.deltaspike.jpa.api.transaction包,在下文中一共展示了Transactional类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: persist

import org.apache.deltaspike.jpa.api.transaction.Transactional; //导入依赖的package包/类
/**
 * Persist the entity.
 *
 * @param  entity  the entity.
 *
 * @return  the persisted entity.
 */
@Transactional
@Override
public <T> T persist(final T entity) {

    // Check if the entity does not exist.
    // This is needed to get OpenJPA to behave like EclipseLink.
    if (entity == null) {
        throw new IllegalArgumentException("The entity cannot be null.");
    }
    
    // Persist the entity.
    T persistedEntity = this.entityManager.merge(entity);
    this.entityManager.flush();

    return persistedEntity;
}
 
开发者ID:lazydog-org,项目名称:repository-parent,代码行数:24,代码来源:AbstractRepository.java

示例2: criaConta

import org.apache.deltaspike.jpa.api.transaction.Transactional; //导入依赖的package包/类
@Transactional
public boolean criaConta(String nome) {
	try {
		RepositorioPessoa repoPessoa = new FabricaRepositorios(entityManager)
											.construirRepositorioPessoa();
		
		Pessoa a = new Pessoa();
		a.setName(nome);

		repoPessoa.adicionar(a);
		
		return true;
	} catch (Exception e) {
		e.printStackTrace();
		return false;
	}
}
 
开发者ID:sedesdev,项目名称:deltaspike-jboss7-archetype,代码行数:18,代码来源:PessoaAS.java

示例3: persistList

import org.apache.deltaspike.jpa.api.transaction.Transactional; //导入依赖的package包/类
/**
 * Persist the list of entities.
 *
 * @param  entities  the entities.
 *
 * @return  the persisted list of entities.
 */
@Transactional
@Override
public <T> List<T> persistList(final List<T> entities) {

    // Initialize.
    List<T> persistedEntities = new ArrayList<T>();

    // Loop through the entities.
    for (T entity : entities) {

        // Persist the entity.
        T persistedEntity = this.persist(entity);

        // Add the persisted entity.
        persistedEntities.add(persistedEntity);
    }

    // Clear the entity manager.
    this.entityManager.clear();
    
    return persistedEntities;
}
 
开发者ID:lazydog-org,项目名称:repository-parent,代码行数:30,代码来源:AbstractRepository.java

示例4: remove

import org.apache.deltaspike.jpa.api.transaction.Transactional; //导入依赖的package包/类
/**
 * Remove the entity.
 *
 * @param  entityClass  the entity class.
 * @param  id           the ID.
 */
@Transactional
@Override
public <T,U> void remove(final Class<T> entityClass, final U id) {

    // Check if the entity class does not exist.
    // This is needed to get Hibernate to behave like EclipseLink.
    if (entityClass == null) {
        throw new IllegalArgumentException("The entity class cannot be null.");
    }
    
    // Check if the ID does not exist.
    // This is needed to get OpenJPA to behave like EclipseLink.
    if (id == null) {
        throw new IllegalArgumentException("The ID cannot be null.");
    }

    // Get the entity.
    T entity = this.entityManager.getReference(entityClass, id);

    // Remove the entity.
    this.entityManager.remove(entity);
    this.entityManager.flush();
}
 
开发者ID:lazydog-org,项目名称:repository-parent,代码行数:30,代码来源:AbstractRepository.java

示例5: get

import org.apache.deltaspike.jpa.api.transaction.Transactional; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:22,代码来源:TransactionContext.java

示例6: testSelectByLastName

import org.apache.deltaspike.jpa.api.transaction.Transactional; //导入依赖的package包/类
@Test
@Transactional(readOnly = true)
public void testSelectByLastName() {
    UserEntity user = UserFactory.create();
    user.setLastName(RandomStringUtils.randomAlphanumeric(32));

    repo.create(user);

    List<UserEntity> result = repo.selectByLastName(user.getLastName());

    assertThat("stored user last name", result.get(0).getLastName(), is(user.getLastName()));
}
 
开发者ID:sitoolkit,项目名称:sit-ad-archetype-javaee7-web,代码行数:13,代码来源:UserRepositoryTest.java

示例7: removeList

import org.apache.deltaspike.jpa.api.transaction.Transactional; //导入依赖的package包/类
/**
 * Remove the entities by the list of IDs.
 *
 * @param  entityClass  the entity class.
 * @param  ids          the IDs.
 */
@Transactional
@Override
public <T,U> void removeList(final Class<T> entityClass, final List<U> ids) {

    // Loop through the IDs.
    for (U id: ids) {

        // Remove the entity.
        this.remove(entityClass, id);
    }
    
    // Clear the entity manager.
    this.entityManager.clear();
}
 
开发者ID:lazydog-org,项目名称:repository-parent,代码行数:21,代码来源:AbstractRepository.java

示例8: init

import org.apache.deltaspike.jpa.api.transaction.Transactional; //导入依赖的package包/类
public RepositoryMethodMetadata init(RepositoryMetadata repositoryMetadata, Method method, BeanManager beanManager)
{
    RepositoryMethodMetadata repositoryMethodMetadata = new RepositoryMethodMetadata();
    
    repositoryMethodMetadata.setMethod(method);

    repositoryMethodMetadata.setReturnsOptional(
            OptionalUtil.isOptionalReturned(method));
    repositoryMethodMetadata.setReturnsStream(
            StreamUtil.isStreamReturned(method));
    
    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(repositoryMetadata, repositoryMethodMetadata, beanManager);

    initSingleResultType(repositoryMethodMetadata);
    initRequiresTransaction(repositoryMethodMetadata);

    
    return repositoryMethodMetadata;
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:40,代码来源:RepositoryMethodMetadataInitializer.java

示例9: extractTransactionalAnnotation

import org.apache.deltaspike.jpa.api.transaction.Transactional; //导入依赖的package包/类
/**
 * @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);
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:12,代码来源:TransactionStrategyHelper.java

示例10: readFrom

import org.apache.deltaspike.jpa.api.transaction.Transactional; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:12,代码来源:EntityManagerMetadata.java

示例11: processTransactional

import org.apache.deltaspike.jpa.api.transaction.Transactional; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:15,代码来源:EntityManagerMetadata.java

示例12: executeInTransaction

import org.apache.deltaspike.jpa.api.transaction.Transactional; //导入依赖的package包/类
@Transactional
public void executeInTransaction()
{
    try
    {
        nestedTransactionBean.executeInTransaction();
    }
    catch (TestException e)
    {
        //catch to test that the transaction doesn't get rolled back
        //do nothing
    }
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:14,代码来源:FirstLevelTransactionBean.java

示例13: executeInTransaction

import org.apache.deltaspike.jpa.api.transaction.Transactional; //导入依赖的package包/类
@Transactional
public void executeInTransaction()
{
    try
    {
        nestedTransactionBean.executeInTransaction();
    }
    catch (TestException e)
    {
        //expected -> do nothing
    }
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:13,代码来源:FirstLevelTransactionBean.java

示例14: executeInTransaction

import org.apache.deltaspike.jpa.api.transaction.Transactional; //导入依赖的package包/类
/**
 * 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
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:11,代码来源:TransactionalBean.java

示例15: insert

import org.apache.deltaspike.jpa.api.transaction.Transactional; //导入依赖的package包/类
@Override
@Transactional
public void insert(Car entity) {
    super.insert(entity);
}
 
开发者ID:adminfaces,项目名称:admin-persistence,代码行数:6,代码来源:CarService.java


注:本文中的org.apache.deltaspike.jpa.api.transaction.Transactional类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。