Search in sources :

Example 6 with DefaultTransactionAttribute

use of org.springframework.transaction.interceptor.DefaultTransactionAttribute in project spring-framework by spring-projects.

the class TransactionAwareCacheDecoratorTests method evictTransactional.

@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));
}
Also used : ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) DefaultTransactionAttribute(org.springframework.transaction.interceptor.DefaultTransactionAttribute) TransactionStatus(org.springframework.transaction.TransactionStatus) ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) Cache(org.springframework.cache.Cache) Test(org.junit.Test)

Example 7 with DefaultTransactionAttribute

use of org.springframework.transaction.interceptor.DefaultTransactionAttribute in project spring-framework by spring-projects.

the class TransactionAwareCacheDecoratorTests method clearTransactional.

@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));
}
Also used : ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) DefaultTransactionAttribute(org.springframework.transaction.interceptor.DefaultTransactionAttribute) TransactionStatus(org.springframework.transaction.TransactionStatus) ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) Cache(org.springframework.cache.Cache) Test(org.junit.Test)

Aggregations

DefaultTransactionAttribute (org.springframework.transaction.interceptor.DefaultTransactionAttribute)7 Test (org.junit.Test)6 TransactionStatus (org.springframework.transaction.TransactionStatus)6 EntityManager (javax.persistence.EntityManager)3 EntityManagerFactory (javax.persistence.EntityManagerFactory)3 Cache (org.springframework.cache.Cache)3 ConcurrentMapCache (org.springframework.cache.concurrent.ConcurrentMapCache)3 EntityTransaction (javax.persistence.EntityTransaction)2 OptimisticLockException (javax.persistence.OptimisticLockException)1 DataSource (javax.sql.DataSource)1 ByteArrayResource (org.springframework.core.io.ByteArrayResource)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 Resource (org.springframework.core.io.Resource)1 OptimisticLockingFailureException (org.springframework.dao.OptimisticLockingFailureException)1 ResourceDatabasePopulator (org.springframework.jdbc.datasource.init.ResourceDatabasePopulator)1 MutablePersistenceUnitInfo (org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo)1 PlatformTransactionManager (org.springframework.transaction.PlatformTransactionManager)1 TransactionAttribute (org.springframework.transaction.interceptor.TransactionAttribute)1 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)1