back out Tx wrap

use qualifier
This commit is contained in:
Ken Stevens 2020-06-25 15:27:31 -04:00
parent 93da042d19
commit c11b6eeab6
2 changed files with 9 additions and 23 deletions

View File

@ -25,21 +25,21 @@ import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.batch.core.explore.support.MapJobExplorerFactoryBean; import org.springframework.batch.core.explore.support.MapJobExplorerFactoryBean;
import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.PlatformTransactionManager;
public class NonPersistedBatchConfigurer extends DefaultBatchConfigurer { public class NonPersistedBatchConfigurer extends DefaultBatchConfigurer {
@Autowired
@Qualifier("hapiTransactionManager")
private PlatformTransactionManager myHapiPlatformTransactionManager;
private PlatformTransactionManager myPlatformTransactionManager;
private MapJobRepositoryFactoryBean myJobRepositoryFactory; private MapJobRepositoryFactoryBean myJobRepositoryFactory;
@Override @Override
public PlatformTransactionManager getTransactionManager() { public PlatformTransactionManager getTransactionManager() {
if (myPlatformTransactionManager == null) { return myHapiPlatformTransactionManager;
myPlatformTransactionManager = new ResourcelessTransactionManager();
}
return myPlatformTransactionManager;
} }

View File

@ -48,11 +48,8 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.support.TransactionTemplate;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.PostConstruct;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -102,30 +99,19 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test {
EmpiSearchParameterLoader myEmpiSearchParameterLoader; EmpiSearchParameterLoader myEmpiSearchParameterLoader;
@Autowired @Autowired
SearchParamRegistryImpl mySearchParamRegistry; SearchParamRegistryImpl mySearchParamRegistry;
@Autowired
private PlatformTransactionManager myPlatformTransactionManager;
private TransactionTemplate myTxTemplate;
@PostConstruct
public void initTxTemplate() {
myTxTemplate = new TransactionTemplate(myPlatformTransactionManager);
}
protected ServletRequestDetails myRequestDetails = new ServletRequestDetails(null); protected ServletRequestDetails myRequestDetails = new ServletRequestDetails(null);
@Override @Override
@After @After
public void after() { public void after() {
// TODO KHS Why does adding Spring Batch now require us to wrap this in a transaction? myEmpiLinkDao.deleteAll();
myTxTemplate.executeWithoutResult(t -> myEmpiLinkDao.deleteAll());
assertEquals(0, myEmpiLinkDao.count()); assertEquals(0, myEmpiLinkDao.count());
super.after(); super.after();
} }
// TODO KHS Why does adding Spring Batch now require us to wrap this in a transaction? protected void saveLink(EmpiLink theEmpiLink) {
protected void saveLink(EmpiLink theNoMatchLink) { myEmpiLinkDaoSvc.save(theEmpiLink);
myTxTemplate.executeWithoutResult(t -> myEmpiLinkDaoSvc.save(theNoMatchLink));
} }
@Nonnull @Nonnull