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 MaterialRepository method findRevisionsMatching.
@SuppressWarnings("unchecked")
public List<MatchedRevision> findRevisionsMatching(final MaterialConfig materialConfig, final String searchString) {
return (List<MatchedRevision>) getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
String sql = "SELECT m.*" + " FROM modifications AS m" + " INNER JOIN materials mat ON mat.id = m.materialId" + " WHERE mat.fingerprint = :finger_print" + " AND (m.revision || ' ' || COALESCE(m.username, '') || ' ' || COALESCE(m.comment, '') LIKE :search_string OR m.pipelineLabel LIKE :search_string)" + " ORDER BY m.id DESC" + " LIMIT 5";
SQLQuery query = session.createSQLQuery(sql);
query.addEntity("m", Modification.class);
Material material = materialConfigConverter.toMaterial(materialConfig);
query.setString("finger_print", material.getFingerprint());
query.setString("search_string", "%" + searchString + "%");
final List<MatchedRevision> list = new ArrayList<>();
for (Modification mod : (List<Modification>) query.list()) {
list.add(material.createMatchedRevision(mod, searchString));
}
return list;
}
});
}
use of org.springframework.orm.hibernate3.HibernateCallback in project gocd by gocd.
the class MaterialRepository method hasPipelineEverRunWith.
public boolean hasPipelineEverRunWith(final String pipelineName, final MaterialRevisions revisions) {
return (Boolean) getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
int numberOfMaterials = revisions.getRevisions().size();
int match = 0;
for (MaterialRevision revision : revisions) {
long materialId = findOrCreateFrom(revision.getMaterial()).getId();
long modificationId = revision.getLatestModification().getId();
String key = cacheKeyForHasPipelineEverRunWithModification(pipelineName, materialId, modificationId);
if (goCache.get(key) != null) {
match++;
continue;
}
String sql = "SELECT materials.id" + " FROM pipelineMaterialRevisions" + " INNER JOIN pipelines ON pipelineMaterialRevisions.pipelineId = pipelines.id" + " INNER JOIN modifications on modifications.id = pipelineMaterialRevisions.torevisionId" + " INNER JOIN materials on modifications.materialId = materials.id" + " WHERE materials.id = ? AND pipelineMaterialRevisions.toRevisionId >= ? AND pipelineMaterialRevisions.fromRevisionId <= ? AND pipelines.name = ?" + " GROUP BY materials.id;";
SQLQuery query = session.createSQLQuery(sql);
query.setLong(0, materialId);
query.setLong(1, modificationId);
query.setLong(2, modificationId);
query.setString(3, pipelineName);
if (!query.list().isEmpty()) {
match++;
goCache.put(key, Boolean.TRUE);
}
}
return match == numberOfMaterials;
}
});
}
use of org.springframework.orm.hibernate3.HibernateCallback in project gocd by gocd.
the class MaterialRepository method modificationAfter.
private long modificationAfter(final long id, final MaterialInstance materialInstance) {
BigInteger result = (BigInteger) getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
String sql = "SELECT id " + " FROM modifications " + " WHERE materialId = ? " + " AND id > ?" + " ORDER BY id" + " LIMIT 1";
SQLQuery query = session.createSQLQuery(sql);
query.setLong(0, materialInstance.getId());
query.setLong(1, id);
return query.uniqueResult();
}
});
return result == null ? id : result.longValue();
}
use of org.springframework.orm.hibernate3.HibernateCallback in project opennms by OpenNMS.
the class EventCountDaoHibernate method getUeiCounts.
@Override
public Set<CountedObject<String>> getUeiCounts(final Integer limit) {
Set<CountedObject<String>> ueis = new TreeSet<CountedObject<String>>();
HibernateCallback<List<CountedObject<String>>> hc = new HibernateCallback<List<CountedObject<String>>>() {
@Override
public List<CountedObject<String>> doInHibernate(Session session) throws HibernateException {
Query queryObject = session.createQuery("SELECT event.eventUei, COUNT(event.eventUei) FROM OnmsEvent event GROUP BY event.eventUei ORDER BY COUNT(event.eventUei) desc");
queryObject.setMaxResults(limit);
SessionFactoryUtils.applyTransactionTimeout(queryObject, getSessionFactory());
List<CountedObject<String>> ueis = new ArrayList<CountedObject<String>>();
@SuppressWarnings("unchecked") final List<Object[]> l = queryObject.list();
for (final Object[] o : l) {
ueis.add(new CountedObject<String>((String) o[0], (Long) o[1]));
}
return ueis;
}
};
ueis.addAll((List<CountedObject<String>>) getHibernateTemplate().executeWithNativeSession(hc));
return ueis;
}
Aggregations