Search in sources :

Example 1 with TransactionSynchronizationAdapter

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;
}
Also used : TransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TransactionSynchronizationManager) File(java.io.File) TransactionSynchronizationAdapter(org.springframework.transaction.support.TransactionSynchronizationAdapter) GitCommand(com.thoughtworks.go.domain.materials.git.GitCommand)

Example 2 with TransactionSynchronizationAdapter

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()));
        }
    });
}
Also used : StageStatusMessage(com.thoughtworks.go.server.messaging.StageStatusMessage) TransactionSynchronizationAdapter(org.springframework.transaction.support.TransactionSynchronizationAdapter)

Example 3 with TransactionSynchronizationAdapter

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);
}
Also used : TransactionSynchronizationAdapter(org.springframework.transaction.support.TransactionSynchronizationAdapter)

Example 4 with TransactionSynchronizationAdapter

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;
}
Also used : TransactionSynchronizationAdapter(org.springframework.transaction.support.TransactionSynchronizationAdapter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with TransactionSynchronizationAdapter

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;
    }
}
Also used : TransactionSynchronizationAdapter(org.springframework.transaction.support.TransactionSynchronizationAdapter) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

TransactionSynchronizationAdapter (org.springframework.transaction.support.TransactionSynchronizationAdapter)34 TransactionStatus (org.springframework.transaction.TransactionStatus)13 Test (org.junit.jupiter.api.Test)8 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)8 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)6 TransactionCallback (org.springframework.transaction.support.TransactionCallback)4 TransactionSynchronizationManager (com.thoughtworks.go.server.transaction.TransactionSynchronizationManager)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Pipeline (com.thoughtworks.go.domain.Pipeline)2 PipelineState (com.thoughtworks.go.domain.PipelineState)2 User (com.thoughtworks.go.domain.User)2 GitCommand (com.thoughtworks.go.domain.materials.git.GitCommand)2 StageStatusMessage (com.thoughtworks.go.server.messaging.StageStatusMessage)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 TransactionSynchronization (org.springframework.transaction.support.TransactionSynchronization)2 Cloner (com.rits.cloning.Cloner)1