use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class PipelineSqlMapDao method save.
@Override
public Pipeline save(final Pipeline pipeline) {
return (Pipeline) transactionTemplate.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) {
transactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCommit() {
goCache.remove(cacheKeyForLatestPipelineIdByPipelineName(pipeline.getName()));
invalidateCacheConditionallyForPipelineInstancesTriggeredWithDependencyMaterial(pipeline);
}
});
pipelineByBuildIdCache.flushOnCommit();
getSqlMapClientTemplate().insert("insertPipeline", pipeline);
savePipelineMaterialRevisions(pipeline, pipeline.getId());
environmentVariableDao.save(pipeline.getId(), EnvironmentVariableType.Trigger, pipeline.scheduleTimeVariables());
return pipeline;
}
});
}
use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class UserSqlMapDao method findNotificationSubscribingUsers.
@Override
public Users findNotificationSubscribingUsers() {
return (Users) transactionTemplate.execute((TransactionCallback) transactionStatus -> {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(User.class);
criteria.setCacheable(true);
criteria.add(Restrictions.isNotEmpty("notificationFilters"));
criteria.add(Restrictions.eq("enabled", true));
return new Users(criteria.list());
});
}
use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class UserSqlMapDao method deleteUser.
@Override
public boolean deleteUser(final String username, String byWhom) {
return (Boolean) transactionTemplate.execute((TransactionCallback) status -> {
User user = findUser(username);
if (user instanceof NullUser) {
throw new RecordNotFoundException(EntityType.User, username);
}
if (user.isEnabled()) {
throw new UserEnabledException();
}
sessionFactory.getCurrentSession().delete(user);
accessTokenDao.revokeTokensBecauseOfUserDelete(Collections.singletonList(username), byWhom);
return Boolean.TRUE;
});
}
use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class AgentMutex method getAgentsByUUIDs.
public List<Agent> getAgentsByUUIDs(List<String> uuids) {
AgentMutex mutex = agentMutexes.acquire(uuids);
synchronized (mutex) {
List<Agent> agents = (List<Agent>) transactionTemplate.execute((TransactionCallback) transactionStatus -> {
Query query = sessionFactory.getCurrentSession().createQuery("FROM Agent where uuid in :uuids and deleted = false");
query.setCacheable(true);
query.setParameterList("uuids", uuids);
return query.list();
});
agentMutexes.release(uuids, mutex);
return agents;
}
}
use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class AgentMutex method fetchAgentFromDBByUUIDIncludingDeleted.
public Agent fetchAgentFromDBByUUIDIncludingDeleted(final String uuid) {
List<String> uuids = singletonList(uuid);
AgentMutex mutex = agentMutexes.acquire(uuids);
synchronized (mutex) {
Agent agent = (Agent) transactionTemplate.execute((TransactionCallback) transactionStatus -> {
Query query = sessionFactory.getCurrentSession().createQuery("FROM Agent where uuid = :uuid");
query.setCacheable(true);
query.setParameter("uuid", uuid);
return query.uniqueResult();
});
agentMutexes.release(uuids, mutex);
return agent;
}
}
Aggregations