use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class AccessTokenSqlMapDao method findAllTokensForUser.
@Override
public List<AccessToken> findAllTokensForUser(String username, AccessTokenFilter filter) {
return (List<AccessToken>) transactionTemplate.execute((TransactionCallback) transactionStatus -> {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(AccessToken.class).add(Restrictions.eq("username", username)).add(Restrictions.eq("deletedBecauseUserDeleted", false));
filter.applyTo(criteria);
return criteria.setCacheable(true).list();
});
}
use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class PluggableSCMMaterialUpdater method insertLatestOrNewModifications.
@Override
public void insertLatestOrNewModifications(final Material material, MaterialInstance materialInstance, File folder, Modifications list) {
final PluggableSCMMaterialInstance currentMaterialInstance = (PluggableSCMMaterialInstance) materialInstance;
final PluggableSCMMaterialInstance latestMaterialInstance = (PluggableSCMMaterialInstance) material.createMaterialInstance();
if (currentMaterialInstance.shouldUpgradeTo(latestMaterialInstance)) {
transactionTemplate.execute((TransactionCallback) transactionStatus -> {
PluggableSCMMaterialInstance materialInstance1 = (PluggableSCMMaterialInstance) materialRepository.find(currentMaterialInstance.getId());
materialInstance1.upgradeTo(latestMaterialInstance);
materialRepository.saveOrUpdate(materialInstance1);
return materialInstance1;
});
}
scmMaterialUpdater.insertLatestOrNewModifications(material, currentMaterialInstance, folder, list);
}
use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class PackageMaterialUpdater method insertLatestOrNewModifications.
@Override
public void insertLatestOrNewModifications(final Material material, MaterialInstance materialInstance, File folder, Modifications list) {
final PackageMaterialInstance packageMaterialInstance = (PackageMaterialInstance) materialInstance;
if (packageMaterialInstance.shouldUpgradeTo((PackageMaterialInstance) material.createMaterialInstance())) {
transactionTemplate.execute((TransactionCallback) transactionStatus -> {
PackageMaterialInstance materialInstance1 = (PackageMaterialInstance) materialRepository.find(packageMaterialInstance.getId());
materialInstance1.upgradeTo((PackageMaterialInstance) material.createMaterialInstance());
materialRepository.saveOrUpdate(materialInstance1);
return materialInstance1;
});
}
scmMaterialUpdater.insertLatestOrNewModifications(material, packageMaterialInstance, folder, list);
}
use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class PipelineSqlMapDaoCachingTest method shouldInvalidateCacheOfPipelineInstancesTriggeredWithMaterialRevision.
@Test
void shouldInvalidateCacheOfPipelineInstancesTriggeredWithMaterialRevision() {
GitMaterialInstance materialInstance = new GitMaterialInstance("url", null, "branch", "submodule", "flyweight");
String cacheKey = pipelineDao.cacheKeyForPipelineInstancesTriggeredWithDependencyMaterial("p1", materialInstance.getFingerprint(), "r1");
List<PipelineIdentifier> result = Arrays.asList(new PipelineIdentifier("p1", 1, "1"));
when(mockTemplate.queryForList(eq("pipelineInstancesTriggeredOffOfMaterialRevision"), any())).thenReturn((List) result);
List<PipelineIdentifier> actual = pipelineDao.getPipelineInstancesTriggeredWithDependencyMaterial("p1", materialInstance, "r1");
assertThat(actual).hasSize(1);
assertThat((List<PipelineIdentifier>) goCache.get(cacheKey)).hasSize(1);
MaterialRevisions materialRevisions = new MaterialRevisions(new MaterialRevision(new GitMaterial("url", "branch"), new Modification("user", "comment", "email", new Date(), "r1")));
Pipeline pipeline = new Pipeline("p1", BuildCause.createWithModifications(materialRevisions, ""));
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
((TransactionSynchronizationAdapter) invocation.getArguments()[0]).afterCommit();
return null;
}
}).when(transactionSynchronizationManager).registerSynchronization(any(TransactionSynchronization.class));
when(transactionTemplate.execute(any(TransactionCallback.class))).then(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
((TransactionCallback) invocation.getArguments()[0]).doInTransaction(new SimpleTransactionStatus());
return null;
}
});
pipelineDao.save(pipeline);
assertThat(goCache.get(cacheKey)).isNull();
}
use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class StageSqlMapDao method save.
@Override
public Stage save(final Pipeline pipeline, final Stage stage) {
return (Stage) transactionTemplate.execute((TransactionCallback) status -> {
transactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCommit() {
String pipelineName = pipeline.getName();
String stageName = stage.getName();
clearStageHistoryPageCaches(stage, pipelineName, false);
clearCachedStage(stage.getIdentifier());
clearCachedAllStages(pipelineName, pipeline.getCounter(), stageName);
removeFromCache(cacheKeyForStageCountForGraph(pipelineName, stageName));
}
});
stage.setPipelineId(pipeline.getId());
int maxStageCounter = getMaxStageCounter(pipeline.getId(), stage.getName());
stage.setCounter(maxStageCounter + 1);
getSqlMapClientTemplate().update("markPreviousStageRunsAsNotLatest", arguments("stageName", stage.getName()).and("pipelineId", pipeline.getId()).asMap());
getSqlMapClientTemplate().insert("insertStage", stage);
stage.setIdentifier(new StageIdentifier(pipeline, stage));
return stage;
});
}
Aggregations