本文整理汇总了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;
}
示例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;
}
}
示例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;
}
示例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();
}
示例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;
}
示例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()));
}
示例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();
}
示例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;
}
示例9: extractTransactionalAnnotation
import org.apache.deltaspike.jpa.api.transaction.Transactional; //导入依赖的package包/类
/**
* @return the @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);
}
示例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;
}
示例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;
}
示例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
}
}
示例13: executeInTransaction
import org.apache.deltaspike.jpa.api.transaction.Transactional; //导入依赖的package包/类
@Transactional
public void executeInTransaction()
{
try
{
nestedTransactionBean.executeInTransaction();
}
catch (TestException e)
{
//expected -> do nothing
}
}
示例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
}
示例15: insert
import org.apache.deltaspike.jpa.api.transaction.Transactional; //导入依赖的package包/类
@Override
@Transactional
public void insert(Car entity) {
super.insert(entity);
}