當前位置: 首頁>>代碼示例>>Java>>正文


Java TransactionSynchronizationAdapter類代碼示例

本文整理匯總了Java中org.springframework.transaction.support.TransactionSynchronizationAdapter的典型用法代碼示例。如果您正苦於以下問題:Java TransactionSynchronizationAdapter類的具體用法?Java TransactionSynchronizationAdapter怎麽用?Java TransactionSynchronizationAdapter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TransactionSynchronizationAdapter類屬於org.springframework.transaction.support包,在下文中一共展示了TransactionSynchronizationAdapter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handleComposeMessageCreateCommand

import org.springframework.transaction.support.TransactionSynchronizationAdapter; //導入依賴的package包/類
private void handleComposeMessageCreateCommand(final Object obj) throws IOException {
  final ComposeMessageCreateCommand cmd = (ComposeMessageCreateCommand) obj;
  final Message message = new MessageBuilder().transferId(cmd.getTransferId())
      .messageState(MessageState.TO_COMPOSE).build();


  message.setInternalData(InternalDataUtils.convertInternalDataToJson(cmd.getData()));

  final BasicOutboundConfiguration configuration =
      basicConfigurationRepository.findOne(cmd.getConfigId());
  message.setOutboundConfiguration(configuration);

  messageRepository.save((MessageImpl) message);
  final String actorId = getContext().parent().path().name();
  TransactionSynchronizationManager
      .registerSynchronization(new TransactionSynchronizationAdapter() {
        @Override
        public void afterCommit() {
          LOG.info("Saved new [{}]", message);
          getSender().tell(new ComposeMessageCreatedEvent(actorId, message.getId()), getSelf());
          stop();
        }
      });
}
 
開發者ID:stefanstaniAIM,項目名稱:IPPR2016,代碼行數:25,代碼來源:ComposePersistenceActor.java

示例2: execute

import org.springframework.transaction.support.TransactionSynchronizationAdapter; //導入依賴的package包/類
@Override
public void execute(final AssignUsersMessage.Request request) throws Exception {
  request.getUserAssignments().forEach(assignment -> {
    final Subject subject = subjectRepository
        .getSubjectForSubjectModelInProcess(request.getPiId(), assignment.getSmId());
    if (subject != null) {
      subject.setUser(assignment.getUserId());
      subjectRepository.save((SubjectImpl) subject);
      LOG.info("New user for subject: {}", subject);
    }
  });

  final ActorRef sender = getSender();
  TransactionSynchronizationManager
      .registerSynchronization(new TransactionSynchronizationAdapter() {
        @Override
        public void afterCommit() {
          sender.tell(new AssignUsersMessage.Response(), getSelf());
        }
      });

}
 
開發者ID:stefanstaniAIM,項目名稱:IPPR2016,代碼行數:23,代碼來源:UserAssignmentsTask.java

示例3: handleStoreExternalDataCommand

import org.springframework.transaction.support.TransactionSynchronizationAdapter; //導入依賴的package包/類
private void handleStoreExternalDataCommand(final Object obj) {
  final StoreExternalDataCommand cmd = (StoreExternalDataCommand) obj;
  final Message message = messageRepository.findOne(cmd.getId());
  message.setExternalData(cmd.getData());
  message.setMessageState(MessageState.COMPOSED);
  messageRepository.save((MessageImpl) message);
  final String actorId = getContext().parent().path().name();

  final ActorRef sender = getSender();
  TransactionSynchronizationManager
      .registerSynchronization(new TransactionSynchronizationAdapter() {
        @Override
        public void afterCommit() {
          LOG.info("Updated external data of [{}]", message);
          sender.tell(new ComposedMessageEvent(actorId, message.getId()), getSelf());
          stop();
        }
      });
}
 
開發者ID:stefanstaniAIM,項目名稱:IPPR2016,代碼行數:20,代碼來源:ComposePersistenceActor.java

示例4: postUpdate

import org.springframework.transaction.support.TransactionSynchronizationAdapter; //導入依賴的package包/類
@PostUpdate
@Async
public void postUpdate(Object object) {
    LOG.info("Listening to post update for object:" + object);
    // Entitys have to be annotated with @EventListeners and reference this class in that annotation, because of this
    // the usages of this class are not executed withing the handle of the Spring context. So now we have to use this funky
    // ass way of wiring in fields AS this method is being called. #sadface
    AutowireHelper.autowire(this);
    // Trying to just add @Transactional(Transactional.TxType.REQUIRES_NEW) to this method didn't work at all, it was just being ignored.
    // This wrapper is what ended up working.
    TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
        @Override
        public void afterCompletion(int status) {
            super.afterCompletion(status);
            List<Webhook> hooks = webhookManager.retrieveWebhooksByEntityNameAndEventType(object.getClass().getSimpleName(), "post-update");
            hooks.stream().forEach(wh -> webhookProcessor.notifyWebhook(wh, object));
        }
    });

}
 
開發者ID:jfillo,項目名稱:spring-data-rest-webhook,代碼行數:21,代碼來源:WebhookEntityListener.java

示例5: sendMail

import org.springframework.transaction.support.TransactionSynchronizationAdapter; //導入依賴的package包/類
private void sendMail(final HarvestPermit permit, final GameSpecies species) {
    final Set<String> emails = findEmails(permit);
    final AllPartnersFinishedHuntingMailService.MailData data = getMailData(permit, species);
    TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
        @Override
        public void afterCommit() {
            try {
                // NOTE: Must invoke through proxy to make sure new transaction is started
                mailService.sendEmailAsync(emails, data);
            } catch (RuntimeException ex) {
                // Exception should be handled, so that HTTP status code is not altered
                LOG.error("Error occurred while sending emails", ex);
            }
        }
    });
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:17,代碼來源:AllPartnersFinishedHuntingMailFeature.java

示例6: storeFile

import org.springframework.transaction.support.TransactionSynchronizationAdapter; //導入依賴的package包/類
@Override
public void storeFile(final FileType fileType,
                      final PersistentFileMetadata metadata,
                      final InputStream inputStream) throws IOException {
    final Path storageFolder = fileType.resolveLocalStorageFolder(this.storageBasePath);
    final Path storageFile = storageFolder.resolve(fileType.formatFilename(metadata));

    TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
        @Override
        public void afterCompletion(final int status) {
            // Remove file if transaction is rolled back
            if (status == STATUS_ROLLED_BACK) {
                deleteIfExists(storageFile, false);
            }
        }
    });

    metadata.setResourceUrl(storageFile.toUri().toURL());

    try {
        Files.copy(inputStream, storageFile, StandardCopyOption.REPLACE_EXISTING);
    } finally {
        inputStream.close();
    }
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:26,代碼來源:LocalFolderFileStorage.java

示例7: create

import org.springframework.transaction.support.TransactionSynchronizationAdapter; //導入依賴的package包/類
@Override
@Transactional
public T create(final T object) {
    validateCredentials();

    final T createdInstance = repository.create(object);

    TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
        @Override
        public void afterCommit() {
            if (allowCreateEvent) {
                sendEvent((Long) getId(createdInstance), CREATE);
            }
        }
    });

    return createdInstance;
}
 
開發者ID:motech,項目名稱:motech,代碼行數:19,代碼來源:DefaultMotechDataService.java

示例8: update

import org.springframework.transaction.support.TransactionSynchronizationAdapter; //導入依賴的package包/類
@Override
@Transactional
public T update(final T object) {
    if (JDOHelper.getObjectState(object) == ObjectState.TRANSIENT) {
        return updateFromTransient(object);
    } else {
        validateCredentials(object);

        updateModificationData(object);
        final T updatedInstance = repository.update(object);

        TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
            @Override
            public void afterCommit() {
                if (allowUpdateEvent) {
                    sendEvent((Long) getId(updatedInstance), UPDATE);
                }
            }
        });

        return updatedInstance;
    }
}
 
開發者ID:motech,項目名稱:motech,代碼行數:24,代碼來源:DefaultMotechDataService.java

示例9: changeSingleTeamHost

import org.springframework.transaction.support.TransactionSynchronizationAdapter; //導入依賴的package包/類
@Transactional
public Team changeSingleTeamHost(final ChangeTeamHost changeTeamHost) {

	final String teamKey = changeTeamHost.getTeamKey();
	final String hostingParticipantKey = changeTeamHost.getHostingParticipantKey();

	final Team team = repository.loadSingleTeamWithVisitationPlan(teamKey, false);

	validateChangeTeamHost(changeTeamHost, team);
	
	changeSingleTeamHost(team, hostingParticipantKey);
	
	// Publish event only after transaction is successfully committed:
	TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
		@Override
		public void afterCommit() {
			eventPublisher.notifyTeamHostChangeByParticipant(team, changeTeamHost);
		}
	});
	
	return team;
}
 
開發者ID:Clemens85,項目名稱:runningdinner,代碼行數:23,代碼來源:RunningDinnerServiceImpl.java

示例10: associateCookie

import org.springframework.transaction.support.TransactionSynchronizationAdapter; //導入依賴的package包/類
public void associateCookie(final AgentIdentifier agentIdentifier, final String cookie) {
    final String uuid = agentIdentifier.getUuid();
    final String key = agentCacheKey(uuid);
    synchronized (key) {
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            @Override protected void doInTransactionWithoutResult(TransactionStatus status) {
                Agent agent = fetchAgentByUuid(uuid);
                if (agent == null) {
                    agent = new Agent(uuid, cookie, agentIdentifier.getHostName(), agentIdentifier.getIpAddress());
                } else {
                    agent.update(cookie, agentIdentifier.getHostName(), agentIdentifier.getIpAddress());
                }
                getHibernateTemplate().saveOrUpdate(agent);
                synchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
                    @Override public void afterCommit() {
                        cache.remove(key);                            
                    }
                });
            }
        });
    }
}
 
開發者ID:gocd,項目名稱:gocd,代碼行數:23,代碼來源:AgentDao.java

示例11: save

import org.springframework.transaction.support.TransactionSynchronizationAdapter; //導入依賴的package包/類
public Pipeline save(final Pipeline pipeline) {
    return (Pipeline) transactionTemplate.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus status) {
            transactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
                @Override
                public void afterCommit() {
                    goCache.remove(cacheKeyForLatestPipelineIdByPipelineName(pipeline.getName()));
                    invalidateCacheConditionallyForPipelineInstancesTriggeredWithDependencyMaterial(pipeline);
                }
            });

            Long pipelineId = (Long) getSqlMapClientTemplate().insert("insertPipeline", pipeline);
            savePipelineMaterialRevisions(pipeline, pipelineId);
            environmentVariableDao.save(pipelineId, EnvironmentVariableType.Trigger, pipeline.scheduleTimeVariables());
            return pipeline;
        }
    });
}
 
開發者ID:gocd,項目名稱:gocd,代碼行數:19,代碼來源:PipelineSqlMapDao.java

示例12: unlockPipeline

import org.springframework.transaction.support.TransactionSynchronizationAdapter; //導入依賴的package包/類
public void unlockPipeline(final String pipelineName) {
    synchronized (pipelineLockStateCacheKey(pipelineName)) {
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                transactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
                    @Override
                    public void afterCommit() {
                        clearLockedPipelineStateCache(pipelineName);
                    }
                });

                final String cacheKey = pipelineLockStateCacheKey(pipelineName);
                PipelineState fromCache = pipelineStateFor(pipelineName);
                PipelineState toBeSaved = null;
                if (fromCache == null) {
                    toBeSaved = new PipelineState(pipelineName);
                } else {
                    toBeSaved = (PipelineState) sessionFactory.getCurrentSession().load(PipelineState.class, fromCache.getId());
                }
                toBeSaved.unlock();
                sessionFactory.getCurrentSession().saveOrUpdate(toBeSaved);
            }
        });
    }
}
 
開發者ID:gocd,項目名稱:gocd,代碼行數:27,代碼來源:PipelineStateDao.java

示例13: changeEnabledStatus

import org.springframework.transaction.support.TransactionSynchronizationAdapter; //導入依賴的package包/類
private void changeEnabledStatus(final List<String> usernames, final boolean enabled) {
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {
        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            transactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
                @Override
                public void afterCommit() {
                    clearEnabledUserCountFromCache();
                }
            });
            String queryString = String.format("update %s set enabled = :enabled where name in (:userNames)", User.class.getName());
            Query query = sessionFactory.getCurrentSession().createQuery(queryString);
            query.setParameter("enabled", enabled);
            query.setParameterList("userNames", usernames);
            query.executeUpdate();
        }
    });
}
 
開發者ID:gocd,項目名稱:gocd,代碼行數:19,代碼來源:UserSqlMapDao.java

示例14: notifyJobStatusChangeListeners

import org.springframework.transaction.support.TransactionSynchronizationAdapter; //導入依賴的package包/類
private void notifyJobStatusChangeListeners(final JobInstance job) {
    transactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
        @Override
        public void afterCommit() {
            List<JobStatusListener> listeners1;
            synchronized (LISTENERS_MODIFICATION_MUTEX) {
                listeners1 = new ArrayList<>(listeners);
            }
            for (JobStatusListener jobStatusListener : listeners1)
                try {
                    jobStatusListener.jobStatusChanged(job);
                } catch (Exception e) {
                    LOGGER.error("error notifying listener for job {}", job, e);
                }
        }
    });
}
 
開發者ID:gocd,項目名稱:gocd,代碼行數:18,代碼來源:JobInstanceService.java

示例15: TransactionTemplate

import org.springframework.transaction.support.TransactionSynchronizationAdapter; //導入依賴的package包/類
@Test
public void shouldAllowRegistrationOfTransactionSynchronization_inTransactionSurroundingBlock_andNotExecuteSynchronizationIfTransactionNeverHappens() {
    TransactionTemplate template = new TransactionTemplate(transactionTemplate);

    final boolean[] afterCommitHappened = new boolean[1];

    String returnVal = (String) template.transactionSurrounding(new TransactionTemplate.TransactionSurrounding<RuntimeException>() {
        public Object surrounding() {
            transactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
                @Override public void afterCommit() {
                    afterCommitHappened[0] = true;
                }
            });
            return "bar";
        }
    });

    assertThat(returnVal, is("bar"));
    assertThat(afterCommitHappened[0], is(false));
}
 
開發者ID:gocd,項目名稱:gocd,代碼行數:21,代碼來源:TransactionTemplateTest.java


注:本文中的org.springframework.transaction.support.TransactionSynchronizationAdapter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。