use of org.springframework.transaction.support.TransactionSynchronizationAdapter in project gocd by gocd.
the class GitMaterial method git.
private GitCommand git(ProcessOutputStreamConsumer outputStreamConsumer, final File workingFolder, int preferredCloneDepth, SubprocessExecutionContext executionContext) throws Exception {
if (isSubmoduleFolder()) {
return new GitCommand(getFingerprint(), new File(workingFolder.getPath()), GitMaterialConfig.DEFAULT_BRANCH, true, executionContext.getDefaultEnvironmentVariables(), secrets());
}
GitCommand gitCommand = new GitCommand(getFingerprint(), workingFolder, getBranch(), false, executionContext.getDefaultEnvironmentVariables(), secrets());
if (!isGitRepository(workingFolder) || isRepositoryChanged(gitCommand, workingFolder)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Invalid git working copy or repository changed. Delete folder: " + workingFolder);
}
deleteDirectoryNoisily(workingFolder);
}
createParentFolderIfNotExist(workingFolder);
if (!workingFolder.exists()) {
TransactionSynchronizationManager txManager = new TransactionSynchronizationManager();
if (txManager.isActualTransactionActive()) {
txManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCompletion(int status) {
if (status != TransactionSynchronization.STATUS_COMMITTED) {
FileUtils.deleteQuietly(workingFolder);
}
}
});
}
int cloneDepth = shallowClone ? preferredCloneDepth : Integer.MAX_VALUE;
int returnValue;
if (executionContext.isServer()) {
returnValue = gitCommand.cloneWithNoCheckout(outputStreamConsumer, url.forCommandline());
} else {
returnValue = gitCommand.clone(outputStreamConsumer, url.forCommandline(), cloneDepth);
}
bombIfFailedToRunCommandLine(returnValue, "Failed to run git clone command");
}
return gitCommand;
}
use of org.springframework.transaction.support.TransactionSynchronizationAdapter in project gocd by gocd.
the class StageService method cancelStage.
public synchronized void cancelStage(final Stage stage) {
cancel(stage);
notifyStageStatusChangeListeners(stage);
transactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCommit() {
stageStatusTopic.post(new StageStatusMessage(stage.getIdentifier(), stage.stageState(), stage.getResult(), UserHelper.getUserName()));
}
});
}
use of org.springframework.transaction.support.TransactionSynchronizationAdapter in project gocd by gocd.
the class StageSqlMapDao method updateResult.
public void updateResult(final Stage stage, final StageResult result) {
transactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCommit() {
StageIdentifier identifier = stage.getIdentifier();
clearStageHistoryPageCaches(stage, identifier.getPipelineName(), true);
clearJobStatusDependentCaches(stage.getId(), identifier);
removeFromCache(cacheKeyForStageCountForGraph(identifier.getPipelineName(), identifier.getStageName()));
}
});
getSqlMapClientTemplate().update("updateStageStatus", arguments("stageId", stage.getId()).and("result", result.toString()).and("state", stage.getState()).and("completedByTransitionId", stage.getCompletedByTransitionId()).asMap());
upddateLastTransitionedTime(stage);
}
use of org.springframework.transaction.support.TransactionSynchronizationAdapter in project motech by motech.
the class DefaultMotechDataService method create.
@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;
}
use of org.springframework.transaction.support.TransactionSynchronizationAdapter in project motech by motech.
the class DefaultMotechDataService method update.
@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;
}
}
Aggregations