예제 #1
0
  private void registerRepository(RuleRepository repository, DatabaseSession session) {
    Map<String, Rule> rulesByKey = Maps.newHashMap();
    for (Rule rule : repository.createRules()) {
      rule.setRepositoryKey(repository.getKey());
      rulesByKey.put(rule.getKey(), rule);
    }
    Logs.INFO.info(rulesByKey.size() + " rules");

    List<Rule> persistedRules = session.getResults(Rule.class, "pluginName", repository.getKey());
    for (Rule persistedRule : persistedRules) {
      Rule rule = rulesByKey.get(persistedRule.getKey());
      if (rule != null) {
        updateRule(persistedRule, rule, session);
        rulesByKey.remove(rule.getKey());
      }
    }

    saveNewRules(rulesByKey.values(), session);
  }
예제 #2
0
  public void start() {
    TimeProfiler profiler = new TimeProfiler();

    DatabaseSession session = sessionFactory.getSession();
    disableAllRules(session);
    for (RuleRepository repository : repositories) {
      profiler.start(
          "Register rules ["
              + repository.getKey()
              + "/"
              + StringUtils.defaultString(repository.getLanguage(), "-")
              + "]");
      registerRepository(repository, session);
      profiler.stop();
    }

    profiler.start("Disable deprecated user rules");
    disableDeprecatedUserRules(session);
    profiler.stop();

    session.commit();
  }