use of org.springframework.orm.hibernate3.HibernateCallback in project gocd by gocd.
the class MaterialRepository method modificationFor.
public List<Modification> modificationFor(final StageIdentifier stageIdentifier) {
if (stageIdentifier == null) {
return null;
}
String key = cacheKeyForModificationsForStageLocator(stageIdentifier);
List<Modification> modifications = (List<Modification>) goCache.get(key);
if (modifications == null) {
synchronized (key) {
modifications = (List<Modification>) goCache.get(key);
if (modifications == null) {
modifications = getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query q = session.createQuery("FROM Modification WHERE revision = :revision ORDER BY id DESC");
q.setParameter("revision", stageIdentifier.getStageLocator());
return q.list();
}
});
if (!modifications.isEmpty()) {
goCache.put(key, modifications);
}
}
}
}
return modifications;
}
use of org.springframework.orm.hibernate3.HibernateCallback in project gocd by gocd.
the class OauthRepository method deleteUsersOauthGrants.
public void deleteUsersOauthGrants(final List<String> userIds) {
txnTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
deleteEntitiesByUserIds(OauthAuthorization.class, session, userIds);
deleteEntitiesByUserIds(OauthToken.class, session, userIds);
return true;
}
});
}
});
}
use of org.springframework.orm.hibernate3.HibernateCallback in project gocd by gocd.
the class UserSqlMapDaoTest method shouldDoADoubleCheckOfCacheBeforeLoadingFromTheDB.
@Test
public void shouldDoADoubleCheckOfCacheBeforeLoadingFromTheDB() throws Exception {
GoCache cache = mock(GoCache.class);
UserSqlMapDao userSqlMapDaoSpy = spy(new UserSqlMapDao(sessionFactory, transactionTemplate, cache, transactionSynchronizationManager));
doReturn(mockHibernateTemplate).when(userSqlMapDaoSpy).hibernateTemplate();
doReturn(10).when(mockHibernateTemplate).execute(Matchers.<HibernateCallback<Object>>any());
Integer firstEnabledUserCount = userSqlMapDaoSpy.enabledUserCount();
assertThat(firstEnabledUserCount, is(10));
verify(mockHibernateTemplate, times(1)).execute(any(HibernateCallback.class));
verify(cache, times(2)).get(UserSqlMapDao.ENABLED_USER_COUNT_CACHE_KEY);
verify(cache, times(1)).put(UserSqlMapDao.ENABLED_USER_COUNT_CACHE_KEY, 10);
}
use of org.springframework.orm.hibernate3.HibernateCallback in project gocd by gocd.
the class PipelineRepositoryTest method stubPipelineInstancesInDb.
private void stubPipelineInstancesInDb(Object[]... rows) {
pipelineRepository.setHibernateTemplate(new HibernateTemplate() {
@Override
public <T> T execute(HibernateCallback<T> action) throws DataAccessException {
try {
return action.doInHibernate(session);
} catch (SQLException e) {
throw new RuntimeException();
}
}
});
when(session.createSQLQuery(anyString())).thenReturn(sqlQuery);
when(sqlQuery.list()).thenReturn(Arrays.asList(rows));
}
use of org.springframework.orm.hibernate3.HibernateCallback in project gocd by gocd.
the class ScheduleTestUtil method modForRev.
private Modification modForRev(final String revision) {
return (Modification) materialRepository.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query q = session.createQuery("from Modification where revision = ?");
q.setParameter(0, revision);
List list = q.list();
if (list.isEmpty()) {
throw new RuntimeException("you are trying to load revision " + revision + " which doesn't exist");
}
return list.get(0);
}
});
}
Aggregations