本文整理汇总了Java中org.springframework.transaction.interceptor.DefaultTransactionAttribute类的典型用法代码示例。如果您正苦于以下问题:Java DefaultTransactionAttribute类的具体用法?Java DefaultTransactionAttribute怎么用?Java DefaultTransactionAttribute使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultTransactionAttribute类属于org.springframework.transaction.interceptor包,在下文中一共展示了DefaultTransactionAttribute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: evictTransactional
import org.springframework.transaction.interceptor.DefaultTransactionAttribute; //导入依赖的package包/类
@Test
public void evictTransactional() {
Cache target = new ConcurrentMapCache("testCache");
Cache cache = new TransactionAwareCacheDecorator(target);
Object key = new Object();
cache.put(key, "123");
TransactionStatus status = txManager.getTransaction(new DefaultTransactionAttribute(
TransactionDefinition.PROPAGATION_REQUIRED));
cache.evict(key);
assertEquals("123", target.get(key, String.class));
txManager.commit(status);
assertNull(target.get(key));
}
示例2: clearTransactional
import org.springframework.transaction.interceptor.DefaultTransactionAttribute; //导入依赖的package包/类
@Test
public void clearTransactional() {
Cache target = new ConcurrentMapCache("testCache");
Cache cache = new TransactionAwareCacheDecorator(target);
Object key = new Object();
cache.put(key, "123");
TransactionStatus status = txManager.getTransaction(new DefaultTransactionAttribute(
TransactionDefinition.PROPAGATION_REQUIRED));
cache.clear();
assertEquals("123", target.get(key, String.class));
txManager.commit(status);
assertNull(target.get(key));
}
示例3: newTaskExecutionTransactionTemplate
import org.springframework.transaction.interceptor.DefaultTransactionAttribute; //导入依赖的package包/类
/**
* Permet d'initialiser le TransactionManager utilisé pour l'exécution de la tâche.
* Dans la mesure du possible, surcharger plutôt {@link #getTaskExecutionTransactionTemplateConfig()}.
*/
protected TransactionTemplate newTaskExecutionTransactionTemplate(EntityManagerUtils entityManagerUtils,
PlatformTransactionManager transactionManager) {
TaskExecutionTransactionTemplateConfig config = getTaskExecutionTransactionTemplateConfig();
TransactionTemplate taskExecutionTransactionTemplate;
if (config.isTransactional()) {
DefaultTransactionAttribute defaultTransactionAttributes = new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
defaultTransactionAttributes.setReadOnly(config.isReadOnly());
taskExecutionTransactionTemplate = new TransactionTemplate(transactionManager, defaultTransactionAttributes);
} else {
taskExecutionTransactionTemplate = new OpenEntityManagerWithNoTransactionTransactionTemplate(
entityManagerUtils, transactionManager, config.isReadOnly());
}
return taskExecutionTransactionTemplate;
}
示例4: setTransactionTemplate
import org.springframework.transaction.interceptor.DefaultTransactionAttribute; //导入依赖的package包/类
@Autowired
private void setTransactionTemplate(PlatformTransactionManager transactionManager) {
DefaultTransactionAttribute writeTransactionAttribute =
new DefaultTransactionAttribute(TransactionAttribute.PROPAGATION_REQUIRED);
writeTransactionAttribute.setReadOnly(false);
writeTransactionTemplate = new TransactionTemplate(transactionManager, writeTransactionAttribute);
DefaultTransactionAttribute writeRequiresNewTransactionAttribute =
new DefaultTransactionAttribute(TransactionAttribute.PROPAGATION_REQUIRES_NEW);
writeRequiresNewTransactionAttribute.setReadOnly(false);
writeRequiresNewTransactionTemplate = new TransactionTemplate(transactionManager, writeRequiresNewTransactionAttribute);
DefaultTransactionAttribute readOnlyTransactionAttribute =
new DefaultTransactionAttribute(TransactionAttribute.PROPAGATION_REQUIRED);
readOnlyTransactionAttribute.setReadOnly(true);
readOnlyTransactionTemplate = new TransactionTemplate(transactionManager, readOnlyTransactionAttribute);
}
示例5: getTransactionAttributeSource
import org.springframework.transaction.interceptor.DefaultTransactionAttribute; //导入依赖的package包/类
@Override
public TransactionAttributeSource getTransactionAttributeSource() {
final TransactionAttributeSource origTxAttrSource = super.getTransactionAttributeSource();
return new TransactionAttributeSource() {
@Override
public TransactionAttribute getTransactionAttribute(final Method method, final Class<?> targetClass) {
TransactionAttribute txAttr = origTxAttrSource.getTransactionAttribute(method, targetClass);
if (txAttr instanceof DefaultTransactionAttribute) {
((DefaultTransactionAttribute) txAttr).setQualifier(AuthContextUtils.getDomain());
}
return txAttr;
}
};
}
示例6: beforeTestClass
import org.springframework.transaction.interceptor.DefaultTransactionAttribute; //导入依赖的package包/类
/**
* If the test method of the supplied {@link TestContext test context} is
* configured to run within a transaction, this method will run
* {@link BeforeTransaction @BeforeTransaction methods} and start a new
* transaction.
* <p>
* Note that if a {@link BeforeTransaction @BeforeTransaction method}
* fails, remaining {@link BeforeTransaction @BeforeTransaction
* methods} will not be invoked, and a transaction will not be started.
*
* @see org.springframework.transaction.annotation.Transactional
*/
@SuppressWarnings("serial")
@Override
public void beforeTestClass(TestContext testContext) throws Exception {
TransactionDefinition transactionDefinition = new DefaultTransactionAttribute();
if (transactionDefinition != null) {
PlatformTransactionManager tm = testContext.getApplicationContext()
.getBean(PlatformTransactionManager.class);
TransactionContext txContext = new TransactionContext(tm,
transactionDefinition);
startNewTransaction(testContext, txContext);
this.transactionContextCache.put(testContext.getTestClass(),
txContext);
}
}
示例7: addUserToGroup
import org.springframework.transaction.interceptor.DefaultTransactionAttribute; //导入依赖的package包/类
private void addUserToGroup(final User crowdUser, final Group group) {
if (crowdUser == null) {
log.warn("Cannot add null user to group!");
} else if (group == null) {
log.warn("Cannot add user to null group!");
} else {
new TransactionTemplate(getTransactionManager(), new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED)).execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
try {
getCrowdService().addUserToGroup(crowdUser, group);
} catch (Throwable t) {
log.error("Failed to add user " + crowdUser.getName() + " to group '" + group.getName() + "'!", t);
}
return null;
}
});
}
}
示例8: removeUserFromGroup
import org.springframework.transaction.interceptor.DefaultTransactionAttribute; //导入依赖的package包/类
private void removeUserFromGroup(final CrowdService crowdService, final User crowdUser, final Group group) {
if (crowdUser == null) {
log.warn("Cannot remove null user from group!");
} else if (group == null) {
log.warn("Cannot remove user from null group!");
} else {
new TransactionTemplate(getTransactionManager(), new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED)).execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
try {
crowdService.removeUserFromGroup(crowdUser, group);
} catch (Throwable t) {
log.error("Failed to remove user " + crowdUser.getName() + " from group '" + group.getName() + "'!", t);
}
return null;
}
});
}
}
示例9: createUser
import org.springframework.transaction.interceptor.DefaultTransactionAttribute; //导入依赖的package包/类
private void createUser(final UserAccessor userAccessor, final String username, final String fullName, final String emailAddress) {
if (username != null) {
new TransactionTemplate(getTransactionManager(), new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED)).execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
try {
userAccessor.createUser(new DefaultUser(username, null, null), Credential.NONE);
} catch (LicensingException le) {
log.error("Cannot create user '" + username + "'!", le);
// if you're having licensing issues, this needs to bubble up.
// see: https://github.com/chauth/confluence_http_authenticator/issues/33
throw le;
} catch (Throwable t) {
log.error("Failed to create user '" + username + "'!", t);
}
return null;
}
});
} else {
log.warn("Cannot add user with null username!");
}
}
示例10: updateUser
import org.springframework.transaction.interceptor.DefaultTransactionAttribute; //导入依赖的package包/类
private void updateUser(final CrowdService crowdService, final User crowdUser) {
if (crowdUser != null) {
new TransactionTemplate(getTransactionManager(), new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED)).execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
try {
crowdService.updateUser(crowdUser);
} catch (Throwable t) {
log.error("Failed to update user '" + crowdUser.getName() + "'!", t);
}
return null;
}
});
} else {
log.warn("Cannot update null user!");
}
}
示例11: testApplicationManagedEntityManagerWithTransaction
import org.springframework.transaction.interceptor.DefaultTransactionAttribute; //导入依赖的package包/类
@Test
public void testApplicationManagedEntityManagerWithTransaction() throws Exception {
Object testEntity = new Object();
EntityTransaction mockTx = mock(EntityTransaction.class);
// This one's for the tx (shared)
EntityManager sharedEm = mock(EntityManager.class);
given(sharedEm.getTransaction()).willReturn(new NoOpEntityTransaction());
// This is the application-specific one
EntityManager mockEm = mock(EntityManager.class);
given(mockEm.getTransaction()).willReturn(mockTx);
given(mockEmf.createEntityManager()).willReturn(sharedEm, mockEm);
LocalContainerEntityManagerFactoryBean cefb = parseValidPersistenceUnit();
JpaTransactionManager jpatm = new JpaTransactionManager();
jpatm.setEntityManagerFactory(cefb.getObject());
TransactionStatus txStatus = jpatm.getTransaction(new DefaultTransactionAttribute());
EntityManagerFactory emf = cefb.getObject();
assertSame("EntityManagerFactory reference must be cached after init", emf, cefb.getObject());
assertNotSame("EMF must be proxied", mockEmf, emf);
EntityManager em = emf.createEntityManager();
em.joinTransaction();
assertFalse(em.contains(testEntity));
jpatm.commit(txStatus);
cefb.destroy();
verify(mockTx).begin();
verify(mockTx).commit();
verify(mockEm).contains(testEntity);
verify(mockEmf).close();
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:41,代码来源:LocalContainerEntityManagerFactoryBeanTests.java
示例12: testApplicationManagedEntityManagerWithJtaTransaction
import org.springframework.transaction.interceptor.DefaultTransactionAttribute; //导入依赖的package包/类
@Test
public void testApplicationManagedEntityManagerWithJtaTransaction() throws Exception {
Object testEntity = new Object();
// This one's for the tx (shared)
EntityManager sharedEm = mock(EntityManager.class);
given(sharedEm.getTransaction()).willReturn(new NoOpEntityTransaction());
// This is the application-specific one
EntityManager mockEm = mock(EntityManager.class);
given(mockEmf.createEntityManager()).willReturn(sharedEm, mockEm);
LocalContainerEntityManagerFactoryBean cefb = parseValidPersistenceUnit();
MutablePersistenceUnitInfo pui = ((MutablePersistenceUnitInfo) cefb.getPersistenceUnitInfo());
pui.setTransactionType(PersistenceUnitTransactionType.JTA);
JpaTransactionManager jpatm = new JpaTransactionManager();
jpatm.setEntityManagerFactory(cefb.getObject());
TransactionStatus txStatus = jpatm.getTransaction(new DefaultTransactionAttribute());
EntityManagerFactory emf = cefb.getObject();
assertSame("EntityManagerFactory reference must be cached after init", emf, cefb.getObject());
assertNotSame("EMF must be proxied", mockEmf, emf);
EntityManager em = emf.createEntityManager();
em.joinTransaction();
assertFalse(em.contains(testEntity));
jpatm.commit(txStatus);
cefb.destroy();
verify(mockEm).joinTransaction();
verify(mockEm).contains(testEntity);
verify(mockEmf).close();
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:39,代码来源:LocalContainerEntityManagerFactoryBeanTests.java
示例13: putTransactional
import org.springframework.transaction.interceptor.DefaultTransactionAttribute; //导入依赖的package包/类
@Test
public void putTransactional() {
Cache target = new ConcurrentMapCache("testCache");
Cache cache = new TransactionAwareCacheDecorator(target);
TransactionStatus status = txManager.getTransaction(new DefaultTransactionAttribute(
TransactionDefinition.PROPAGATION_REQUIRED));
Object key = new Object();
cache.put(key, "123");
assertNull(target.get(key));
txManager.commit(status);
assertEquals("123", target.get(key, String.class));
}
示例14: setPlatformTransactionManager
import org.springframework.transaction.interceptor.DefaultTransactionAttribute; //导入依赖的package包/类
@Autowired
@Lazy // Mutable properties may require a more complex infrastructure, whose setup may require access to immutable properties
public void setPlatformTransactionManager(PlatformTransactionManager transactionManager) {
DefaultTransactionAttribute writeTransactionAttribute =
new DefaultTransactionAttribute(TransactionAttribute.PROPAGATION_REQUIRED);
writeTransactionAttribute.setReadOnly(false);
writeTransactionTemplate = new TransactionTemplate(transactionManager, writeTransactionAttribute);
}
示例15: setPlatformTransactionManager
import org.springframework.transaction.interceptor.DefaultTransactionAttribute; //导入依赖的package包/类
@Autowired
public void setPlatformTransactionManager(PlatformTransactionManager transactionManager) {
DefaultTransactionAttribute readOnlyTransactionAttribute = new DefaultTransactionAttribute(TransactionAttribute.PROPAGATION_REQUIRES_NEW);
readOnlyTransactionAttribute.setReadOnly(true);
readOnlyTransactionTemplate = new TransactionTemplate(transactionManager, readOnlyTransactionAttribute);
DefaultTransactionAttribute writeTransactionAttribute = new DefaultTransactionAttribute(TransactionAttribute.PROPAGATION_REQUIRES_NEW);
writeTransactionAttribute.setReadOnly(false);
writeTransactionTemplate = new TransactionTemplate(transactionManager, writeTransactionAttribute);
}
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:11,代码来源:TransactionScopeIndependantRunnerServiceImpl.java