List of usage examples for org.springframework.transaction.support TransactionTemplate setPropagationBehavior
public final void setPropagationBehavior(int propagationBehavior)
From source file:ca.uhn.fhir.jpa.dao.BaseHapiFhirSystemDao.java
private int doPerformReindexingPass(final Integer theCount) { TransactionTemplate txTemplate = new TransactionTemplate(myTxManager); txTemplate.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRED); int retVal = doPerformReindexingPassForResources(theCount, txTemplate); return retVal; }
From source file:fi.hsl.parkandride.core.service.PredictionService.java
private void doUpdatePredictions() { log.info("Updating predictions"); TransactionTemplate txTemplate = new TransactionTemplate(transactionManager); txTemplate.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED); // TODO: set in Core/JdbcConfiguration txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); for (Long predictorId : findPredictorsNeedingUpdate()) { try {//from w w w .j a v a 2 s . c o m txTemplate.execute(tx -> { updatePredictor(predictorId); log.debug("Updating predictor {} done", predictorId); return null; }); } catch (Exception e) { log.error("Failed to update predictor {}", predictorId, e); } } }
From source file:ca.uhn.fhir.jpa.dao.BaseHapiFhirSystemDao.java
private void markResourceAsIndexingFailed(final long theId) { TransactionTemplate txTemplate = new TransactionTemplate(myTxManager); txTemplate.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRES_NEW); txTemplate.execute(new TransactionCallback<Void>() { @Override/* ww w .ja v a 2 s . co m*/ public Void doInTransaction(TransactionStatus theStatus) { ourLog.info("Marking resource with PID {} as indexing_failed", new Object[] { theId }); Query q = myEntityManager .createQuery("UPDATE ResourceTable t SET t.myIndexStatus = :status WHERE t.myId = :id"); q.setParameter("status", INDEX_STATUS_INDEXING_FAILED); q.setParameter("id", theId); q.executeUpdate(); q = myEntityManager.createQuery("DELETE FROM ResourceTag t WHERE t.myResourceId = :id"); q.setParameter("id", theId); q.executeUpdate(); q = myEntityManager .createQuery("DELETE FROM ResourceIndexedSearchParamCoords t WHERE t.myResourcePid = :id"); q.setParameter("id", theId); q.executeUpdate(); q = myEntityManager .createQuery("DELETE FROM ResourceIndexedSearchParamDate t WHERE t.myResourcePid = :id"); q.setParameter("id", theId); q.executeUpdate(); q = myEntityManager .createQuery("DELETE FROM ResourceIndexedSearchParamNumber t WHERE t.myResourcePid = :id"); q.setParameter("id", theId); q.executeUpdate(); q = myEntityManager.createQuery( "DELETE FROM ResourceIndexedSearchParamQuantity t WHERE t.myResourcePid = :id"); q.setParameter("id", theId); q.executeUpdate(); q = myEntityManager .createQuery("DELETE FROM ResourceIndexedSearchParamString t WHERE t.myResourcePid = :id"); q.setParameter("id", theId); q.executeUpdate(); q = myEntityManager .createQuery("DELETE FROM ResourceIndexedSearchParamToken t WHERE t.myResourcePid = :id"); q.setParameter("id", theId); q.executeUpdate(); q = myEntityManager .createQuery("DELETE FROM ResourceIndexedSearchParamUri t WHERE t.myResourcePid = :id"); q.setParameter("id", theId); q.executeUpdate(); q = myEntityManager.createQuery("DELETE FROM ResourceLink t WHERE t.mySourceResourcePid = :id"); q.setParameter("id", theId); q.executeUpdate(); q = myEntityManager.createQuery("DELETE FROM ResourceLink t WHERE t.myTargetResourcePid = :id"); q.setParameter("id", theId); q.executeUpdate(); return null; } }); }
From source file:ca.uhn.fhir.jpa.dao.dstu3.FhirResourceDaoSubscriptionDstu3.java
@Override @Transactional(propagation = Propagation.NOT_SUPPORTED) public synchronized int pollForNewUndeliveredResources() { if (getConfig().isSubscriptionEnabled() == false) { return 0; }/* w w w . j a v a2 s. co m*/ ourLog.trace("Beginning pollForNewUndeliveredResources()"); // SubscriptionCandidateResource Collection<Long> subscriptions = mySubscriptionTableDao .findSubscriptionsWhichNeedToBeChecked(SubscriptionStatusEnum.ACTIVE.getCode(), new Date()); TransactionTemplate txTemplate = new TransactionTemplate(myTxManager); txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); int retVal = 0; for (final Long nextSubscriptionTablePid : subscriptions) { retVal += txTemplate.execute(new TransactionCallback<Integer>() { @Override public Integer doInTransaction(TransactionStatus theStatus) { SubscriptionTable nextSubscriptionTable = mySubscriptionTableDao .findOne(nextSubscriptionTablePid); return pollForNewUndeliveredResources(nextSubscriptionTable); } }); } return retVal; }
From source file:com.alibaba.otter.node.etl.load.loader.db.interceptor.operation.AbstractOperationInterceptor.java
private void init(final JdbcTemplate jdbcTemplate, final String markTableName, final String markTableColumn) { int count = jdbcTemplate .queryForInt(MessageFormat.format(checkDataSql, markTableName, GLOBAL_THREAD_COUNT - 1)); if (count != GLOBAL_THREAD_COUNT) { if (logger.isInfoEnabled()) { logger.info("Interceptor: init " + markTableName + "'s data."); }// w ww . j a v a 2 s . c o m TransactionTemplate transactionTemplate = new TransactionTemplate(); transactionTemplate .setTransactionManager(new DataSourceTransactionManager(jdbcTemplate.getDataSource())); transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_NOT_SUPPORTED);// ?????? transactionTemplate.execute(new TransactionCallback() { public Object doInTransaction(TransactionStatus status) { jdbcTemplate.execute(MessageFormat.format(deleteDataSql, markTableName)); String batchSql = MessageFormat.format(updateSql, new Object[] { markTableName, markTableColumn }); jdbcTemplate.batchUpdate(batchSql, new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int idx) throws SQLException { ps.setInt(1, idx); ps.setInt(2, 0); // ps.setNull(3, Types.VARCHAR); } public int getBatchSize() { return GLOBAL_THREAD_COUNT; } }); return null; } }); if (logger.isInfoEnabled()) { logger.info("Interceptor: Init EROSA Client Data: " + updateSql); } } }
From source file:ca.uhn.fhir.jpa.dao.dstu3.FhirResourceDaoSubscriptionDstu3.java
@Scheduled(fixedDelay = DateUtils.MILLIS_PER_MINUTE) @Transactional(propagation = Propagation.NOT_SUPPORTED) @Override//from ww w . j a v a2 s .co m public void purgeInactiveSubscriptions() { if (getConfig().isSchedulingDisabled()) { return; } Long purgeInactiveAfterMillis = getConfig().getSubscriptionPurgeInactiveAfterMillis(); if (getConfig().isSubscriptionEnabled() == false || purgeInactiveAfterMillis == null) { return; } Date cutoff = new Date(System.currentTimeMillis() - purgeInactiveAfterMillis); Collection<SubscriptionTable> toPurge = mySubscriptionTableDao.findInactiveBeforeCutoff(cutoff); for (SubscriptionTable subscriptionTable : toPurge) { final IdDt subscriptionId = subscriptionTable.getSubscriptionResource().getIdDt(); ourLog.info("Deleting inactive subscription {} - Created {}, last client poll {}", new Object[] { subscriptionId.toUnqualified(), subscriptionTable.getCreated(), subscriptionTable.getLastClientPoll() }); TransactionTemplate txTemplate = new TransactionTemplate(myTxManager); txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); txTemplate.execute(new TransactionCallback<Void>() { @Override public Void doInTransaction(TransactionStatus theStatus) { delete(subscriptionId, null); return null; } }); } }
From source file:org.fcrepo.camel.FcrepoTransactionManagerTest.java
@Test(expected = CannotCreateTransactionException.class) public void testTransactionBeginError() throws FcrepoOperationFailedException { final String baseUrl = "http://localhost:8080/rest"; final String tx = "tx:1234567890"; final URI beginUri = URI.create(baseUrl + FcrepoConstants.TRANSACTION); final FcrepoTransactionManager txMgr = new FcrepoTransactionManager(); txMgr.setBaseUrl(baseUrl);//from w ww. j ava2 s. co m TestUtils.setField(txMgr, "fcrepoClient", mockClient); final TransactionTemplate transactionTemplate = new TransactionTemplate(txMgr); final DefaultTransactionDefinition txDef = new DefaultTransactionDefinition( TransactionDefinition.PROPAGATION_REQUIRED); transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); transactionTemplate.afterPropertiesSet(); when(mockPostBuilder.perform()).thenThrow(new FcrepoOperationFailedException(beginUri, 400, "Bad Request")); txMgr.getTransaction(txDef); }
From source file:org.fcrepo.camel.FcrepoTransactionManagerTest.java
@Test(expected = CannotCreateTransactionException.class) public void testTransactionBeginNoLocationError() throws FcrepoOperationFailedException { final String baseUrl = "http://localhost:8080/rest"; final String tx = "tx:1234567890"; final URI beginUri = URI.create(baseUrl + FcrepoConstants.TRANSACTION); final FcrepoTransactionManager txMgr = new FcrepoTransactionManager(); txMgr.setBaseUrl(baseUrl);//from www.java2 s . c o m TestUtils.setField(txMgr, "fcrepoClient", mockClient); final TransactionTemplate transactionTemplate = new TransactionTemplate(txMgr); final DefaultTransactionDefinition txDef = new DefaultTransactionDefinition( TransactionDefinition.PROPAGATION_REQUIRED); transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); transactionTemplate.afterPropertiesSet(); when(mockPostBuilder.perform()).thenReturn(new FcrepoResponse(beginUri, 201, emptyMap(), null)); txMgr.getTransaction(txDef); }
From source file:org.fcrepo.camel.FcrepoTransactionManagerTest.java
@Test(expected = CannotCreateTransactionException.class) public void testTransactionNullResponseError() throws FcrepoOperationFailedException { final String baseUrl = "http://localhost:8080/rest"; final String tx = "tx:1234567890"; final URI beginUri = URI.create(baseUrl + FcrepoConstants.TRANSACTION); final FcrepoTransactionManager txMgr = new FcrepoTransactionManager(); txMgr.setBaseUrl(baseUrl);//from w w w . jav a 2 s.co m TestUtils.setField(txMgr, "fcrepoClient", mockClient); final TransactionTemplate transactionTemplate = new TransactionTemplate(txMgr); final DefaultTransactionDefinition txDef = new DefaultTransactionDefinition( TransactionDefinition.PROPAGATION_REQUIRED); transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); transactionTemplate.afterPropertiesSet(); when(mockPostBuilder.perform()).thenReturn(null); txMgr.getTransaction(txDef); }