本文整理汇总了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();
}
});
}
示例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());
}
});
}
示例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();
}
});
}
示例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));
}
});
}
示例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();
}
}
示例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;
}
示例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;
}
}
示例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;
}
示例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);
}
});
}
});
}
}
示例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;
}
});
}
示例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);
}
});
}
}
示例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();
}
});
}
示例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);
}
}
});
}
示例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));
}