private void disableDeprecatedUserRules(DatabaseSession session) { List<Integer> deprecatedUserRuleIds = Lists.newLinkedList(); deprecatedUserRuleIds.addAll( session .createQuery( "SELECT r.id FROM " + Rule.class.getSimpleName() + " r WHERE r.parent IS NOT NULL AND NOT EXISTS(FROM " + Rule.class.getSimpleName() + " p WHERE r.parent=p)") .getResultList()); deprecatedUserRuleIds.addAll( session .createQuery( "SELECT r.id FROM " + Rule.class.getSimpleName() + " r WHERE r.parent IS NOT NULL AND EXISTS(FROM " + Rule.class.getSimpleName() + " p WHERE r.parent=p and p.enabled=false)") .getResultList()); for (Integer deprecatedUserRuleId : deprecatedUserRuleIds) { Rule rule = session.getSingleResult(Rule.class, "id", deprecatedUserRuleId); rule.setEnabled(false); session.saveWithoutFlush(rule); } }
/** * Only used to get the real date of the snapshot on the current period. The date is used to * calculate new_violations measures */ @CheckForNull private Snapshot findSnapshot(Snapshot projectSnapshot) { String hql = "from " + Snapshot.class.getSimpleName() + " where resourceId=:resourceId and (rootId=:rootSnapshotId or id=:rootSnapshotId)"; List<Snapshot> snapshots = session .createQuery(hql) .setParameter("resourceId", projectSnapshot.getResourceId()) .setParameter("rootSnapshotId", projectSnapshot.getId()) .setMaxResults(1) .getResultList(); return snapshots.isEmpty() ? null : snapshots.get(0); }
private void deleteDeprecatedParameters(Rule persistedRule, Rule rule, DatabaseSession session) { if (persistedRule.getParams() != null && persistedRule.getParams().size() > 0) { for (Iterator<RuleParam> it = persistedRule.getParams().iterator(); it.hasNext(); ) { RuleParam persistedParam = it.next(); if (rule.getParam(persistedParam.getKey()) == null) { it.remove(); session .createQuery( "delete from " + ActiveRuleParam.class.getSimpleName() + " where ruleParam=:param") .setParameter("param", persistedParam) .executeUpdate(); } } } }
private void disableAllRules(DatabaseSession session) { session .createQuery( "UPDATE " + Rule.class.getSimpleName() + " SET enabled=false WHERE parent IS NULL") .executeUpdate(); }