use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class PipelineRepositoryIntegrationTest method save.
private long save(final PipelineConfig pipelineConfig, final int counter, final double naturalOrder, final MaterialRevision... materialRevisions) {
return (Long) transactionTemplate.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) {
MaterialRevisions revisions = new MaterialRevisions(materialRevisions);
materialRepository.save(revisions);
Pipeline instance = instanceFactory.createPipelineInstance(pipelineConfig, BuildCause.createWithModifications(revisions, "me"), new DefaultSchedulingContext(), "md5-test", new TimeProvider());
instance.setCounter(counter);
instance.setNaturalOrder(naturalOrder);
return pipelineSqlMapDao.save(instance).getId();
}
});
}
use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class PipelineStateDao method pipelineStateFor.
public PipelineState pipelineStateFor(String pipelineName) {
String cacheKey = pipelineLockStateCacheKey(pipelineName);
PipelineState pipelineState = (PipelineState) goCache.get(cacheKey);
if (pipelineState != null) {
return pipelineState.equals(PipelineState.NOT_LOCKED) ? null : pipelineState;
}
synchronized (cacheKey) {
pipelineState = (PipelineState) goCache.get(cacheKey);
if (pipelineState != null) {
return pipelineState.equals(PipelineState.NOT_LOCKED) ? null : pipelineState;
}
pipelineState = (PipelineState) transactionTemplate.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus transactionStatus) {
return sessionFactory.getCurrentSession().createCriteria(PipelineState.class).add(Restrictions.eq("pipelineName", pipelineName)).setCacheable(false).uniqueResult();
}
});
if (pipelineState != null && pipelineState.isLocked()) {
StageIdentifier lockedBy = (StageIdentifier) getSqlMapClientTemplate().queryForObject("lockedPipeline", pipelineState.getLockedByPipelineId());
pipelineState.setLockedBy(lockedBy);
}
goCache.put(cacheKey, pipelineState == null ? PipelineState.NOT_LOCKED : pipelineState);
return pipelineState;
}
}
use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class PipelineStateDao method lockedPipelines.
public List<String> lockedPipelines() {
return (List<String>) transactionTemplate.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) {
PropertyProjection pipelineName = Projections.property("pipelineName");
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(PipelineState.class).setProjection(pipelineName).add(Restrictions.eq("locked", true));
criteria.setCacheable(false);
List<String> list = criteria.list();
return list;
}
});
}
use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class PluginSqlMapDao method getAllPlugins.
// used in tests
@Override
public List<Plugin> getAllPlugins() {
return (List<Plugin>) transactionTemplate.execute((TransactionCallback) transactionStatus -> {
Query query = sessionFactory.getCurrentSession().createQuery("FROM " + Plugin.class.getSimpleName());
query.setCacheable(true);
return query.list();
});
}
use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class PluginSqlMapDao method findPlugin.
@Override
public Plugin findPlugin(final String pluginId) {
String cacheKey = cacheKeyForPluginSettings(pluginId);
Plugin plugin = (Plugin) goCache.get(cacheKey);
if (plugin != null) {
return plugin;
}
synchronized (cacheKey) {
plugin = (Plugin) goCache.get(cacheKey);
if (plugin != null) {
return plugin;
}
plugin = (Plugin) transactionTemplate.execute((TransactionCallback) transactionStatus -> sessionFactory.getCurrentSession().createCriteria(Plugin.class).add(Restrictions.eq("pluginId", pluginId)).setCacheable(true).uniqueResult());
if (plugin != null) {
goCache.put(cacheKey, plugin);
return plugin;
}
goCache.remove(cacheKey);
return new NullPlugin();
}
}
Aggregations