use of org.springframework.transaction.support.TransactionSynchronizationAdapter in project gocd by gocd.
the class MaterialRepository method save.
private void save(final PipelineMaterialRevision pipelineMaterialRevision, final String pipelineName) {
getHibernateTemplate().save(pipelineMaterialRevision);
transactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCommit() {
String key = cacheKeyForLatestPmrForPipelineKey(pipelineMaterialRevision.getMaterialId(), pipelineName.toLowerCase());
synchronized (key) {
goCache.remove(key);
}
}
});
}
use of org.springframework.transaction.support.TransactionSynchronizationAdapter in project gocd by gocd.
the class GoCache method stopServingForTransaction.
public void stopServingForTransaction() {
if (transactionSynchronizationManager.isTransactionBodyExecuting() && !doNotServeForTransaction()) {
doNotServeForTransaction.set(true);
transactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void beforeCompletion() {
doNotServeForTransaction.set(false);
}
});
}
}
use of org.springframework.transaction.support.TransactionSynchronizationAdapter in project gocd by gocd.
the class PipelineSqlMapDao method unlockPipeline.
public void unlockPipeline(final String pipelineName) {
lockPipelineMutex.writeLock().lock();
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
final String cacheKey = lockedPipelineCacheKey(pipelineName);
transactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCompletion(int status) {
goCache.remove(cacheKey);
lockPipelineMutex.writeLock().unlock();
}
});
getSqlMapClientTemplate().update("unlockLockedPipeline", pipelineName);
}
});
}
use of org.springframework.transaction.support.TransactionSynchronizationAdapter in project gocd by gocd.
the class PipelineSqlMapDao method lockPipeline.
public void lockPipeline(final Pipeline pipeline) {
lockPipelineMutex.writeLock().lock();
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
final String pipelineName = pipeline.getName();
transactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCompletion(int status) {
clearLockedPipelineCache(pipelineName);
lockPipelineMutex.writeLock().unlock();
}
});
StageIdentifier identifier = lockedPipeline(pipelineName);
if (identifier != null && !identifier.pipelineIdentifier().equals(pipeline.getIdentifier())) {
throw new RuntimeException(String.format("Pipeline '%s' is already locked (counter = %s)", pipelineName, identifier.getPipelineCounter()));
}
getSqlMapClientTemplate().update("lockPipeline", pipeline.getId());
}
});
}
use of org.springframework.transaction.support.TransactionSynchronizationAdapter in project gocd by gocd.
the class PipelineSqlMapDao method save.
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, EnvironmentVariableSqlMapDao.EnvironmentVariableType.Trigger, pipeline.scheduleTimeVariables());
return pipeline;
}
});
}
Aggregations