use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class PipelineTimeline method update.
public void update() {
acquireAllWriteLocks();
try {
final long maximumIdBeforeUpdate = maximumId;
transactionTemplate.execute((TransactionCallback) transactionStatus -> {
final List<PipelineTimelineEntry> newlyAddedEntries = new ArrayList<>();
transactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCompletion(int status) {
if (STATUS_ROLLED_BACK == status) {
rollbackTempEntries();
} else if (STATUS_COMMITTED == status) {
notifyListeners(newlyAddedEntries);
}
}
private void rollbackTempEntries() {
for (PipelineTimelineEntry entry : newlyAddedEntries) {
rollbackNewEntryFor(entry);
}
maximumId = maximumIdBeforeUpdate;
}
private void rollbackNewEntryFor(PipelineTimelineEntry entry) {
CaseInsensitiveString pipelineName = new CaseInsensitiveString(entry.getPipelineName());
initializedNaturalOrderCollection(pipelineName).remove(entry);
initializedScheduleOrderCollection(pipelineName).remove(entry);
}
});
pipelineRepository.updatePipelineTimeline(PipelineTimeline.this, newlyAddedEntries);
return null;
});
} finally {
releaseAllWriteLocks();
}
}
use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class UserSqlMapDao method deleteUsers.
@Override
public boolean deleteUsers(List<String> userNames, String byWhom) {
return (Boolean) transactionTemplate.execute((TransactionCallback) status -> {
String queryString = "delete from User where name in (:userNames)";
Query query = sessionFactory.getCurrentSession().createQuery(queryString);
query.setParameterList("userNames", userNames);
query.executeUpdate();
accessTokenDao.revokeTokensBecauseOfUserDelete(userNames, byWhom);
return Boolean.TRUE;
});
}
use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class EnvironmentVariableSqlMapDao method load.
@Override
public EnvironmentVariables load(final Long entityId, final EnvironmentVariableType type) {
List<EnvironmentVariable> result = (List<EnvironmentVariable>) transactionTemplate.execute((TransactionCallback) transactionStatus -> {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(EnvironmentVariable.class).add(Restrictions.eq("entityId", entityId)).add(Restrictions.eq("entityType", type.toString())).addOrder(Order.asc("id"));
criteria.setCacheable(true);
return criteria.list();
});
return new EnvironmentVariables(result);
}
use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class JobInstanceSqlMapDao method updateStateAndResult.
@Override
public JobInstance updateStateAndResult(final JobInstance jobInstance) {
return (JobInstance) transactionTemplate.execute((TransactionCallback) status -> {
transactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCommit() {
synchronized (cacheKeyForJobPlan(jobInstance.getId())) {
removeCachedJobPlan(jobInstance);
}
synchronized (cacheKeyForActiveJobIds()) {
goCache.remove(cacheKeyForActiveJobIds());
}
String activeJobKey = cacheKeyForActiveJob(jobInstance.getId());
synchronized (activeJobKey) {
goCache.remove(activeJobKey);
}
removeCachedJobInstance(jobInstance);
}
});
logIfJobIsCompleted(jobInstance);
updateStatus(jobInstance);
updateResult(jobInstance);
return jobInstance;
});
}
use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class MaterialRepositoryIntegrationTest method shouldAllowSavingModificationsIfRevisionsAcrossDifferentMaterialsHappenToBeSame.
@Test
public void shouldAllowSavingModificationsIfRevisionsAcrossDifferentMaterialsHappenToBeSame() {
final MaterialInstance materialInstance1 = repo.findOrCreateFrom(new GitMaterial(UUID.randomUUID().toString(), "branch"));
final MaterialInstance materialInstance2 = repo.findOrCreateFrom(new GitMaterial(UUID.randomUUID().toString(), "branch"));
final ArrayList<Modification> modificationsForFirstMaterial = getModifications(3);
transactionTemplate.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) {
repo.saveModifications(materialInstance1, modificationsForFirstMaterial);
return null;
}
});
assertThat(repo.getModificationsFor(materialInstance1, Pagination.pageByNumber(1, 10, 10)).size(), is(3));
final ArrayList<Modification> modificationsForSecondMaterial = getModifications(3);
transactionTemplate.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) {
repo.saveModifications(materialInstance2, modificationsForSecondMaterial);
return null;
}
});
Modifications modificationsFromDb = repo.getModificationsFor(materialInstance2, Pagination.pageByNumber(1, 10, 10));
assertThat(modificationsFromDb.size(), is(3));
for (Modification modification : modificationsForSecondMaterial) {
assertThat(modificationsFromDb.containsRevisionFor(modification), is(true));
}
}
Aggregations